Medtrum: Check for bolus in progress
This commit is contained in:
parent
6ebec7935d
commit
0c38967c00
3 changed files with 38 additions and 31 deletions
|
@ -49,14 +49,12 @@ class SynchronizePacket(injector: HasAndroidInjector) : MedtrumPacket(injector)
|
|||
aapsLogger.debug(LTag.PUMPCOMM, "SynchronizePacket: fieldMask: $fieldMask")
|
||||
}
|
||||
|
||||
// Remove bolus fields from fieldMask if fields are present (we sync bolus trough other commands)
|
||||
// Remove extended bolus field from fieldMask if field is present (extended bolus is not supported)
|
||||
if (fieldMask and MASK_SUSPEND != 0) {
|
||||
offset += 4 // If field is present, skip 4 bytes
|
||||
}
|
||||
if (fieldMask and MASK_NORMAL_BOLUS != 0) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "SynchronizePacket: Normal bolus present removing from fieldMask")
|
||||
fieldMask = fieldMask and MASK_NORMAL_BOLUS.inv()
|
||||
syncData = syncData.copyOfRange(0, offset) + syncData.copyOfRange(offset + 3, syncData.size)
|
||||
offset += 3 // If field is present, skip 3 bytes
|
||||
}
|
||||
if (fieldMask and MASK_EXTENDED_BOLUS != 0) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "SynchronizePacket: Extended bolus present removing from fieldMask")
|
||||
|
|
|
@ -287,20 +287,22 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
|||
}
|
||||
|
||||
fun setBolus(detailedBolusInfo: DetailedBolusInfo, t: EventOverviewBolusProgress.Treatment): Boolean {
|
||||
if (!isConnected) return false
|
||||
if (BolusProgressData.stopPressed) return false
|
||||
if (!isConnected) {
|
||||
aapsLogger.warn(LTag.PUMPCOMM, "Pump not connected, not setting bolus")
|
||||
return false
|
||||
}
|
||||
if (BolusProgressData.stopPressed) {
|
||||
aapsLogger.warn(LTag.PUMPCOMM, "Bolus stop pressed, not setting bolus")
|
||||
return false
|
||||
}
|
||||
if (!medtrumPump.bolusDone) {
|
||||
aapsLogger.warn(LTag.PUMPCOMM, "Bolus already in progress, not setting new one")
|
||||
return false
|
||||
}
|
||||
|
||||
val insulin = detailedBolusInfo.insulin
|
||||
val bolusStart = System.currentTimeMillis()
|
||||
|
||||
medtrumPump.bolusDone = false
|
||||
medtrumPump.bolusingTreatment = t
|
||||
medtrumPump.bolusAmountToBeDelivered = insulin
|
||||
medtrumPump.bolusStopped = false
|
||||
medtrumPump.bolusProgressLastTimeStamp = bolusStart
|
||||
|
||||
if (insulin > 0) {
|
||||
val result = sendPacketAndGetResponse(SetBolusPacket(injector, insulin))
|
||||
if (!result) {
|
||||
if (!sendPacketAndGetResponse(SetBolusPacket(injector, insulin))) {
|
||||
aapsLogger.error(LTag.PUMPCOMM, "Failed to set bolus")
|
||||
commandQueue.loadEvents(null) // make sure if anything is delivered (which is highly unlikely at this point) we get it
|
||||
t.insulin = 0.0
|
||||
|
@ -312,6 +314,13 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
|||
return false
|
||||
}
|
||||
|
||||
val bolusStart = System.currentTimeMillis()
|
||||
medtrumPump.bolusDone = false
|
||||
medtrumPump.bolusingTreatment = t
|
||||
medtrumPump.bolusAmountToBeDelivered = insulin
|
||||
medtrumPump.bolusStopped = false
|
||||
medtrumPump.bolusProgressLastTimeStamp = bolusStart
|
||||
|
||||
detailedBolusInfo.timestamp = bolusStart // Make sure the timestamp is set to the start of the bolus
|
||||
detailedBolusInfoStorage.add(detailedBolusInfo) // will be picked up on reading history
|
||||
// Sync the initial bolus
|
||||
|
|
Loading…
Reference in a new issue