Medtrum: Do not spam event bus on bolus progress

This commit is contained in:
jbr7rr 2023-10-08 11:33:40 +02:00
parent bface2a24d
commit 5945aa40ab

View file

@ -420,6 +420,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 +437,15 @@ class MedtrumService : DaggerService(), BLECommCallback {
disconnect("Communication stopped") disconnect("Communication stopped")
} }
} else { } else {
bolusingEvent.t = medtrumPump.bolusingTreatment val currentBolusAmount = medtrumPump.bolusingTreatment?.insulin
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 if (currentBolusAmount != null && currentBolusAmount != lastSentBolusAmount) {
rxBus.send(bolusingEvent) 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
}
} }
} }