diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 6e56ecda13..d1c4fda2e7 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -151,7 +151,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, private final Handler loopHandler = new Handler(Looper.getMainLooper()); private final Runnable statusChecker; - private boolean isSetTempBasalRunning; private boolean isCancelTempBasalRunning; @Inject @@ -303,23 +302,23 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, .toObservable(EventPreferenceChange.class) .observeOn(Schedulers.io()) .subscribe(event -> { - if (event.isChanged(getResourceHelper(), R.string.key_omnipod_basal_beeps_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_bolus_beeps_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_tbr_beeps_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_smb_beeps_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_suspend_delivery_button_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_pulse_log_button_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_rileylink_stats_button_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_time_change_event_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_tbr_sound_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_smb_sound_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_notification_uncertain_bolus_sound_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_automatically_acknowledge_alerts_enabled)) { + if (event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.BASAL_BEEPS_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.BOLUS_BEEPS_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.TBR_BEEPS_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.SMB_BEEPS_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.SUSPEND_DELIVERY_BUTTON_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.PULSE_LOG_BUTTON_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.RILEYLINK_STATS_BUTTON_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.TIME_CHANGE_EVENT_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_TBR_SOUND_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_SMB_SOUND_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_BOLUS_SOUND_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.AUTOMATICALLY_ACKNOWLEDGE_ALERTS_ENABLED)) { aapsOmnipodManager.reloadSettings(); - } else if (event.isChanged(getResourceHelper(), R.string.key_omnipod_expiration_reminder_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_expiration_reminder_hours_before_shutdown) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_low_reservoir_alert_enabled) || - event.isChanged(getResourceHelper(), R.string.key_omnipod_low_reservoir_alert_units)) { + } else if (event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.EXPIRATION_REMINDER_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.EXPIRATION_REMINDER_HOURS_BEFORE_SHUTDOWN) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.LOW_RESERVOIR_ALERT_ENABLED) || + event.isChanged(getResourceHelper(), OmnipodStorageKeys.Preferences.LOW_RESERVOIR_ALERT_UNITS)) { if (!verifyPodAlertConfiguration()) { getCommandQueue().customCommand(new CommandUpdateAlertConfiguration(), null); } @@ -364,11 +363,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, } private void handleUncertainTbrRecovery() { - // Ignore changes in certainty during tbr commands; these are normal - if (isSetTempBasalRunning || isCancelTempBasalRunning) { - return; - } - TemporaryBasal tempBasal = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis()); if (podStateManager.isTempBasalRunning() && tempBasal == null) { @@ -661,13 +655,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, } } - isSetTempBasalRunning = true; - PumpEnactResult result; - try { - result = executeCommand(OmnipodCommandType.SET_TEMPORARY_BASAL, () -> aapsOmnipodManager.setTemporaryBasal(new TempBasalPair(absoluteRate, false, durationInMinutes))); - } finally { - isSetTempBasalRunning = false; - } + PumpEnactResult result = executeCommand(OmnipodCommandType.SET_TEMPORARY_BASAL, () -> aapsOmnipodManager.setTemporaryBasal(new TempBasalPair(absoluteRate, false, durationInMinutes))); aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - setTBR. Response: " + result.success); diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/OmnipodMessage.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/OmnipodMessage.java index 7531631b12..e0c7bf9848 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/OmnipodMessage.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/OmnipodMessage.java @@ -6,7 +6,9 @@ import java.util.List; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.CancelDeliveryCommand; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.command.GetStatusCommand; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.DeliveryType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.MessageBlockType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodCrc; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PacketType; @@ -145,6 +147,14 @@ public class OmnipodMessage { return false; } + public boolean isSetTempBasalMessage() { + return messageBlocks.size() >= 2 && messageBlocks.get(0).getType() == MessageBlockType.SET_INSULIN_SCHEDULE && messageBlocks.get(1).getType() == MessageBlockType.TEMP_BASAL_EXTRA; + } + + public boolean isCancelTempBasalMessage() { + return messageBlocks.size() >= 1 && messageBlocks.get(0).getType() == MessageBlockType.CANCEL_DELIVERY && ((CancelDeliveryCommand) messageBlocks.get(0)).getDeliveryTypes().contains(DeliveryType.TEMP_BASAL); + } + @Override public String toString() { return "OmnipodMessage{" + diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/CancelDeliveryCommand.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/CancelDeliveryCommand.java index 71eb4084d4..be8f09230f 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/CancelDeliveryCommand.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/communication/message/command/CancelDeliveryCommand.java @@ -60,6 +60,10 @@ public class CancelDeliveryCommand extends NonceResyncableMessageBlock { encode(); } + public EnumSet getDeliveryTypes() { + return deliveryTypes.clone(); + } + @Override public String toString() { return "CancelDeliveryCommand{" + diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java index 2af4d0734f..570289a198 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/PodStateManager.java @@ -21,6 +21,7 @@ import java.util.function.Supplier; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.OmnipodMessage; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.StatusUpdatableResponse; import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoDetailedStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.ActivationProgress; @@ -550,7 +551,7 @@ public abstract class PodStateManager { /** * Does not automatically store pod state in order to decrease I/O load */ - public final void updateFromResponse(StatusUpdatableResponse status) { + public final void updateFromResponse(StatusUpdatableResponse status, OmnipodMessage requestMessage) { setSafe(() -> { if (podState.getActivatedAt() == null) { DateTime activatedAtCalculated = DateTime.now().withZone(podState.getTimeZone()).minus(status.getTimeActive()); @@ -581,7 +582,10 @@ public abstract class PodStateManager { } if (!isTempBasalCertain) { podState.setTempBasalCertain(true); - onUncertainTbrRecovered(); + if (!requestMessage.isSetTempBasalMessage() // We always set TBR to uncertain before sending the set temp basal command, so this is not an actual recovery + && !requestMessage.isCancelTempBasalMessage()) { // Delivery status changed, so we can't recover here + onUncertainTbrRecovered(); + } } if (!isBasalCertain) { podState.setBasalCertain(true); diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java index b6cb382a0d..9d9e4a0433 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/manager/AapsOmnipodManager.java @@ -167,7 +167,7 @@ public class AapsOmnipodManager { pulseLogButtonEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.PULSE_LOG_BUTTON_ENABLED, false); rileylinkStatsButtonEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.RILEYLINK_STATS_BUTTON_ENABLED, false); timeChangeEventEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.TIME_CHANGE_EVENT_ENABLED, true); - notificationUncertainTbrSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_TBR_SOUND_ENABLED, true); + notificationUncertainTbrSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_TBR_SOUND_ENABLED, false); notificationUncertainSmbSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_SMB_SOUND_ENABLED, true); notificationUncertainBolusSoundEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.NOTIFICATION_UNCERTAIN_BOLUS_SOUND_ENABLED, true); automaticallyAcknowledgeAlertsEnabled = sp.getBoolean(OmnipodStorageKeys.Preferences.AUTOMATICALLY_ACKNOWLEDGE_ALERTS_ENABLED, false); diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java index 822228d949..44f2069c59 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/manager/OmnipodRileyLinkCommunicationManager.java @@ -129,11 +129,11 @@ public class OmnipodRileyLinkCommunicationManager extends RileyLinkCommunication aapsLogger.debug(LTag.PUMPBTCOMM, "Received response from the Pod [responseMessageBlock={}]", responseMessageBlock); if (responseMessageBlock instanceof StatusUpdatableResponse) { - podStateManager.updateFromResponse((StatusUpdatableResponse) responseMessageBlock); + podStateManager.updateFromResponse((StatusUpdatableResponse) responseMessageBlock, message); } else if (responseMessageBlock instanceof PodInfoResponse) { PodInfo podInfo = ((PodInfoResponse) responseMessageBlock).getPodInfo(); if (podInfo instanceof StatusUpdatableResponse) { - podStateManager.updateFromResponse((StatusUpdatableResponse) podInfo); + podStateManager.updateFromResponse((StatusUpdatableResponse) podInfo, message); } } diff --git a/omnipod/src/main/res/xml/pref_omnipod.xml b/omnipod/src/main/res/xml/pref_omnipod.xml index 8b59e41416..d0135d82a1 100644 --- a/omnipod/src/main/res/xml/pref_omnipod.xml +++ b/omnipod/src/main/res/xml/pref_omnipod.xml @@ -82,7 +82,7 @@