Fix formatting.
This commit is contained in:
parent
1b5b06d349
commit
b9f12aeddb
|
@ -96,7 +96,7 @@ Usage:
|
||||||
as a notification in AAPS. If they occur while no connection is open to the pump, going to the
|
as a notification in AAPS. If they occur while no connection is open to the pump, going to the
|
||||||
combo tab and hitting the Refresh button will take over those alerts by confirming them and
|
combo tab and hitting the Refresh button will take over those alerts by confirming them and
|
||||||
showing a notification in AAPS.
|
showing a notification in AAPS.
|
||||||
- When AAPS fails to confirm a TBR CANCELLED alert, or one is raised for different raising,
|
- When AAPS fails to confirm a TBR CANCELLED alert, or one is raised for a different reason,
|
||||||
hitting Refresh in the Combo tab establishes a connection, confirms the alert and shows
|
hitting Refresh in the Combo tab establishes a connection, confirms the alert and shows
|
||||||
a notification for it in AAPS. This can safely be done, since those alerts are benign - an
|
a notification for it in AAPS. This can safely be done, since those alerts are benign - an
|
||||||
appropriate TBR will be set again during the next loop iteration.
|
appropriate TBR will be set again during the next loop iteration.
|
||||||
|
|
|
@ -54,144 +54,144 @@ public class BolusCommand extends BaseCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
if (cancelRequested) {
|
if (cancelRequested) {
|
||||||
bolusProgressReporter.report(STOPPED, 0, 0);
|
bolusProgressReporter.report(STOPPED, 0, 0);
|
||||||
result.success = true;
|
|
||||||
log.debug("Stage 0: cancelled bolus before programming");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bolusProgressReporter.report(PROGRAMMING, 0, 0);
|
|
||||||
enterBolusMenu();
|
|
||||||
inputBolusAmount();
|
|
||||||
verifyDisplayedBolusAmount();
|
|
||||||
|
|
||||||
// last chance to abort before confirming the bolus
|
|
||||||
if (cancelRequested) {
|
|
||||||
bolusProgressReporter.report(STOPPING, 0, 0);
|
|
||||||
scripter.returnToRootMenu();
|
|
||||||
bolusProgressReporter.report(STOPPED, 0, 0);
|
|
||||||
result.success = true;
|
|
||||||
log.debug("Stage 1: cancelled bolus after programming");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// confirm bolus
|
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER);
|
|
||||||
scripter.pressCheckKey();
|
|
||||||
log.debug("Stage 2: bolus confirmed");
|
|
||||||
|
|
||||||
// the pump displays the entered bolus and waits a few seconds to let user check and cancel
|
|
||||||
while (scripter.getCurrentMenu().getType() == MenuType.BOLUS_ENTER) {
|
|
||||||
if (cancelRequested) {
|
|
||||||
log.debug("Stage 2: cancelling during confirmation wait");
|
|
||||||
bolusProgressReporter.report(STOPPING, 0, 0);
|
|
||||||
scripter.pressUpKey();
|
|
||||||
// wait up to 1s for a BOLUS_CANCELLED alert, if it doesn't happen we missed
|
|
||||||
// the window, simply continue and let the next cancel attempt try its luck
|
|
||||||
boolean alertWasCancelled = scripter.confirmAlert(PumpWarningCodes.BOLUS_CANCELLED, 1000);
|
|
||||||
if (alertWasCancelled) {
|
|
||||||
log.debug("Stage 2: successfully cancelled during confirmation wait");
|
|
||||||
bolusProgressReporter.report(STOPPED, 0, 0);
|
|
||||||
result.success = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SystemClock.sleep(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the bolus progress is displayed on the main menu
|
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU,
|
|
||||||
"Pump did not return to MAIN_MEU from BOLUS_ENTER to deliver bolus. "
|
|
||||||
+ "Check pump manually, the bolus might not have been delivered.");
|
|
||||||
bolusProgressReporter.report(DELIVERING, 0, 0);
|
|
||||||
|
|
||||||
// wait for bolus delivery to complete; the remaining units to deliver are counted down
|
|
||||||
boolean cancelInProgress = false;
|
|
||||||
Double lastBolusReported = 0d;
|
|
||||||
Double bolusRemaining = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_REMAINING);
|
|
||||||
Thread cancellationThread = null;
|
|
||||||
while (bolusRemaining != null || scripter.getCurrentMenu().getType() == MenuType.WARNING_OR_ERROR) {
|
|
||||||
if (cancelRequested && !cancelInProgress) {
|
|
||||||
log.debug("Stage 3: cancellation while delivering bolus");
|
|
||||||
bolusProgressReporter.report(STOPPING, 0, 0);
|
|
||||||
cancelInProgress = true;
|
|
||||||
cancellationThread = new Thread(() ->
|
|
||||||
scripter.pressKeyMs(RuffyScripter.Key.UP, 3000), "bolus-canceller");
|
|
||||||
cancellationThread.start();
|
|
||||||
}
|
|
||||||
if (scripter.getCurrentMenu().getType() == MenuType.WARNING_OR_ERROR) {
|
|
||||||
// confirm warning alert and update the result to indicate alerts occurred
|
|
||||||
WarningOrErrorCode warningOrErrorCode = scripter.readWarningOrErrorCode();
|
|
||||||
if (warningOrErrorCode.errorCode != null) {
|
|
||||||
throw new CommandException("Pump is in error state");
|
|
||||||
}
|
|
||||||
Integer warningCode = warningOrErrorCode.warningCode;
|
|
||||||
if (Objects.equals(warningCode, PumpWarningCodes.BOLUS_CANCELLED)) {
|
|
||||||
scripter.confirmAlert(PumpWarningCodes.BOLUS_CANCELLED, 2000);
|
|
||||||
bolusProgressReporter.report(STOPPED, 0, 0);
|
|
||||||
log.debug("Stage 3: confirmed BOLUS CANCELLED after cancelling bolus during delivery");
|
|
||||||
} else if (Objects.equals(warningCode, PumpWarningCodes.CARTRIDGE_LOW)) {
|
|
||||||
scripter.confirmAlert(PumpWarningCodes.CARTRIDGE_LOW, 2000);
|
|
||||||
result.forwardedWarnings.add(PumpWarningCodes.CARTRIDGE_LOW);
|
|
||||||
log.debug("Stage 3: confirmed low cartridge alert and forwarding to AAPS");
|
|
||||||
} else if (Objects.equals(warningCode, PumpWarningCodes.BATTERY_LOW)) {
|
|
||||||
scripter.confirmAlert(PumpWarningCodes.BATTERY_LOW, 2000);
|
|
||||||
result.forwardedWarnings.add(PumpWarningCodes.BATTERY_LOW);
|
|
||||||
log.debug("Stage 3: confirmed low battery alert and forwarding to AAPS");
|
|
||||||
} else {
|
|
||||||
// all other warnings or errors;
|
|
||||||
// An occlusion error can also occur during bolus. To read the partially delivered
|
|
||||||
// bolus, we'd have to first confirm the error. But an (occlusion) **error** shall not
|
|
||||||
// be confirmed and potentially be swallowed by a bug or shaky comms, so we let
|
|
||||||
// the pump be noisy (which the user will have to interact with anyway).
|
|
||||||
// Thus, this method will terminate with an exception and display an error message.
|
|
||||||
// Ideally, sometime after the user has dealt with the situation, the partially
|
|
||||||
// delivered bolus should be read. However, ready history is tricky at this point.
|
|
||||||
// Also: with an occlusion, the amount of insulin active is in question.
|
|
||||||
// It would be safer to assume the delivered bolus results in IOB, but there's
|
|
||||||
// only so much we can do at this point, so the user shall take over here and
|
|
||||||
// add a bolus record as and if needed.
|
|
||||||
throw new CommandException("Pump is showing exotic warning/error: " + warningOrErrorCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bolusRemaining != null && !Objects.equals(bolusRemaining, lastBolusReported)) {
|
|
||||||
log.debug("Delivering bolus, remaining: " + bolusRemaining);
|
|
||||||
int percentDelivered = (int) (100 - (bolusRemaining / bolus * 100));
|
|
||||||
bolusProgressReporter.report(DELIVERING, percentDelivered, bolus - bolusRemaining);
|
|
||||||
lastBolusReported = bolusRemaining;
|
|
||||||
}
|
|
||||||
SystemClock.sleep(50);
|
|
||||||
bolusRemaining = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_REMAINING);
|
|
||||||
}
|
|
||||||
// if a cancellation was started by pressing up for 3 seconds but the bolus has finished during those
|
|
||||||
// three seconds, must wait until the button is unpressed again so that follow up commands
|
|
||||||
// work properly.
|
|
||||||
if (cancellationThread != null) {
|
|
||||||
try {
|
|
||||||
cancellationThread.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cancelInProgress) {
|
|
||||||
log.debug("Stage 4: reading last bolus from pump history since a cancellation was requested during bolus delivery");
|
|
||||||
ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus();
|
|
||||||
readReservoirLevelAndLastBolus.setScripter(scripter);
|
|
||||||
readReservoirLevelAndLastBolus.execute();
|
|
||||||
Bolus lastBolus = readReservoirLevelAndLastBolus.result.lastBolus;
|
|
||||||
if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) {
|
|
||||||
throw new CommandException("Unable to determine last bolus");
|
|
||||||
}
|
|
||||||
log.debug("Stage 4:" + lastBolus.amount + " U delivered before cancellation according to history");
|
|
||||||
result.delivered = lastBolus.amount;
|
|
||||||
} else {
|
|
||||||
log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered");
|
|
||||||
result.delivered = bolus;
|
|
||||||
bolusProgressReporter.report(DELIVERED, 100, bolus);
|
|
||||||
}
|
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
log.debug("Stage 0: cancelled bolus before programming");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bolusProgressReporter.report(PROGRAMMING, 0, 0);
|
||||||
|
enterBolusMenu();
|
||||||
|
inputBolusAmount();
|
||||||
|
verifyDisplayedBolusAmount();
|
||||||
|
|
||||||
|
// last chance to abort before confirming the bolus
|
||||||
|
if (cancelRequested) {
|
||||||
|
bolusProgressReporter.report(STOPPING, 0, 0);
|
||||||
|
scripter.returnToRootMenu();
|
||||||
|
bolusProgressReporter.report(STOPPED, 0, 0);
|
||||||
|
result.success = true;
|
||||||
|
log.debug("Stage 1: cancelled bolus after programming");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// confirm bolus
|
||||||
|
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER);
|
||||||
|
scripter.pressCheckKey();
|
||||||
|
log.debug("Stage 2: bolus confirmed");
|
||||||
|
|
||||||
|
// the pump displays the entered bolus and waits a few seconds to let user check and cancel
|
||||||
|
while (scripter.getCurrentMenu().getType() == MenuType.BOLUS_ENTER) {
|
||||||
|
if (cancelRequested) {
|
||||||
|
log.debug("Stage 2: cancelling during confirmation wait");
|
||||||
|
bolusProgressReporter.report(STOPPING, 0, 0);
|
||||||
|
scripter.pressUpKey();
|
||||||
|
// wait up to 1s for a BOLUS_CANCELLED alert, if it doesn't happen we missed
|
||||||
|
// the window, simply continue and let the next cancel attempt try its luck
|
||||||
|
boolean alertWasCancelled = scripter.confirmAlert(PumpWarningCodes.BOLUS_CANCELLED, 1000);
|
||||||
|
if (alertWasCancelled) {
|
||||||
|
log.debug("Stage 2: successfully cancelled during confirmation wait");
|
||||||
|
bolusProgressReporter.report(STOPPED, 0, 0);
|
||||||
|
result.success = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SystemClock.sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the bolus progress is displayed on the main menu
|
||||||
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU,
|
||||||
|
"Pump did not return to MAIN_MEU from BOLUS_ENTER to deliver bolus. "
|
||||||
|
+ "Check pump manually, the bolus might not have been delivered.");
|
||||||
|
bolusProgressReporter.report(DELIVERING, 0, 0);
|
||||||
|
|
||||||
|
// wait for bolus delivery to complete; the remaining units to deliver are counted down
|
||||||
|
boolean cancelInProgress = false;
|
||||||
|
Double lastBolusReported = 0d;
|
||||||
|
Double bolusRemaining = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_REMAINING);
|
||||||
|
Thread cancellationThread = null;
|
||||||
|
while (bolusRemaining != null || scripter.getCurrentMenu().getType() == MenuType.WARNING_OR_ERROR) {
|
||||||
|
if (cancelRequested && !cancelInProgress) {
|
||||||
|
log.debug("Stage 3: cancellation while delivering bolus");
|
||||||
|
bolusProgressReporter.report(STOPPING, 0, 0);
|
||||||
|
cancelInProgress = true;
|
||||||
|
cancellationThread = new Thread(() ->
|
||||||
|
scripter.pressKeyMs(RuffyScripter.Key.UP, 3000), "bolus-canceller");
|
||||||
|
cancellationThread.start();
|
||||||
|
}
|
||||||
|
if (scripter.getCurrentMenu().getType() == MenuType.WARNING_OR_ERROR) {
|
||||||
|
// confirm warning alert and update the result to indicate alerts occurred
|
||||||
|
WarningOrErrorCode warningOrErrorCode = scripter.readWarningOrErrorCode();
|
||||||
|
if (warningOrErrorCode.errorCode != null) {
|
||||||
|
throw new CommandException("Pump is in error state");
|
||||||
|
}
|
||||||
|
Integer warningCode = warningOrErrorCode.warningCode;
|
||||||
|
if (Objects.equals(warningCode, PumpWarningCodes.BOLUS_CANCELLED)) {
|
||||||
|
scripter.confirmAlert(PumpWarningCodes.BOLUS_CANCELLED, 2000);
|
||||||
|
bolusProgressReporter.report(STOPPED, 0, 0);
|
||||||
|
log.debug("Stage 3: confirmed BOLUS CANCELLED after cancelling bolus during delivery");
|
||||||
|
} else if (Objects.equals(warningCode, PumpWarningCodes.CARTRIDGE_LOW)) {
|
||||||
|
scripter.confirmAlert(PumpWarningCodes.CARTRIDGE_LOW, 2000);
|
||||||
|
result.forwardedWarnings.add(PumpWarningCodes.CARTRIDGE_LOW);
|
||||||
|
log.debug("Stage 3: confirmed low cartridge alert and forwarding to AAPS");
|
||||||
|
} else if (Objects.equals(warningCode, PumpWarningCodes.BATTERY_LOW)) {
|
||||||
|
scripter.confirmAlert(PumpWarningCodes.BATTERY_LOW, 2000);
|
||||||
|
result.forwardedWarnings.add(PumpWarningCodes.BATTERY_LOW);
|
||||||
|
log.debug("Stage 3: confirmed low battery alert and forwarding to AAPS");
|
||||||
|
} else {
|
||||||
|
// all other warnings or errors;
|
||||||
|
// An occlusion error can also occur during bolus. To read the partially delivered
|
||||||
|
// bolus, we'd have to first confirm the error. But an (occlusion) **error** shall not
|
||||||
|
// be confirmed and potentially be swallowed by a bug or shaky comms, so we let
|
||||||
|
// the pump be noisy (which the user will have to interact with anyway).
|
||||||
|
// Thus, this method will terminate with an exception and display an error message.
|
||||||
|
// Ideally, sometime after the user has dealt with the situation, the partially
|
||||||
|
// delivered bolus should be read. However, ready history is tricky at this point.
|
||||||
|
// Also: with an occlusion, the amount of insulin active is in question.
|
||||||
|
// It would be safer to assume the delivered bolus results in IOB, but there's
|
||||||
|
// only so much we can do at this point, so the user shall take over here and
|
||||||
|
// add a bolus record as and if needed.
|
||||||
|
throw new CommandException("Pump is showing exotic warning/error: " + warningOrErrorCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bolusRemaining != null && !Objects.equals(bolusRemaining, lastBolusReported)) {
|
||||||
|
log.debug("Delivering bolus, remaining: " + bolusRemaining);
|
||||||
|
int percentDelivered = (int) (100 - (bolusRemaining / bolus * 100));
|
||||||
|
bolusProgressReporter.report(DELIVERING, percentDelivered, bolus - bolusRemaining);
|
||||||
|
lastBolusReported = bolusRemaining;
|
||||||
|
}
|
||||||
|
SystemClock.sleep(50);
|
||||||
|
bolusRemaining = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_REMAINING);
|
||||||
|
}
|
||||||
|
// if a cancellation was started by pressing up for 3 seconds but the bolus has finished during those
|
||||||
|
// three seconds, must wait until the button is unpressed again so that follow up commands
|
||||||
|
// work properly.
|
||||||
|
if (cancellationThread != null) {
|
||||||
|
try {
|
||||||
|
cancellationThread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancelInProgress) {
|
||||||
|
log.debug("Stage 4: reading last bolus from pump history since a cancellation was requested during bolus delivery");
|
||||||
|
ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus();
|
||||||
|
readReservoirLevelAndLastBolus.setScripter(scripter);
|
||||||
|
readReservoirLevelAndLastBolus.execute();
|
||||||
|
Bolus lastBolus = readReservoirLevelAndLastBolus.result.lastBolus;
|
||||||
|
if (lastBolus == null || Math.abs(System.currentTimeMillis() - lastBolus.timestamp) >= 10 * 60 * 1000) {
|
||||||
|
throw new CommandException("Unable to determine last bolus");
|
||||||
|
}
|
||||||
|
log.debug("Stage 4:" + lastBolus.amount + " U delivered before cancellation according to history");
|
||||||
|
result.delivered = lastBolus.amount;
|
||||||
|
} else {
|
||||||
|
log.debug("Stage 4: full bolus of " + bolus + " U was successfully delivered");
|
||||||
|
result.delivered = bolus;
|
||||||
|
bolusProgressReporter.report(DELIVERED, 100, bolus);
|
||||||
|
}
|
||||||
|
result.success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enterBolusMenu() {
|
private void enterBolusMenu() {
|
||||||
|
|
Loading…
Reference in a new issue