Merge pull request #2885 from jbr7rr/medtrum-fixes

Medtrum: Defaults and notification on warning
This commit is contained in:
Milos Kozak 2023-10-09 16:24:01 +02:00 committed by GitHub
commit 68d227239b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 11 deletions

View file

@ -138,6 +138,7 @@ open class Notification {
const val PUMP_SETTINGS_FAILED = 84 const val PUMP_SETTINGS_FAILED = 84
const val PUMP_TIMEZONE_UPDATE_FAILED = 85 const val PUMP_TIMEZONE_UPDATE_FAILED = 85
const val BLUETOOTH_NOT_SUPPORTED = 86 const val BLUETOOTH_NOT_SUPPORTED = 86
const val PUMP_WARNING = 87
const val USER_MESSAGE = 1000 const val USER_MESSAGE = 1000

View file

@ -71,6 +71,15 @@ class MedtrumPump @Inject constructor(
_activeAlarms = value _activeAlarms = value
} }
// New pump warnings
private val _pumpWarning = MutableStateFlow(AlarmState.NONE)
val pumpWarningFlow: StateFlow<AlarmState> = _pumpWarning
var pumpWarning: AlarmState
get() = _pumpWarning.value
set(value) {
_pumpWarning.value = value
}
// Prime progress as state flow // Prime progress as state flow
private val _primeProgress = MutableStateFlow(0) private val _primeProgress = MutableStateFlow(0)
val primeProgressFlow: StateFlow<Int> = _primeProgress val primeProgressFlow: StateFlow<Int> = _primeProgress

View file

@ -200,7 +200,11 @@ class NotificationPacket(val injector: HasAndroidInjector) {
val alarmState = AlarmState.values()[i] val alarmState = AlarmState.values()[i]
if ((alarmFlags shr i) and 1 != 0) { if ((alarmFlags shr i) and 1 != 0) {
// If the alarm bit is set, add the corresponding alarm to activeAlarms // If the alarm bit is set, add the corresponding alarm to activeAlarms
if (!medtrumPump.activeAlarms.contains(alarmState)) {
aapsLogger.debug(LTag.PUMPCOMM, "Adding alarm $alarmState to active alarms")
medtrumPump.addAlarm(alarmState) medtrumPump.addAlarm(alarmState)
medtrumPump.pumpWarning = alarmState
}
} else if (medtrumPump.activeAlarms.contains(alarmState)) { } else if (medtrumPump.activeAlarms.contains(alarmState)) {
// If the alarm bit is not set, and the corresponding alarm is in activeAlarms, remove it // If the alarm bit is not set, and the corresponding alarm is in activeAlarms, remove it
medtrumPump.removeAlarm(alarmState) medtrumPump.removeAlarm(alarmState)

View file

@ -164,6 +164,11 @@ class MedtrumService : DaggerService(), BLECommCallback {
handleConnectionStateChange(connectionState) handleConnectionStateChange(connectionState)
} }
} }
scope.launch {
medtrumPump.pumpWarningFlow.collect { pumpWarning ->
notifyPumpWarning(pumpWarning)
}
}
} }
override fun onDestroy() { override fun onDestroy() {
@ -317,6 +322,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
} }
// Resume suspended pump // Resume suspended pump
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector)) if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
if (result) medtrumPump.clearAlarmState()
} }
return result return result
} }
@ -420,6 +426,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
var communicationLost = false var communicationLost = false
var connectionRetryCounter = 0 var connectionRetryCounter = 0
var checkTime = medtrumPump.bolusProgressLastTimeStamp var checkTime = medtrumPump.bolusProgressLastTimeStamp
var lastSentBolusAmount: Double? = null
while (!medtrumPump.bolusStopped && !medtrumPump.bolusDone && !communicationLost) { while (!medtrumPump.bolusStopped && !medtrumPump.bolusDone && !communicationLost) {
SystemClock.sleep(100) SystemClock.sleep(100)
@ -436,10 +443,15 @@ class MedtrumService : DaggerService(), BLECommCallback {
disconnect("Communication stopped") disconnect("Communication stopped")
} }
} else { } else {
val currentBolusAmount = medtrumPump.bolusingTreatment?.insulin
if (currentBolusAmount != null && currentBolusAmount != lastSentBolusAmount) {
bolusingEvent.t = medtrumPump.bolusingTreatment bolusingEvent.t = medtrumPump.bolusingTreatment
bolusingEvent.status = rh.gs(info.nightscout.pump.common.R.string.bolus_delivered_so_far, medtrumPump.bolusingTreatment?.insulin, medtrumPump.bolusAmountToBeDelivered) bolusingEvent.status = rh.gs(info.nightscout.pump.common.R.string.bolus_delivered_so_far, medtrumPump.bolusingTreatment?.insulin, medtrumPump.bolusAmountToBeDelivered)
bolusingEvent.percent = round((medtrumPump.bolusingTreatment?.insulin?.div(medtrumPump.bolusAmountToBeDelivered) ?: 0.0) * 100).toInt() - 1 bolusingEvent.percent = round(currentBolusAmount.div(medtrumPump.bolusAmountToBeDelivered) * 100).toInt() - 1
rxBus.send(bolusingEvent) rxBus.send(bolusingEvent)
lastSentBolusAmount = currentBolusAmount
}
} }
} }
@ -577,6 +589,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
when (state) { when (state) {
MedtrumPumpState.NONE, MedtrumPumpState.NONE,
MedtrumPumpState.STOPPED -> { MedtrumPumpState.STOPPED -> {
rxBus.send(EventDismissNotification(Notification.PUMP_WARNING))
rxBus.send(EventDismissNotification(Notification.PUMP_ERROR)) rxBus.send(EventDismissNotification(Notification.PUMP_ERROR))
rxBus.send(EventDismissNotification(Notification.PUMP_SUSPENDED)) rxBus.send(EventDismissNotification(Notification.PUMP_SUSPENDED))
uiInteraction.addNotification( uiInteraction.addNotification(
@ -607,7 +620,6 @@ class MedtrumService : DaggerService(), BLECommCallback {
MedtrumPumpState.ACTIVE_ALT -> { MedtrumPumpState.ACTIVE_ALT -> {
rxBus.send(EventDismissNotification(Notification.PATCH_NOT_ACTIVE)) rxBus.send(EventDismissNotification(Notification.PATCH_NOT_ACTIVE))
rxBus.send(EventDismissNotification(Notification.PUMP_SUSPENDED)) rxBus.send(EventDismissNotification(Notification.PUMP_SUSPENDED))
medtrumPump.clearAlarmState()
} }
MedtrumPumpState.LOW_BG_SUSPENDED, MedtrumPumpState.LOW_BG_SUSPENDED,
@ -625,20 +637,22 @@ class MedtrumService : DaggerService(), BLECommCallback {
} }
MedtrumPumpState.HOURLY_MAX_SUSPENDED -> { MedtrumPumpState.HOURLY_MAX_SUSPENDED -> {
uiInteraction.addNotification( uiInteraction.addNotificationWithSound(
Notification.PUMP_SUSPENDED, Notification.PUMP_SUSPENDED,
rh.gs(R.string.pump_is_suspended_hour_max), rh.gs(R.string.pump_is_suspended_hour_max),
Notification.NORMAL, Notification.URGENT,
app.aaps.core.ui.R.raw.alarm
) )
// Pump will report proper TBR for this from loadEvents() // Pump will report proper TBR for this from loadEvents()
commandQueue.loadEvents(null) commandQueue.loadEvents(null)
} }
MedtrumPumpState.DAILY_MAX_SUSPENDED -> { MedtrumPumpState.DAILY_MAX_SUSPENDED -> {
uiInteraction.addNotification( uiInteraction.addNotificationWithSound(
Notification.PUMP_SUSPENDED, Notification.PUMP_SUSPENDED,
rh.gs(R.string.pump_is_suspended_day_max), rh.gs(R.string.pump_is_suspended_day_max),
Notification.NORMAL, Notification.URGENT,
app.aaps.core.ui.R.raw.alarm
) )
// Pump will report proper TBR for this from loadEvents() // Pump will report proper TBR for this from loadEvents()
commandQueue.loadEvents(null) commandQueue.loadEvents(null)
@ -683,6 +697,23 @@ class MedtrumService : DaggerService(), BLECommCallback {
} }
} }
private fun notifyPumpWarning(alarmState: AlarmState) {
// Notification on pump warning
if (sp.getBoolean(R.string.key_pump_warning_notification, true) && alarmState != AlarmState.NONE) {
uiInteraction.addNotification(
Notification.PUMP_WARNING,
rh.gs(R.string.pump_warning, medtrumPump.alarmStateToString(alarmState)),
Notification.ANNOUNCEMENT,
)
pumpSync.insertAnnouncement(
medtrumPump.alarmStateToString(alarmState),
null,
medtrumPump.pumpType(),
medtrumPump.pumpSN.toString(radix = 16)
)
}
}
/** BLECommCallbacks */ /** BLECommCallbacks */
override fun onBLEConnected() { override fun onBLEConnected() {
aapsLogger.debug(LTag.PUMPCOMM, "<<<<< onBLEConnected") aapsLogger.debug(LTag.PUMPCOMM, "<<<<< onBLEConnected")

View file

@ -4,6 +4,7 @@
<string name="key_sn_input" translatable="false">sn_input</string> <string name="key_sn_input" translatable="false">sn_input</string>
<string name="key_alarm_setting" translatable="false">alarm_setting</string> <string name="key_alarm_setting" translatable="false">alarm_setting</string>
<string name="key_patch_expiration" translatable="false">patch_expiration</string> <string name="key_patch_expiration" translatable="false">patch_expiration</string>
<string name="key_pump_warning_notification" translatable="false">pump_warning_notification</string>
<string name="key_hourly_max_insulin" translatable="false">hourly_max_insulin</string> <string name="key_hourly_max_insulin" translatable="false">hourly_max_insulin</string>
<string name="key_daily_max_insulin" translatable="false">daily_max_insulin</string> <string name="key_daily_max_insulin" translatable="false">daily_max_insulin</string>
@ -30,6 +31,7 @@
<string name="medtrum_pump_description">Pump integration for Medtrum Nano and Medtrum 300U</string> <string name="medtrum_pump_description">Pump integration for Medtrum Nano and Medtrum 300U</string>
<string name="medtrum_pump_setting">Medtrum pump settings</string> <string name="medtrum_pump_setting">Medtrum pump settings</string>
<string name="pump_error">Pump error: %1$s !! </string> <string name="pump_error">Pump error: %1$s !! </string>
<string name="pump_warning">Pump warning: %1$s </string>
<string name="pump_is_suspended">Pump is suspended</string> <string name="pump_is_suspended">Pump is suspended</string>
<string name="pump_is_suspended_hour_max">Pump is suspended due to hourly max insulin exceeded</string> <string name="pump_is_suspended_hour_max">Pump is suspended due to hourly max insulin exceeded</string>
<string name="pump_is_suspended_day_max">Pump is suspended due to daily max insulin exceeded</string> <string name="pump_is_suspended_day_max">Pump is suspended due to daily max insulin exceeded</string>
@ -138,6 +140,8 @@
<string name="pump_unsupported">Pump untested: %1$d! Please contact us at discord or github for support</string> <string name="pump_unsupported">Pump untested: %1$d! Please contact us at discord or github for support</string>
<string name="alarm_setting_title">Alarm Settings</string> <string name="alarm_setting_title">Alarm Settings</string>
<string name="alarm_setting_summary">Select your preferred pump alarm settings.</string> <string name="alarm_setting_summary">Select your preferred pump alarm settings.</string>
<string name="pump_warning_notification_title">Notification on pump warning</string>
<string name="pump_warning_notification_summary">Show notification on non critical pump warnings: low battery, low reservoir (20 units) and expires soon. Recommended to leave enabled when pump alarms are set to silent.</string>
<string name="patch_expiration_title">Patch Expiration</string> <string name="patch_expiration_title">Patch Expiration</string>
<string name="patch_expiration_summary">When enabled, the patch will expire after 3 days, with a grace period of 8 hours after that.</string> <string name="patch_expiration_summary">When enabled, the patch will expire after 3 days, with a grace period of 8 hours after that.</string>
<string name="hourly_max_insulin_title">Hourly Maximum Insulin</string> <string name="hourly_max_insulin_title">Hourly Maximum Insulin</string>

View file

@ -14,7 +14,7 @@
android:title="@string/sn_input_title" /> android:title="@string/sn_input_title" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="true"
android:key="@string/key_patch_expiration" android:key="@string/key_patch_expiration"
android:title="@string/patch_expiration_title" android:title="@string/patch_expiration_title"
android:summary="@string/patch_expiration_summary" /> android:summary="@string/patch_expiration_summary" />
@ -27,6 +27,12 @@
android:entries="@array/alarmSettings" android:entries="@array/alarmSettings"
android:entryValues="@array/alarmSettingsValues" /> android:entryValues="@array/alarmSettingsValues" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_pump_warning_notification"
android:title="@string/pump_warning_notification_title"
android:summary="@string/pump_warning_notification_summary" />
<app.aaps.core.validators.ValidatingEditTextPreference <app.aaps.core.validators.ValidatingEditTextPreference
android:defaultValue="25" android:defaultValue="25"
android:inputType="number" android:inputType="number"