Restore command queue in Pod status, properly update it and disable buttons when queue is not empty
This commit is contained in:
parent
ae4b25af89
commit
6b6b4eb759
5 changed files with 42 additions and 57 deletions
|
@ -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.communication.message.response.podinfo.PodInfoRecentPulseLog;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
|
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.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.event.EventOmnipodPumpValuesChanged;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager;
|
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.RileyLinkOmnipodService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.RileyLinkOmnipodService;
|
||||||
|
@ -133,7 +132,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private long nextPodCheck;
|
private long nextPodCheck;
|
||||||
private boolean sentIdToFirebase;
|
private boolean sentIdToFirebase;
|
||||||
private long lastConnectionTimeMillis;
|
private long lastConnectionTimeMillis;
|
||||||
private boolean podStateActionsAllowed = true;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OmnipodPumpPlugin(
|
public OmnipodPumpPlugin(
|
||||||
|
@ -403,7 +401,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
initializeAfterRileyLinkConnection();
|
initializeAfterRileyLinkConnection();
|
||||||
} else if (!omnipodStatusRequestList.isEmpty()) {
|
} else if (!omnipodStatusRequestList.isEmpty()) {
|
||||||
setAllowPodStateActions(false);
|
|
||||||
Iterator<OmnipodStatusRequestType> iterator = omnipodStatusRequestList.iterator();
|
Iterator<OmnipodStatusRequestType> iterator = omnipodStatusRequestList.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
@ -439,10 +436,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name());
|
aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name());
|
||||||
}
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
setAllowPodStateActions(true);
|
|
||||||
}
|
}
|
||||||
} else if (this.hasTimeDateOrTimeZoneChanged) {
|
} else if (this.hasTimeDateOrTimeZoneChanged) {
|
||||||
setAllowPodStateActions(false);
|
|
||||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime);
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
@ -463,7 +458,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
timeChangeRetries = 0;
|
timeChangeRetries = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setAllowPodStateActions(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,7 +771,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPodStatusRequest(OmnipodStatusRequestType pumpStatusRequest) {
|
public void addPodStatusRequest(OmnipodStatusRequestType pumpStatusRequest) {
|
||||||
setAllowPodStateActions(false);
|
|
||||||
omnipodStatusRequestList.add(pumpStatusRequest);
|
omnipodStatusRequestList.add(pumpStatusRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,7 +852,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||||
setAllowPodStateActions(false);
|
|
||||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo));
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo));
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
@ -868,7 +860,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
result.carbsDelivered(detailedBolusInfo.carbs);
|
result.carbsDelivered(detailedBolusInfo.carbs);
|
||||||
}
|
}
|
||||||
setAllowPodStateActions(true);
|
|
||||||
|
|
||||||
return result;
|
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));
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,12 +203,7 @@ public class OmnipodManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cancelDelivery(EnumSet.allOf(DeliveryType.class), acknowledgementBeep);
|
cancelDelivery(EnumSet.allOf(DeliveryType.class), acknowledgementBeep);
|
||||||
} catch (Exception ex) {
|
|
||||||
logCommandExecutionFinished("setBasalSchedule");
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
try {
|
try {
|
||||||
return executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podStateManager, schedule,
|
return executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podStateManager, schedule,
|
||||||
false, podStateManager.getScheduleOffset(), acknowledgementBeep)));
|
false, podStateManager.getScheduleOffset(), acknowledgementBeep)));
|
||||||
|
@ -231,21 +226,18 @@ public class OmnipodManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep);
|
cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep);
|
||||||
} catch (Exception ex) {
|
|
||||||
logCommandExecutionFinished("setTemporaryBasal");
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
StatusResponse statusResponse = executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction(
|
StatusResponse statusResponse = executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction(
|
||||||
podStateManager, rate, duration,
|
podStateManager, rate, duration,
|
||||||
acknowledgementBeep, completionBeep)));
|
acknowledgementBeep, completionBeep)));
|
||||||
return statusResponse;
|
return statusResponse;
|
||||||
} catch (OmnipodException ex) {
|
} catch (OmnipodException ex) {
|
||||||
// Treat all exceptions as uncertain failures, because all delivery has been suspended here.
|
// 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
|
// Setting this to an uncertain failure will enable for the user to get an appropriate warning
|
||||||
ex.setCertainFailure(false);
|
ex.setCertainFailure(false);
|
||||||
throw ex;
|
throw ex;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
logCommandExecutionFinished("setTemporaryBasal");
|
logCommandExecutionFinished("setTemporaryBasal");
|
||||||
}
|
}
|
||||||
|
@ -295,8 +287,6 @@ public class OmnipodManager {
|
||||||
// Catch uncertain exceptions as we still want to report bolus progress indication
|
// Catch uncertain exceptions as we still want to report bolus progress indication
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "Caught exception[certainFailure=false] in bolus", ex);
|
aapsLogger.error(LTag.PUMPBTCOMM, "Caught exception[certainFailure=false] in bolus", ex);
|
||||||
commandDeliveryStatus = CommandDeliveryStatus.UNCERTAIN_FAILURE;
|
commandDeliveryStatus = CommandDeliveryStatus.UNCERTAIN_FAILURE;
|
||||||
} finally {
|
|
||||||
logCommandExecutionFinished("bolus");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime startDate = DateTime.now().minus(OmnipodConstants.AVERAGE_BOLUS_COMMAND_COMMUNICATION_DURATION);
|
DateTime startDate = DateTime.now().minus(OmnipodConstants.AVERAGE_BOLUS_COMMAND_COMMUNICATION_DURATION);
|
||||||
|
@ -365,6 +355,8 @@ public class OmnipodManager {
|
||||||
})
|
})
|
||||||
.subscribe());
|
.subscribe());
|
||||||
|
|
||||||
|
logCommandExecutionFinished("bolus");
|
||||||
|
|
||||||
return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject);
|
return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
|
|
@ -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.OmnipodConstants
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus
|
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.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.event.EventOmnipodPumpValuesChanged
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil
|
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.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
@ -129,7 +129,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
} else {
|
} else {
|
||||||
disablePodActionButtons()
|
disablePodActionButtons()
|
||||||
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodPulseLog);
|
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodPulseLog);
|
||||||
commandQueue.readStatus("Clicked Refresh", null)
|
commandQueue.readStatus("Clicked Pulse Log", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,9 +152,10 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
updatePodActionButtons()
|
updatePodActionButtons()
|
||||||
}, { fabricPrivacy.logException(it) })
|
}, { fabricPrivacy.logException(it) })
|
||||||
disposables += rxBus
|
disposables += rxBus
|
||||||
.toObservable(EventOmnipodPodStateActionsAllowedChanged::class.java)
|
.toObservable(EventQueueChanged::class.java)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({
|
.subscribe({
|
||||||
|
updateQueueStatus()
|
||||||
updatePodActionButtons()
|
updatePodActionButtons()
|
||||||
}, { fabricPrivacy.logException(it) })
|
}, { fabricPrivacy.logException(it) })
|
||||||
disposables += rxBus
|
disposables += rxBus
|
||||||
|
@ -176,6 +177,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
updateRileyLinkStatus()
|
updateRileyLinkStatus()
|
||||||
updateOmipodStatus()
|
updateOmipodStatus()
|
||||||
updatePodActionButtons()
|
updatePodActionButtons()
|
||||||
|
updateQueueStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@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() {
|
private fun updatePodActionButtons() {
|
||||||
updateRefreshStatusButton()
|
updateRefreshStatusButton()
|
||||||
updateAcknowledgeAlertsButton()
|
updateAcknowledgeAlertsButton()
|
||||||
|
@ -353,12 +365,12 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
|
|
||||||
private fun updateRefreshStatusButton() {
|
private fun updateRefreshStatusButton() {
|
||||||
omnipod_refresh.isEnabled = podStateManager.isPodInitialized && podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED)
|
omnipod_refresh.isEnabled = podStateManager.isPodInitialized && podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED)
|
||||||
&& rileyLinkServiceData.rileyLinkServiceState.isReady && omnipodPumpPlugin.isPodStateActionsAllowed
|
&& rileyLinkServiceData.rileyLinkServiceState.isReady && isQueueEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateAcknowledgeAlertsButton() {
|
private fun updateAcknowledgeAlertsButton() {
|
||||||
if (podStateManager.isPodInitialized && podStateManager.hasActiveAlerts() && !podStateManager.isPodDead) {
|
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 {
|
} else {
|
||||||
omnipod_pod_active_alerts_ack.isEnabled = false
|
omnipod_pod_active_alerts_ack.isEnabled = false
|
||||||
}
|
}
|
||||||
|
@ -367,7 +379,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
fun updatePulseLogButton() {
|
fun updatePulseLogButton() {
|
||||||
if (aapsOmnipodManager.isPodDebuggingOptionsEnabled) {
|
if (aapsOmnipodManager.isPodDebuggingOptionsEnabled) {
|
||||||
omnipod_pod_debug.visibility = View.VISIBLE
|
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 {
|
} else {
|
||||||
omnipod_pod_debug.visibility = View.GONE
|
omnipod_pod_debug.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
@ -412,4 +424,8 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isQueueEmpty(): Boolean {
|
||||||
|
return commandQueue.size() == 0 && commandQueue.performing() == null
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,6 +320,13 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/omnipod_queue"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text=""
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="2dip"
|
android:layout_height="2dip"
|
||||||
|
|
Loading…
Reference in a new issue