From bface2a24dddcf82ac06388e18ad947be8029f5c Mon Sep 17 00:00:00 2001
From: jbr7rr <>
Date: Sun, 8 Oct 2023 08:41:38 +0200
Subject: [PATCH 1/4] Medtrum: Patch expiration default to true
---
pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml b/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml
index 3e929bdcbb..b27de7bd1e 100644
--- a/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml
+++ b/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml
@@ -14,7 +14,7 @@
android:title="@string/sn_input_title" />
From 5945aa40ab989b374529d11f3b84268f384c3ec0 Mon Sep 17 00:00:00 2001
From: jbr7rr <>
Date: Sun, 8 Oct 2023 11:33:40 +0200
Subject: [PATCH 2/4] Medtrum: Do not spam event bus on bolus progress
---
.../pump/medtrum/services/MedtrumService.kt | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
index 91057b7aaf..ca6d0207aa 100644
--- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
+++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
@@ -420,6 +420,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
var communicationLost = false
var connectionRetryCounter = 0
var checkTime = medtrumPump.bolusProgressLastTimeStamp
+ var lastSentBolusAmount: Double? = null
while (!medtrumPump.bolusStopped && !medtrumPump.bolusDone && !communicationLost) {
SystemClock.sleep(100)
@@ -436,10 +437,15 @@ class MedtrumService : DaggerService(), BLECommCallback {
disconnect("Communication stopped")
}
} else {
- bolusingEvent.t = medtrumPump.bolusingTreatment
- 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
- rxBus.send(bolusingEvent)
+ val currentBolusAmount = medtrumPump.bolusingTreatment?.insulin
+
+ if (currentBolusAmount != null && currentBolusAmount != lastSentBolusAmount) {
+ bolusingEvent.t = medtrumPump.bolusingTreatment
+ bolusingEvent.status = rh.gs(info.nightscout.pump.common.R.string.bolus_delivered_so_far, medtrumPump.bolusingTreatment?.insulin, medtrumPump.bolusAmountToBeDelivered)
+ bolusingEvent.percent = round(currentBolusAmount.div(medtrumPump.bolusAmountToBeDelivered) * 100).toInt() - 1
+ rxBus.send(bolusingEvent)
+ lastSentBolusAmount = currentBolusAmount
+ }
}
}
From ccb7961e50dc84494e7c2d912904846f7333948d Mon Sep 17 00:00:00 2001
From: jbr7rr <>
Date: Sun, 8 Oct 2023 12:16:09 +0200
Subject: [PATCH 3/4] Medtrum: Option to show notification on non critical pump
alerts
---
.../interfaces/notifications/Notification.kt | 1 +
.../nightscout/pump/medtrum/MedtrumPump.kt | 9 +++++
.../comm/packets/NotificationPacket.kt | 6 +++-
.../pump/medtrum/services/MedtrumService.kt | 33 ++++++++++++++++---
pump/medtrum/src/main/res/values/strings.xml | 4 +++
.../src/main/res/xml/pref_medtrum_pump.xml | 6 ++++
6 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt b/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt
index ba138abaf8..f9eb549c7b 100644
--- a/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt
+++ b/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt
@@ -138,6 +138,7 @@ open class Notification {
const val PUMP_SETTINGS_FAILED = 84
const val PUMP_TIMEZONE_UPDATE_FAILED = 85
const val BLUETOOTH_NOT_SUPPORTED = 86
+ const val PUMP_WARNING = 87
const val USER_MESSAGE = 1000
diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt
index 48cba7b7a9..4a7f99e566 100644
--- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt
+++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt
@@ -71,6 +71,15 @@ class MedtrumPump @Inject constructor(
_activeAlarms = value
}
+ // New pump warnings
+ private val _pumpWarning = MutableStateFlow(AlarmState.NONE)
+ val pumpWarningFlow: StateFlow = _pumpWarning
+ var pumpWarning: AlarmState
+ get() = _pumpWarning.value
+ set(value) {
+ _pumpWarning.value = value
+ }
+
// Prime progress as state flow
private val _primeProgress = MutableStateFlow(0)
val primeProgressFlow: StateFlow = _primeProgress
diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt
index cc3d1c9178..32ed8e39d6 100644
--- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt
+++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt
@@ -200,7 +200,11 @@ class NotificationPacket(val injector: HasAndroidInjector) {
val alarmState = AlarmState.values()[i]
if ((alarmFlags shr i) and 1 != 0) {
// If the alarm bit is set, add the corresponding alarm to activeAlarms
- medtrumPump.addAlarm(alarmState)
+ if (!medtrumPump.activeAlarms.contains(alarmState)) {
+ aapsLogger.debug(LTag.PUMPCOMM, "Adding alarm $alarmState to active alarms")
+ medtrumPump.addAlarm(alarmState)
+ medtrumPump.pumpWarning = alarmState
+ }
} else if (medtrumPump.activeAlarms.contains(alarmState)) {
// If the alarm bit is not set, and the corresponding alarm is in activeAlarms, remove it
medtrumPump.removeAlarm(alarmState)
diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
index ca6d0207aa..d60ab4936d 100644
--- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
+++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
@@ -164,6 +164,11 @@ class MedtrumService : DaggerService(), BLECommCallback {
handleConnectionStateChange(connectionState)
}
}
+ scope.launch {
+ medtrumPump.pumpWarningFlow.collect { pumpWarning ->
+ notifyPumpWarning(pumpWarning)
+ }
+ }
}
override fun onDestroy() {
@@ -583,6 +588,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
when (state) {
MedtrumPumpState.NONE,
MedtrumPumpState.STOPPED -> {
+ rxBus.send(EventDismissNotification(Notification.PUMP_WARNING))
rxBus.send(EventDismissNotification(Notification.PUMP_ERROR))
rxBus.send(EventDismissNotification(Notification.PUMP_SUSPENDED))
uiInteraction.addNotification(
@@ -631,20 +637,22 @@ class MedtrumService : DaggerService(), BLECommCallback {
}
MedtrumPumpState.HOURLY_MAX_SUSPENDED -> {
- uiInteraction.addNotification(
+ uiInteraction.addNotificationWithSound(
Notification.PUMP_SUSPENDED,
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()
commandQueue.loadEvents(null)
}
MedtrumPumpState.DAILY_MAX_SUSPENDED -> {
- uiInteraction.addNotification(
+ uiInteraction.addNotificationWithSound(
Notification.PUMP_SUSPENDED,
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()
commandQueue.loadEvents(null)
@@ -689,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 */
override fun onBLEConnected() {
aapsLogger.debug(LTag.PUMPCOMM, "<<<<< onBLEConnected")
diff --git a/pump/medtrum/src/main/res/values/strings.xml b/pump/medtrum/src/main/res/values/strings.xml
index 147c018513..b508b7150d 100644
--- a/pump/medtrum/src/main/res/values/strings.xml
+++ b/pump/medtrum/src/main/res/values/strings.xml
@@ -4,6 +4,7 @@
sn_input
alarm_setting
patch_expiration
+ pump_warning_notification
hourly_max_insulin
daily_max_insulin
@@ -30,6 +31,7 @@
Pump integration for Medtrum Nano and Medtrum 300U
Medtrum pump settings
Pump error: %1$s !!
+ Pump warning: %1$s
Pump is suspended
Pump is suspended due to hourly max insulin exceeded
Pump is suspended due to daily max insulin exceeded
@@ -138,6 +140,8 @@
Pump untested: %1$d! Please contact us at discord or github for support
Alarm Settings
Select your preferred pump alarm settings.
+ Notification on pump warning
+ 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.
Patch Expiration
When enabled, the patch will expire after 3 days, with a grace period of 8 hours after that.
Hourly Maximum Insulin
diff --git a/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml b/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml
index b27de7bd1e..4e4ff321ba 100644
--- a/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml
+++ b/pump/medtrum/src/main/res/xml/pref_medtrum_pump.xml
@@ -27,6 +27,12 @@
android:entries="@array/alarmSettings"
android:entryValues="@array/alarmSettingsValues" />
+
+
Date: Sun, 8 Oct 2023 19:49:40 +0200
Subject: [PATCH 4/4] Medtrum: Do not clearAlarms on going to ACTIVE
---
.../info/nightscout/pump/medtrum/services/MedtrumService.kt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
index d60ab4936d..c04f5e9f1d 100644
--- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
+++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt
@@ -322,6 +322,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
}
// Resume suspended pump
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
+ if (result) medtrumPump.clearAlarmState()
}
return result
}
@@ -619,7 +620,6 @@ class MedtrumService : DaggerService(), BLECommCallback {
MedtrumPumpState.ACTIVE_ALT -> {
rxBus.send(EventDismissNotification(Notification.PATCH_NOT_ACTIVE))
rxBus.send(EventDismissNotification(Notification.PUMP_SUSPENDED))
- medtrumPump.clearAlarmState()
}
MedtrumPumpState.LOW_BG_SUSPENDED,