From 6b6b4eb759f1712dbed45d1288570141dc76a6d1 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Tue, 25 Aug 2020 02:07:59 +0200 Subject: [PATCH] Restore command queue in Pod status, properly update it and disable buttons when queue is not empty --- .../pump/omnipod/OmnipodPumpPlugin.java | 22 ------------ .../driver/manager/OmnipodManager.java | 34 +++++++------------ ...entOmnipodPodStateActionsAllowedChanged.kt | 8 ----- .../pump/omnipod/ui/OmnipodFragment.kt | 28 +++++++++++---- .../src/main/res/layout/omnipod_fragment.xml | 7 ++++ 5 files changed, 42 insertions(+), 57 deletions(-) delete mode 100644 omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodPodStateActionsAllowedChanged.kt 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 43a3b3a5c9..73a3f81691 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 @@ -75,7 +75,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStorage import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager; -import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPodStateActionsAllowedChanged; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.RileyLinkOmnipodService; @@ -133,7 +132,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, private long nextPodCheck; private boolean sentIdToFirebase; private long lastConnectionTimeMillis; - private boolean podStateActionsAllowed = true; @Inject public OmnipodPumpPlugin( @@ -403,7 +401,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, if (firstRun) { initializeAfterRileyLinkConnection(); } else if (!omnipodStatusRequestList.isEmpty()) { - setAllowPodStateActions(false); Iterator iterator = omnipodStatusRequestList.iterator(); while (iterator.hasNext()) { @@ -439,10 +436,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name()); } iterator.remove(); - setAllowPodStateActions(true); } } else if (this.hasTimeDateOrTimeZoneChanged) { - setAllowPodStateActions(false); PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime); if (result.success) { @@ -463,7 +458,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, timeChangeRetries = 0; } } - setAllowPodStateActions(true); } } @@ -777,7 +771,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, } public void addPodStatusRequest(OmnipodStatusRequestType pumpStatusRequest) { - setAllowPodStateActions(false); omnipodStatusRequestList.add(pumpStatusRequest); } @@ -859,7 +852,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, @NonNull protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) { - setAllowPodStateActions(false); PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo)); if (result.success) { @@ -868,7 +860,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, result.carbsDelivered(detailedBolusInfo.carbs); } - setAllowPodStateActions(true); return result; } @@ -902,17 +893,4 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId)); } - private void setAllowPodStateActions(boolean allowed) { - if (podStateActionsAllowed != allowed) { - podStateActionsAllowed = allowed; - rxBus.send(new EventOmnipodPodStateActionsAllowedChanged()); - } - } - - // Allow usage of buttons in Omnipod tab that read or modify the Pod state: - // Refresh Status, Acknowledge Alerts and Get Pulse Log - public boolean isPodStateActionsAllowed() { - return podStateActionsAllowed; - } - } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java index 867f26235b..dc80e5ab0c 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/manager/OmnipodManager.java @@ -203,12 +203,7 @@ public class OmnipodManager { try { cancelDelivery(EnumSet.allOf(DeliveryType.class), acknowledgementBeep); - } catch (Exception ex) { - logCommandExecutionFinished("setBasalSchedule"); - throw ex; - } - try { try { return executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podStateManager, schedule, false, podStateManager.getScheduleOffset(), acknowledgementBeep))); @@ -231,21 +226,18 @@ public class OmnipodManager { try { cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep); - } catch (Exception ex) { - logCommandExecutionFinished("setTemporaryBasal"); - throw ex; - } - try { - StatusResponse statusResponse = executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction( - podStateManager, rate, duration, - acknowledgementBeep, completionBeep))); - return statusResponse; - } catch (OmnipodException ex) { - // Treat all exceptions as uncertain failures, because all delivery has been suspended here. - // Setting this to an uncertain failure will enable for the user to get an appropriate warning - ex.setCertainFailure(false); - throw ex; + try { + StatusResponse statusResponse = executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction( + podStateManager, rate, duration, + acknowledgementBeep, completionBeep))); + return statusResponse; + } catch (OmnipodException ex) { + // Treat all exceptions as uncertain failures, because all delivery has been suspended here. + // Setting this to an uncertain failure will enable for the user to get an appropriate warning + ex.setCertainFailure(false); + throw ex; + } } finally { logCommandExecutionFinished("setTemporaryBasal"); } @@ -295,8 +287,6 @@ public class OmnipodManager { // Catch uncertain exceptions as we still want to report bolus progress indication aapsLogger.error(LTag.PUMPBTCOMM, "Caught exception[certainFailure=false] in bolus", ex); commandDeliveryStatus = CommandDeliveryStatus.UNCERTAIN_FAILURE; - } finally { - logCommandExecutionFinished("bolus"); } DateTime startDate = DateTime.now().minus(OmnipodConstants.AVERAGE_BOLUS_COMMAND_COMMUNICATION_DURATION); @@ -365,6 +355,8 @@ public class OmnipodManager { }) .subscribe()); + logCommandExecutionFinished("bolus"); + return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject); } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodPodStateActionsAllowedChanged.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodPodStateActionsAllowedChanged.kt deleted file mode 100644 index 15f4a792f3..0000000000 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/event/EventOmnipodPodStateActionsAllowedChanged.kt +++ /dev/null @@ -1,8 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.event - -import info.nightscout.androidaps.events.Event - -/** - * Created by andy on 04.06.2018. - */ -class EventOmnipodPodStateActionsAllowedChanged : Event() \ No newline at end of file diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodFragment.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodFragment.kt index 27626ccd06..56b7dfe784 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodFragment.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodFragment.kt @@ -24,10 +24,10 @@ import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStatusR import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager -import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPodStateActionsAllowedChanged import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil +import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T @@ -129,7 +129,7 @@ class OmnipodFragment : DaggerFragment() { } else { disablePodActionButtons() omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodPulseLog); - commandQueue.readStatus("Clicked Refresh", null) + commandQueue.readStatus("Clicked Pulse Log", null) } } } @@ -152,9 +152,10 @@ class OmnipodFragment : DaggerFragment() { updatePodActionButtons() }, { fabricPrivacy.logException(it) }) disposables += rxBus - .toObservable(EventOmnipodPodStateActionsAllowedChanged::class.java) + .toObservable(EventQueueChanged::class.java) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ + updateQueueStatus() updatePodActionButtons() }, { fabricPrivacy.logException(it) }) disposables += rxBus @@ -176,6 +177,7 @@ class OmnipodFragment : DaggerFragment() { updateRileyLinkStatus() updateOmipodStatus() updatePodActionButtons() + updateQueueStatus() } @Synchronized @@ -339,6 +341,16 @@ class OmnipodFragment : DaggerFragment() { } } + private fun updateQueueStatus() { + val status = commandQueue.spannedStatus() + if (status.toString() == "") { + omnipod_queue.visibility = View.GONE + } else { + omnipod_queue.visibility = View.VISIBLE + omnipod_queue.text = status + } + } + private fun updatePodActionButtons() { updateRefreshStatusButton() updateAcknowledgeAlertsButton() @@ -353,12 +365,12 @@ class OmnipodFragment : DaggerFragment() { private fun updateRefreshStatusButton() { omnipod_refresh.isEnabled = podStateManager.isPodInitialized && podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED) - && rileyLinkServiceData.rileyLinkServiceState.isReady && omnipodPumpPlugin.isPodStateActionsAllowed + && rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty() } private fun updateAcknowledgeAlertsButton() { if (podStateManager.isPodInitialized && podStateManager.hasActiveAlerts() && !podStateManager.isPodDead) { - omnipod_pod_active_alerts_ack.isEnabled = omnipodPumpPlugin.isPodStateActionsAllowed && rileyLinkServiceData.rileyLinkServiceState.isReady + omnipod_pod_active_alerts_ack.isEnabled = rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty() } else { omnipod_pod_active_alerts_ack.isEnabled = false } @@ -367,7 +379,7 @@ class OmnipodFragment : DaggerFragment() { fun updatePulseLogButton() { if (aapsOmnipodManager.isPodDebuggingOptionsEnabled) { omnipod_pod_debug.visibility = View.VISIBLE - omnipod_pod_debug.isEnabled = podStateManager.isPodActivationCompleted && omnipodPumpPlugin.isPodStateActionsAllowed && rileyLinkServiceData.rileyLinkServiceState.isReady + omnipod_pod_debug.isEnabled = podStateManager.isPodActivationCompleted && rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty() } else { omnipod_pod_debug.visibility = View.GONE } @@ -412,4 +424,8 @@ class OmnipodFragment : DaggerFragment() { } } + private fun isQueueEmpty(): Boolean { + return commandQueue.size() == 0 && commandQueue.performing() == null + } + } diff --git a/omnipod/src/main/res/layout/omnipod_fragment.xml b/omnipod/src/main/res/layout/omnipod_fragment.xml index a6aa589167..e5fd330f49 100644 --- a/omnipod/src/main/res/layout/omnipod_fragment.xml +++ b/omnipod/src/main/res/layout/omnipod_fragment.xml @@ -320,6 +320,13 @@ + +