MDT: fix initialization

This commit is contained in:
Milos Kozak 2022-06-30 23:44:32 +02:00
parent 5d749e121f
commit 77e112471f
5 changed files with 34 additions and 50 deletions

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.HandlerThread import android.os.HandlerThread
@ -16,13 +15,11 @@ import info.nightscout.androidaps.events.EventTempBasalChange
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState
import info.nightscout.androidaps.plugins.pump.common.events.EventRefreshButtonState import info.nightscout.androidaps.plugins.pump.common.events.EventRefreshButtonState
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity
@ -42,8 +39,9 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.WarnColors import info.nightscout.androidaps.utils.WarnColors
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import javax.inject.Inject import javax.inject.Inject
@ -59,7 +57,6 @@ class MedtronicFragment : DaggerFragment() {
@Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin @Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin
@Inject lateinit var warnColors: WarnColors @Inject lateinit var warnColors: WarnColors
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
@Inject lateinit var medtronicUtil: MedtronicUtil @Inject lateinit var medtronicUtil: MedtronicUtil
@Inject lateinit var medtronicPumpStatus: MedtronicPumpStatus @Inject lateinit var medtronicPumpStatus: MedtronicPumpStatus
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData @Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
@ -92,7 +89,7 @@ class MedtronicFragment : DaggerFragment() {
binding.rlStatus.text = rh.gs(RileyLinkServiceState.NotStarted.resourceId) binding.rlStatus.text = rh.gs(RileyLinkServiceState.NotStarted.resourceId)
binding.pumpStatusIcon.setTextColor(rh.gac(context,R.attr.defaultTextColor)) binding.pumpStatusIcon.setTextColor(rh.gac(context, R.attr.defaultTextColor))
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
binding.pumpStatusIcon.text = "{fa-bed}" binding.pumpStatusIcon.text = "{fa-bed}"
@ -200,7 +197,7 @@ class MedtronicFragment : DaggerFragment() {
rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + rh.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump)) rileyLinkServiceData.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + rh.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
else -> "{fa-bluetooth-b} " + rh.gs(resourceId) else -> "{fa-bluetooth-b} " + rh.gs(resourceId)
} }
binding.rlStatus.setTextColor(rh.gac( context, if (rileyLinkError != null) R.attr.warningColor else R.attr.defaultTextColor)) binding.rlStatus.setTextColor(rh.gac(context, if (rileyLinkError != null) R.attr.warningColor else R.attr.defaultTextColor))
binding.errors.text = binding.errors.text =
rileyLinkServiceData.rileyLinkError?.let { rileyLinkServiceData.rileyLinkError?.let {
@ -253,8 +250,10 @@ class MedtronicFragment : DaggerFragment() {
private fun displayNotConfiguredDialog() { private fun displayNotConfiguredDialog() {
context?.let { context?.let {
OKDialog.show(it, rh.gs(R.string.medtronic_warning), OKDialog.show(
rh.gs(R.string.medtronic_error_operation_not_possible_no_configuration), null) it, rh.gs(R.string.medtronic_warning),
rh.gs(R.string.medtronic_error_operation_not_possible_no_configuration), null
)
} }
} }
@ -272,7 +271,7 @@ class MedtronicFragment : DaggerFragment() {
val min = (System.currentTimeMillis() - medtronicPumpStatus.lastConnection) / 1000 / 60 val min = (System.currentTimeMillis() - medtronicPumpStatus.lastConnection) / 1000 / 60
if (medtronicPumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) { if (medtronicPumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
binding.lastConnection.setText(R.string.medtronic_pump_connected_now) binding.lastConnection.setText(R.string.medtronic_pump_connected_now)
binding.lastConnection.setTextColor(rh.gac(context,R.attr.defaultTextColor)) binding.lastConnection.setTextColor(rh.gac(context, R.attr.defaultTextColor))
} else if (medtronicPumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) { } else if (medtronicPumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) {
if (min < 60) { if (min < 60) {
@ -288,10 +287,10 @@ class MedtronicFragment : DaggerFragment() {
binding.lastConnection.text = (rh.gq(R.plurals.duration_days, d, d) + " " binding.lastConnection.text = (rh.gq(R.plurals.duration_days, d, d) + " "
+ rh.gs(R.string.ago)) + rh.gs(R.string.ago))
} }
binding.lastConnection.setTextColor(rh.gac(context,R.attr.warningColor)) binding.lastConnection.setTextColor(rh.gac(context, R.attr.warningColor))
} else { } else {
binding.lastConnection.text = minAgo binding.lastConnection.text = minAgo
binding.lastConnection.setTextColor(rh.gac(context,R.attr.defaultTextColor)) binding.lastConnection.setTextColor(rh.gac(context, R.attr.defaultTextColor))
} }
} }
@ -329,7 +328,8 @@ class MedtronicFragment : DaggerFragment() {
if (medtronicPumpStatus.batteryType == BatteryType.None || medtronicPumpStatus.batteryVoltage == null) { if (medtronicPumpStatus.batteryType == BatteryType.None || medtronicPumpStatus.batteryVoltage == null) {
binding.pumpStateBattery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " binding.pumpStateBattery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} "
} else { } else {
binding.pumpStateBattery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage) binding.pumpStateBattery.text =
"{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage)
} }
warnColors.setColorInverse(binding.pumpStateBattery, medtronicPumpStatus.batteryRemaining.toDouble(), 25.0, 10.0) warnColors.setColorInverse(binding.pumpStateBattery, medtronicPumpStatus.batteryRemaining.toDouble(), 25.0, 10.0)

View file

@ -55,6 +55,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.TimeChangeType import info.nightscout.androidaps.utils.TimeChangeType
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag import info.nightscout.shared.logging.LTag
@ -215,27 +216,13 @@ class MedtronicPumpPlugin @Inject constructor(
}.start() }.start()
} }
override val serviceClass: Class<*> override val serviceClass: Class<*> = RileyLinkMedtronicService::class.java
get() = RileyLinkMedtronicService::class.java override val pumpStatusData: PumpStatus get() = medtronicPumpStatus
override fun deviceID(): String = "Medtronic"
override val pumpStatusData: info.nightscout.androidaps.plugins.pump.common.data.PumpStatus override val isFakingTempsByExtendedBoluses: Boolean = false
get() = medtronicPumpStatus override fun canHandleDST(): Boolean = false
override fun deviceID(): String {
return "Medtronic"
}
override val isFakingTempsByExtendedBoluses: Boolean
get() = false
override fun canHandleDST(): Boolean {
return false
}
// Pump Plugin
private var isServiceSet: Boolean = false private var isServiceSet: Boolean = false
override val rileyLinkService: RileyLinkMedtronicService? get() = rileyLinkMedtronicService
override val rileyLinkService: RileyLinkMedtronicService? = rileyLinkMedtronicService
override val pumpInfo: RileyLinkPumpInfo override val pumpInfo: RileyLinkPumpInfo
get() = RileyLinkPumpInfo( get() = RileyLinkPumpInfo(
@ -244,7 +231,7 @@ class MedtronicPumpPlugin @Inject constructor(
medtronicPumpStatus.serialNumber medtronicPumpStatus.serialNumber
) )
override val lastConnectionTimeMillis: Long = medtronicPumpStatus.lastConnection override val lastConnectionTimeMillis: Long get() = medtronicPumpStatus.lastConnection
override fun setLastCommunicationToNow() { override fun setLastCommunicationToNow() {
medtronicPumpStatus.setLastCommunicationToNow() medtronicPumpStatus.setLastCommunicationToNow()

View file

@ -120,9 +120,8 @@ class RileyLinkBroadcastReceiver : DaggerBroadcastReceiver() {
RileyLinkConst.Intents.RileyLinkNewAddressSet -> { RileyLinkConst.Intents.RileyLinkNewAddressSet -> {
val rileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "") val rileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "")
if (rileylinkBLEAddress == "") { if (rileylinkBLEAddress == "") aapsLogger.error("No Rileylink BLE Address saved in app")
aapsLogger.error("No Rileylink BLE Address saved in app") else rileyLinkService?.reconfigureRileyLink(rileylinkBLEAddress)
} else rileyLinkService?.reconfigureRileyLink(rileylinkBLEAddress)
true true
} }

View file

@ -44,7 +44,7 @@ abstract class RileyLinkService : DaggerService() {
@Inject lateinit var rfSpy: RFSpy // interface for RL xxx Mhz radio. @Inject lateinit var rfSpy: RFSpy // interface for RL xxx Mhz radio.
private val bluetoothAdapter: BluetoothAdapter? get() = (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter private val bluetoothAdapter: BluetoothAdapter? get() = (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter
protected var broadcastReceiver: RileyLinkBroadcastReceiver? = null private var broadcastReceiver: RileyLinkBroadcastReceiver? = null
private var bluetoothStateReceiver: RileyLinkBluetoothStateReceiver? = null private var bluetoothStateReceiver: RileyLinkBluetoothStateReceiver? = null
override fun onCreate() { override fun onCreate() {

View file

@ -6,9 +6,6 @@ import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange; import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
@ -18,6 +15,8 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistor
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
/** /**
* Created by andy on 16/05/2018. * Created by andy on 16/05/2018.
@ -30,7 +29,6 @@ public class RileyLinkServiceData {
@Inject AAPSLogger aapsLogger; @Inject AAPSLogger aapsLogger;
@Inject RileyLinkUtil rileyLinkUtil; @Inject RileyLinkUtil rileyLinkUtil;
@Inject RxBus rxBus; @Inject RxBus rxBus;
@Inject ActivePlugin activePlugin;
boolean tuneUpDone = false; boolean tuneUpDone = false;
public RileyLinkError rileyLinkError; public RileyLinkError rileyLinkError;