From 5945aa40ab989b374529d11f3b84268f384c3ec0 Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Sun, 8 Oct 2023 11:33:40 +0200 Subject: [PATCH] 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 + } } }