Alarm on pump suspended states
This commit is contained in:
parent
3ae145524c
commit
ecb2c977ec
2 changed files with 53 additions and 15 deletions
|
@ -10,10 +10,10 @@ import dagger.android.DaggerService
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||||
import info.nightscout.interfaces.constraints.Constraints
|
import info.nightscout.interfaces.constraints.Constraints
|
||||||
|
import info.nightscout.interfaces.notifications.Notification
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||||
import info.nightscout.interfaces.profile.Profile
|
import info.nightscout.interfaces.profile.Profile
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
import info.nightscout.interfaces.pump.PumpSync
|
||||||
import info.nightscout.interfaces.queue.Callback
|
import info.nightscout.interfaces.queue.Callback
|
||||||
import info.nightscout.interfaces.queue.CommandQueue
|
import info.nightscout.interfaces.queue.CommandQueue
|
||||||
|
@ -24,12 +24,11 @@ import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.ConnectionState
|
import info.nightscout.pump.medtrum.code.ConnectionState
|
||||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||||
import info.nightscout.pump.medtrum.comm.packets.*
|
import info.nightscout.pump.medtrum.comm.packets.*
|
||||||
import info.nightscout.pump.medtrum.extension.toInt
|
|
||||||
import info.nightscout.pump.medtrum.extension.toLong
|
|
||||||
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
||||||
import info.nightscout.rx.AapsSchedulers
|
import info.nightscout.rx.AapsSchedulers
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.rx.events.EventAppExit
|
import info.nightscout.rx.events.EventAppExit
|
||||||
|
import info.nightscout.rx.events.EventDismissNotification
|
||||||
import info.nightscout.rx.events.EventOverviewBolusProgress
|
import info.nightscout.rx.events.EventOverviewBolusProgress
|
||||||
import info.nightscout.rx.events.EventPreferenceChange
|
import info.nightscout.rx.events.EventPreferenceChange
|
||||||
import info.nightscout.rx.events.EventPumpStatusChanged
|
import info.nightscout.rx.events.EventPumpStatusChanged
|
||||||
|
@ -46,7 +45,6 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
|
@ -73,6 +71,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
// TODO: Test and further increase?
|
// TODO: Test and further increase?
|
||||||
private const val COMMAND_DEFAULT_TIMEOUT_SEC: Long = 60
|
private const val COMMAND_DEFAULT_TIMEOUT_SEC: Long = 60
|
||||||
private const val COMMAND_SYNC_TIMEOUT_SEC: Long = 120
|
private const val COMMAND_SYNC_TIMEOUT_SEC: Long = 120
|
||||||
|
@ -109,8 +108,45 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
changePump()
|
changePump()
|
||||||
}
|
}
|
||||||
}, fabricPrivacy::logException)
|
}, fabricPrivacy::logException)
|
||||||
|
scope.launch {
|
||||||
|
medtrumPump.pumpStateFlow.collect { state ->
|
||||||
|
when (state) {
|
||||||
|
MedtrumPumpState.LOWBG_SUSPENDED,
|
||||||
|
MedtrumPumpState.LOWBG_SUSPENDED2,
|
||||||
|
MedtrumPumpState.AUTO_SUSPENDED,
|
||||||
|
MedtrumPumpState.HMAX_SUSPENDED,
|
||||||
|
MedtrumPumpState.DMAX_SUSPENDED,
|
||||||
|
MedtrumPumpState.SUSPENDED,
|
||||||
|
MedtrumPumpState.PAUSED,
|
||||||
|
MedtrumPumpState.OCCLUSION,
|
||||||
|
MedtrumPumpState.EXPIRED,
|
||||||
|
MedtrumPumpState.RESERVOIR_EMPTY,
|
||||||
|
MedtrumPumpState.PATCH_FAULT,
|
||||||
|
MedtrumPumpState.PATCH_FAULT2,
|
||||||
|
MedtrumPumpState.BASE_FAULT,
|
||||||
|
MedtrumPumpState.BATTERY_OUT,
|
||||||
|
MedtrumPumpState.NO_CALIBRATION -> {
|
||||||
|
// Pump suspended show error!
|
||||||
|
uiInteraction.addNotificationWithSound(
|
||||||
|
Notification.PUMP_ERROR,
|
||||||
|
rh.gs(R.string.pump_error, state.toString()),
|
||||||
|
Notification.URGENT,
|
||||||
|
info.nightscout.core.ui.R.raw.alarm
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
MedtrumPumpState.STOPPED -> {
|
||||||
|
rxBus.send(EventDismissNotification(Notification.PUMP_ERROR))
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
changePump()
|
changePump()
|
||||||
// TODO: We should probably listen to the pump state as well and handle some state changes? Or do we handle that in the packets or medtrumPump?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -168,7 +204,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
// Send a poll patch, to workaround connection losses?
|
// Send a poll patch, to workaround connection losses?
|
||||||
var result = sendPacketAndGetResponse(PollPatchPacket(injector))
|
var result = sendPacketAndGetResponse(PollPatchPacket(injector))
|
||||||
// So just do a syncronize to make sure we have the latest data
|
// So just do a syncronize to make sure we have the latest data
|
||||||
if (result) result = sendPacketAndGetResponse(SynchronizePacket(injector))
|
if (result) result = sendPacketAndGetResponse(SynchronizePacket(injector))
|
||||||
|
|
||||||
// Sync records (based on the info we have from the sync)
|
// Sync records (based on the info we have from the sync)
|
||||||
if (result) result = syncRecords()
|
if (result) result = syncRecords()
|
||||||
|
@ -297,7 +333,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
result = sendPacketAndGetResponse(PollPatchPacket(injector))
|
result = sendPacketAndGetResponse(PollPatchPacket(injector))
|
||||||
SystemClock.sleep(100)
|
SystemClock.sleep(100)
|
||||||
// Get our record
|
// Get our record
|
||||||
if (result) result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence))
|
if (result) result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence), COMMAND_SYNC_TIMEOUT_SEC)
|
||||||
if (result == false) break
|
if (result == false) break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -431,6 +467,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
// State for connect flow
|
// State for connect flow
|
||||||
private inner class AuthState : State() {
|
private inner class AuthState : State() {
|
||||||
|
|
||||||
val retryCounter = 0
|
val retryCounter = 0
|
||||||
|
|
||||||
override fun onEnter() {
|
override fun onEnter() {
|
||||||
|
@ -519,8 +556,8 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
LTag.PUMPCOMM,
|
LTag.PUMPCOMM,
|
||||||
"GetTimeState.onIndication need to set time. systemTime: $currTime PumpTime: ${medtrumPump.lastTimeReceivedFromPump} Pump Time to system time: " + timeUtil
|
"GetTimeState.onIndication need to set time. systemTime: $currTime PumpTime: ${medtrumPump.lastTimeReceivedFromPump} Pump Time to system time: " + timeUtil
|
||||||
.convertPumpTimeToSystemTimeMillis(
|
.convertPumpTimeToSystemTimeMillis(
|
||||||
medtrumPump.lastTimeReceivedFromPump
|
medtrumPump.lastTimeReceivedFromPump
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
// TODO: Setting time cancels any TBR, so we need to handle that and cancel? or let AAPS handle time syncs?
|
// TODO: Setting time cancels any TBR, so we need to handle that and cancel? or let AAPS handle time syncs?
|
||||||
toState(SetTimeState())
|
toState(SetTimeState())
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
<string name="medtrum_pump_shortname">MT</string>
|
<string name="medtrum_pump_shortname">MT</string>
|
||||||
<string name="medtrum_pump_description">Medtrum Nano</string>
|
<string name="medtrum_pump_description">Medtrum Nano</string>
|
||||||
<string name="medtrumpump_settings">Medtrum pump settings</string>
|
<string name="medtrumpump_settings">Medtrum pump settings</string>
|
||||||
|
<string name="pump_error">Pump error: %1$s !! </string>
|
||||||
|
|
||||||
<!-- overview fragment -->
|
<!-- overview fragment -->
|
||||||
<string name="medtrum_ble_status">BLE Status</string>
|
<string name="medtrum_ble_status">BLE Status</string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue