This commit is contained in:
Andrei Vereha 2021-06-19 14:31:14 +02:00
parent d4a73abbf3
commit a0b64a9062
5 changed files with 63 additions and 30 deletions

View file

@ -198,7 +198,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
activeCommandEntry = { historyId -> activeCommandEntry = { historyId ->
podStateManager.createActiveCommand(historyId, basalProgram = basalProgram) podStateManager.createActiveCommand(historyId, basalProgram = basalProgram)
}, },
command = omnipodManager.setBasalProgram(basalProgram).ignoreElements(), command = omnipodManager.setBasalProgram(basalProgram, hasBasalBeepEnabled()).ignoreElements(),
post = failWhenUnconfirmed(), post = failWhenUnconfirmed(),
).toPumpEnactResult() ).toPumpEnactResult()
} }
@ -218,7 +218,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
else else
executeProgrammingCommand( executeProgrammingCommand(
historyEntry = history.createRecord(OmnipodCommandType.SUSPEND_DELIVERY), historyEntry = history.createRecord(OmnipodCommandType.SUSPEND_DELIVERY),
command = omnipodManager.suspendDelivery() command = omnipodManager.suspendDelivery(hasBasalBeepEnabled())
.filter { podEvent -> podEvent.isCommandSent() } .filter { podEvent -> podEvent.isCommandSent() }
.map { .map {
pumpSyncTempBasal( pumpSyncTempBasal(
@ -293,8 +293,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
try { try {
aapsLogger.info(LTag.PUMP, "Delivering treatment: $detailedBolusInfo") aapsLogger.info(LTag.PUMP, "Delivering treatment: $detailedBolusInfo")
val bolusBeeps = sp.getBoolean(R.string.key_omnipod_common_bolus_beeps_enabled, false) val beepsConfigurationKey = if (detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB)
R.string.key_omnipod_common_smb_beeps_enabled
else
R.string.key_omnipod_common_bolus_beeps_enabled
val bolusBeeps = sp.getBoolean(beepsConfigurationKey, false)
R.string.key_omnipod_common_smb_beeps_enabled
if (detailedBolusInfo.carbs > 0 || if (detailedBolusInfo.carbs > 0 ||
detailedBolusInfo.insulin == 0.0 detailedBolusInfo.insulin == 0.0
) { ) {
@ -451,9 +455,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
private fun cancelBolus(): Completable { private fun cancelBolus(): Completable {
val bolusBeeps = sp.getBoolean(R.string.key_omnipod_common_bolus_beeps_enabled, false)
return executeProgrammingCommand( return executeProgrammingCommand(
historyEntry = history.createRecord(commandType = OmnipodCommandType.CANCEL_BOLUS), historyEntry = history.createRecord(commandType = OmnipodCommandType.CANCEL_BOLUS),
command = omnipodManager.stopBolus().ignoreElements() command = omnipodManager.stopBolus(bolusBeeps).ignoreElements()
) )
} }
@ -497,7 +502,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
enforceNew: Boolean, enforceNew: Boolean,
tbrType: PumpSync.TemporaryBasalType tbrType: PumpSync.TemporaryBasalType
): PumpEnactResult { ): PumpEnactResult {
val tempBasalBeeps = sp.getBoolean(R.string.key_omnipod_common_tbr_beeps_enabled, false) val tempBasalBeeps = hasTempBasalBeepEnabled()
aapsLogger.info( aapsLogger.info(
LTag.PUMP, LTag.PUMP,
"setTempBasalAbsolute: duration=$durationInMinutes min, rate=$absoluteRate U/h :: " + "setTempBasalAbsolute: duration=$durationInMinutes min, rate=$absoluteRate U/h :: " +
@ -586,7 +591,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
aapsLogger.info(LTag.PUMP, "Canceling existing temp basal") aapsLogger.info(LTag.PUMP, "Canceling existing temp basal")
executeProgrammingCommand( executeProgrammingCommand(
historyEntry = history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), historyEntry = history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL),
command = omnipodManager.stopTempBasal().ignoreElements() command = omnipodManager.stopTempBasal(hasTempBasalBeepEnabled()).ignoreElements()
) )
} }
} }
@ -611,6 +616,14 @@ class OmnipodDashPumpPlugin @Inject constructor(
.comment("Omnipod Dash driver does not support extended boluses") .comment("Omnipod Dash driver does not support extended boluses")
} }
private fun hasTempBasalBeepEnabled(): Boolean {
return sp.getBoolean(R.string.key_omnipod_common_tbr_beeps_enabled, false)
}
private fun hasBasalBeepEnabled(): Boolean {
return sp.getBoolean(R.string.key_omnipod_common_basal_beeps_enabled, false)
}
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult {
if (!podStateManager.tempBasalActive && if (!podStateManager.tempBasalActive &&
pumpSync.expectedPumpState().temporaryBasal == null pumpSync.expectedPumpState().temporaryBasal == null
@ -621,7 +634,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
return executeProgrammingCommand( return executeProgrammingCommand(
historyEntry = history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), historyEntry = history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL),
command = omnipodManager.stopTempBasal().ignoreElements(), command = omnipodManager.stopTempBasal(hasTempBasalBeepEnabled()).ignoreElements(),
).toPumpEnactResult() ).toPumpEnactResult()
} }
@ -728,7 +741,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
private fun suspendDelivery(): PumpEnactResult { private fun suspendDelivery(): PumpEnactResult {
return executeProgrammingCommand( return executeProgrammingCommand(
historyEntry = history.createRecord(OmnipodCommandType.SUSPEND_DELIVERY), historyEntry = history.createRecord(OmnipodCommandType.SUSPEND_DELIVERY),
command = omnipodManager.suspendDelivery() command = omnipodManager.suspendDelivery(hasBasalBeepEnabled())
.filter { podEvent -> podEvent.isCommandSent() } .filter { podEvent -> podEvent.isCommandSent() }
.map { .map {
pumpSyncTempBasal( pumpSyncTempBasal(
@ -754,7 +767,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
executeProgrammingCommand( executeProgrammingCommand(
pre = observeDeliverySuspended(), pre = observeDeliverySuspended(),
historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY), historyEntry = history.createRecord(OmnipodCommandType.RESUME_DELIVERY),
command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(it)).ignoreElements() command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(it), hasBasalBeepEnabled()).ignoreElements()
).toPumpEnactResult() ).toPumpEnactResult()
} ?: PumpEnactResult(injector).success(false).enacted(false).comment("No profile active") // TODO i18n } ?: PumpEnactResult(injector).success(false).enacted(false).comment("No profile active") // TODO i18n
} }

View file

@ -18,19 +18,19 @@ interface OmnipodDashManager {
fun getStatus(type: ResponseType.StatusResponseType): Observable<PodEvent> fun getStatus(type: ResponseType.StatusResponseType): Observable<PodEvent>
fun setBasalProgram(basalProgram: BasalProgram): Observable<PodEvent> fun setBasalProgram(basalProgram: BasalProgram, hasBasalBeepEnabled: Boolean): Observable<PodEvent>
fun suspendDelivery(): Observable<PodEvent> fun suspendDelivery(hasBasalBeepEnabled: Boolean): Observable<PodEvent>
fun setTime(): Observable<PodEvent> fun setTime(): Observable<PodEvent>
fun setTempBasal(rate: Double, durationInMinutes: Short, tempBasalBeeps: Boolean): Observable<PodEvent> fun setTempBasal(rate: Double, durationInMinutes: Short, tempBasalBeeps: Boolean): Observable<PodEvent>
fun stopTempBasal(): Observable<PodEvent> fun stopTempBasal(hasTempBasalBeepEnabled: Boolean): Observable<PodEvent>
fun bolus(units: Double, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent> fun bolus(units: Double, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent>
fun stopBolus(): Observable<PodEvent> fun stopBolus(beep: Boolean): Observable<PodEvent>
fun playBeep(beepType: BeepType): Observable<PodEvent> fun playBeep(beepType: BeepType): Observable<PodEvent>

View file

@ -157,7 +157,7 @@ class OmnipodDashManagerImpl @Inject constructor(
} }
} }
private fun observeSendProgramBasalCommand(basalProgram: BasalProgram): Observable<PodEvent> { private fun observeSendProgramBasalCommand(basalProgram: BasalProgram, hasBasalBeepEnabled: Boolean): Observable<PodEvent> {
return Observable.defer { return Observable.defer {
val currentTime = Date() val currentTime = Date()
logger.debug(LTag.PUMPCOMM, "Programming basal. currentTime={}, basalProgram={}", currentTime, basalProgram) logger.debug(LTag.PUMPCOMM, "Programming basal. currentTime={}, basalProgram={}", currentTime, basalProgram)
@ -166,7 +166,7 @@ class OmnipodDashManagerImpl @Inject constructor(
.setUniqueId(podStateManager.uniqueId!!.toInt()) .setUniqueId(podStateManager.uniqueId!!.toInt())
.setSequenceNumber(podStateManager.messageSequenceNumber) .setSequenceNumber(podStateManager.messageSequenceNumber)
.setNonce(NONCE) .setNonce(NONCE)
.setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0)) .setProgramReminder(ProgramReminder(atStart = hasBasalBeepEnabled, atEnd = hasBasalBeepEnabled, atInterval = 0))
.setBasalProgram(basalProgram) .setBasalProgram(basalProgram)
.setCurrentTime(currentTime) .setCurrentTime(currentTime)
.build(), .build(),
@ -399,7 +399,7 @@ class OmnipodDashManagerImpl @Inject constructor(
} }
if (podStateManager.activationProgress.isBefore(ActivationProgress.PROGRAMMED_BASAL)) { if (podStateManager.activationProgress.isBefore(ActivationProgress.PROGRAMMED_BASAL)) {
observables.add( observables.add(
observeSendProgramBasalCommand(basalProgram) observeSendProgramBasalCommand(basalProgram, false)
.doOnComplete(ActivationProgressUpdater(ActivationProgress.PROGRAMMED_BASAL)) .doOnComplete(ActivationProgressUpdater(ActivationProgress.PROGRAMMED_BASAL))
) )
} }
@ -419,11 +419,11 @@ class OmnipodDashManagerImpl @Inject constructor(
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
} }
override fun setBasalProgram(basalProgram: BasalProgram): Observable<PodEvent> { override fun setBasalProgram(basalProgram: BasalProgram, hasBasalBeepEnabled: Boolean): Observable<PodEvent> {
return Observable.concat( return Observable.concat(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendProgramBasalCommand(basalProgram) observeSendProgramBasalCommand(basalProgram, hasBasalBeepEnabled)
) )
// TODO these would be common for any observable returned in a public function in this class // TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor()) .doOnNext(PodEventInterceptor())
@ -431,25 +431,41 @@ class OmnipodDashManagerImpl @Inject constructor(
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
} }
private fun observeSendStopDeliveryCommand(deliveryType: StopDeliveryCommand.DeliveryType): Observable<PodEvent> { private fun observeSendStopDeliveryCommand(
deliveryType: StopDeliveryCommand.DeliveryType,
beepEnabled: Boolean
): Observable<PodEvent> {
return Observable.defer { return Observable.defer {
val beepType = if (!beepEnabled) {
BeepType.SILENT
} else {
when (deliveryType) {
StopDeliveryCommand.DeliveryType.ALL, StopDeliveryCommand.DeliveryType.BASAL ->
BeepType.FOUR_TIMES_BIP_BEEP
StopDeliveryCommand.DeliveryType.TEMP_BASAL ->
BeepType.LONG_SINGLE_BEEP
StopDeliveryCommand.DeliveryType.BOLUS ->
BeepType.LONG_SINGLE_BEEP
}
}
bleManager.sendCommand( bleManager.sendCommand(
StopDeliveryCommand.Builder() StopDeliveryCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber) .setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(podStateManager.uniqueId!!.toInt()) .setUniqueId(podStateManager.uniqueId!!.toInt())
.setNonce(NONCE) .setNonce(NONCE)
.setDeliveryType(deliveryType) .setDeliveryType(deliveryType)
.setBeepType(beepType)
.build(), .build(),
DefaultStatusResponse::class DefaultStatusResponse::class
) )
} }
} }
override fun suspendDelivery(): Observable<PodEvent> { override fun suspendDelivery(hasBasalBeepEnabled: Boolean): Observable<PodEvent> {
return Observable.concat( return Observable.concat(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.ALL) observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.ALL, hasBasalBeepEnabled)
) )
// TODO these would be common for any observable returned in a public function in this class // TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor()) .doOnNext(PodEventInterceptor())
@ -491,11 +507,11 @@ class OmnipodDashManagerImpl @Inject constructor(
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
} }
override fun stopTempBasal(): Observable<PodEvent> { override fun stopTempBasal(hasTempBasalBeepEnabled: Boolean): Observable<PodEvent> {
return Observable.concat( return Observable.concat(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.TEMP_BASAL) observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.TEMP_BASAL, hasTempBasalBeepEnabled)
) )
// TODO these would be common for any observable returned in a public function in this class // TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor()) .doOnNext(PodEventInterceptor())
@ -520,11 +536,11 @@ class OmnipodDashManagerImpl @Inject constructor(
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
} }
override fun stopBolus(): Observable<PodEvent> { override fun stopBolus(beep: Boolean): Observable<PodEvent> {
return Observable.concat( return Observable.concat(
observePodRunning, observePodRunning,
observeConnectToPod, observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.BOLUS) observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.BOLUS, beep)
) )
// TODO these would be common for any observable returned in a public function in this class // TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor()) .doOnNext(PodEventInterceptor())

View file

@ -427,6 +427,11 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
podState.uniqueId = response.uniqueIdReceivedInCommand podState.uniqueId = response.uniqueIdReceivedInCommand
podState.lastUpdatedSystem = System.currentTimeMillis() podState.lastUpdatedSystem = System.currentTimeMillis()
// TODO: what is considered to be the pod activation time?
// LTK negotiation ?
// setUniqueId?
// compute it from the number of "minutesOnPod"?
podState.activationTime = System.currentTimeMillis()
store() store()
rxBus.send(EventOmnipodDashPumpValuesChanged()) rxBus.send(EventOmnipodDashPumpValuesChanged())

View file

@ -561,9 +561,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
private fun updateSuspendDeliveryButton() { private fun updateSuspendDeliveryButton() {
// If the Pod is currently suspended, we show the Resume delivery button instead. // If the Pod is currently suspended, we show the Resume delivery button instead.
// TODO: isSuspendDeliveryButtonEnabled doesn't work if (isSuspendDeliveryButtonEnabled() &&
val isSuspendDeliveryButtonEnabled = true
if (isSuspendDeliveryButtonEnabled &&
podStateManager.isPodRunning && podStateManager.isPodRunning &&
(!podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(CommandSuspendDelivery::class.java)) (!podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(CommandSuspendDelivery::class.java))
) { ) {
@ -592,7 +590,8 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
} }
private fun isSuspendDeliveryButtonEnabled(): Boolean { private fun isSuspendDeliveryButtonEnabled(): Boolean {
return sp.getBoolean(R.string.omnipod_common_preferences_suspend_delivery_button_enabled, false) R.string.key_omnipod_common_basal_beeps_enabled
return sp.getBoolean(R.string.key_omnipod_common_suspend_delivery_button_enabled, false)
} }
private fun displayErrorDialog(title: String, message: String, withSound: Boolean) { private fun displayErrorDialog(title: String, message: String, withSound: Boolean) {