From 0434fc746803b725f9df01fe18c38911c6062014 Mon Sep 17 00:00:00 2001 From: jbr7rr Date: Wed, 13 Nov 2024 12:35:26 +0100 Subject: [PATCH 1/2] Medtrum: Clarify bolus error, clarify sync status --- .../java/info/nightscout/pump/medtrum/MedtrumPlugin.kt | 5 ++--- .../java/info/nightscout/pump/medtrum/MedtrumPump.kt | 3 +++ .../nightscout/pump/medtrum/services/MedtrumService.kt | 10 ++++++++++ pump/medtrum/src/main/res/values/strings.xml | 8 ++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt index 45b1ddfd3fa..95102a85b21 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt @@ -397,10 +397,9 @@ import kotlin.math.abs result.success = connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep result.bolusDelivered = t.insulin if (!result.success) { - // Note: There are no error codes - result.comment = "failed" + result.comment(medtrumPump.bolusErrorReason ?: rh.gs(R.string.bolus_error_reason_pump_error)) } else { - result.comment = "ok" + result.comment(app.aaps.core.ui.R.string.ok) } aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Success: ${result.success} Asked: ${detailedBolusInfo.insulin} Delivered: ${result.bolusDelivered}") return result 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 a59edda971e..fdcec62530e 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 @@ -250,10 +250,13 @@ class MedtrumPump @Inject constructor( _bolusAmountToBeDelivered = value sp.putDouble(R.string.key_bolus_amount_to_be_delivered, value) } + + var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment var bolusProgressLastTimeStamp: Long = 0 // timestamp of last bolus progress message var bolusStopped = false // bolus stopped by user var bolusDone = true // Bolus completed or stopped on pump, initialize as true as to don't show bolus on init + var bolusErrorReason: String? = null private val _bolusAmountDelivered = MutableStateFlow(0.0) val bolusAmountDeliveredFlow: StateFlow = _bolusAmountDelivered 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 af367c30d01..a9c71afa709 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 @@ -315,6 +315,8 @@ class MedtrumService : DaggerService(), BLECommCallback { } else { aapsLogger.error(LTag.PUMPCOMM, "Failed to load events") } + // Update ui text to getting pump status (indicating syncing records is finished) + rxBus.send(EventPumpStatusChanged(rh.gs(R.string.getting_pump_status))) return result } @@ -352,8 +354,10 @@ class MedtrumService : DaggerService(), BLECommCallback { val insulin = detailedBolusInfo.insulin medtrumPump.bolusDone = false medtrumPump.bolusStopped = false + medtrumPump.bolusErrorReason = null if (!sendBolusCommand(insulin)) { + medtrumPump.bolusErrorReason = rh.gs(R.string.bolus_error_reason_unable_to_send_command) aapsLogger.error(LTag.PUMPCOMM, "Failed to set bolus") commandQueue.readStatus(rh.gs(R.string.bolus_error), null) // make sure if anything is delivered (which is highly unlikely at this point) we get it medtrumPump.bolusDone = true @@ -414,14 +418,17 @@ class MedtrumService : DaggerService(), BLECommCallback { private fun canSetBolus(): Boolean { if (!isConnected) { aapsLogger.warn(LTag.PUMPCOMM, "Pump not connected, not setting bolus") + medtrumPump.bolusErrorReason = rh.gs(R.string.bolus_error_reason_not_connected) return false } if (BolusProgressData.stopPressed) { aapsLogger.warn(LTag.PUMPCOMM, "Bolus stop pressed, not setting bolus") + medtrumPump.bolusErrorReason = rh.gs(R.string.bolus_error_reason_user) return false } if (!medtrumPump.bolusDone) { aapsLogger.warn(LTag.PUMPCOMM, "Bolus already in progress, not setting new one") + medtrumPump.bolusErrorReason = rh.gs(R.string.bolus_error_reason_already_in_progress) return false } return true @@ -454,6 +461,7 @@ class MedtrumService : DaggerService(), BLECommCallback { connectionRetryCounter++ } else { communicationLost = true + medtrumPump.bolusErrorReason = rh.gs(R.string.bolus_error_reason_communication_lost) aapsLogger.warn(LTag.PUMPCOMM, "Retry connection failed, communication stopped") disconnect("Communication stopped") } @@ -494,6 +502,7 @@ class MedtrumService : DaggerService(), BLECommCallback { fun stopBolus() { aapsLogger.debug(LTag.PUMPCOMM, "bolusStop >>>>> @ " + if (medtrumPump.bolusingTreatment == null) "" else medtrumPump.bolusingTreatment?.insulin) + medtrumPump.bolusErrorReason = rh.gs(R.string.bolus_error_reason_user) if (isConnected) { var success = sendPacketAndGetResponse(CancelBolusPacket(injector)) val timeout = System.currentTimeMillis() + T.secs(30).msecs() @@ -563,6 +572,7 @@ class MedtrumService : DaggerService(), BLECommCallback { var failureCount = 0 if (medtrumPump.syncedSequenceNumber < medtrumPump.currentSequenceNumber) { for (sequence in (medtrumPump.syncedSequenceNumber + 1)..medtrumPump.currentSequenceNumber) { + rxBus.send(EventPumpStatusChanged(rh.gs(R.string.syncing_records, (medtrumPump.currentSequenceNumber - sequence + 1)))) val packet = GetRecordPacket(injector, sequence) result = sendPacketAndGetResponse(packet, COMMAND_SYNC_TIMEOUT_SEC) if (!result && packet.failed) { diff --git a/pump/medtrum/src/main/res/values/strings.xml b/pump/medtrum/src/main/res/values/strings.xml index e5ac7972ed6..025ea7d9bb0 100644 --- a/pump/medtrum/src/main/res/values/strings.xml +++ b/pump/medtrum/src/main/res/values/strings.xml @@ -162,8 +162,16 @@ Getting pump status + Syncing records, %1$d left Getting bolus status Getting temporary basal status Setting user options + + Bolus cancelled by user + Pump not connected + Bolus already in progress + Unable to send bolus command + Timeout getting bolus status + Pump error From 1624e699b52c636b631752770cfac3a51aded0a9 Mon Sep 17 00:00:00 2001 From: jbr7rr Date: Wed, 13 Nov 2024 12:35:45 +0100 Subject: [PATCH 2/2] Clarify bolus error text --- core/ui/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index cf81c5e8675..6f5ed8199ad 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -114,7 +114,7 @@ BG Calibration Run alarm in %1$d min - Bolus reported an error. Manually check real delivered amount + Bolus reported an error. Manually check real delivered insulin and carb amount Bolus reminder Duration g