wip cancelling
This commit is contained in:
parent
a664bdeaaa
commit
22e3517cd6
|
@ -356,6 +356,7 @@ public class RuffyScripter {
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
return e.toCommandResult();
|
return e.toCommandResult();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// TODO detect and report pump warnings/errors differently?
|
||||||
log.error("Error in ruffyscripter/ruffy", e);
|
log.error("Error in ruffyscripter/ruffy", e);
|
||||||
return new CommandResult().exception(e).message("Unexpected exception communication with ruffy: " + e.getMessage());
|
return new CommandResult().exception(e).message("Unexpected exception communication with ruffy: " + e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -14,10 +14,10 @@ import java.util.Locale;
|
||||||
import de.jotomo.ruffyscripter.PumpState;
|
import de.jotomo.ruffyscripter.PumpState;
|
||||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
|
|
||||||
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.BOLUSING;
|
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.DELIVERING;
|
||||||
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.CANCELLED;
|
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.STOPPED;
|
||||||
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.CANCELLING;
|
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.STOPPING;
|
||||||
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.FINISHED;
|
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.DELIVERED;
|
||||||
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.PREPARING;
|
import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.PREPARING;
|
||||||
|
|
||||||
public class BolusCommand implements Command {
|
public class BolusCommand implements Command {
|
||||||
|
@ -45,55 +45,75 @@ public class BolusCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) {
|
public CommandResult execute(RuffyScripter scripter, PumpState initialPumpState) {
|
||||||
progressReportCallback.progress(PREPARING, 0, 0);
|
|
||||||
try {
|
try {
|
||||||
enterBolusMenu(scripter);
|
enterBolusMenu(scripter);
|
||||||
|
|
||||||
inputBolusAmount(scripter);
|
inputBolusAmount(scripter);
|
||||||
verifyDisplayedBolusAmount(scripter);
|
verifyDisplayedBolusAmount(scripter);
|
||||||
|
|
||||||
|
if (cancelRequested) {
|
||||||
|
progressReportCallback.report(STOPPING, 0, 0);
|
||||||
|
scripter.goToMainTypeScreen(MenuType.MAIN_MENU, 30 * 1000);
|
||||||
|
progressReportCallback.report(STOPPED, 0, 0);
|
||||||
|
return new CommandResult().success(true).enacted(false)
|
||||||
|
.message("Bolus cancelled as per user request with no insulin delivered");
|
||||||
|
}
|
||||||
|
|
||||||
// confirm bolus
|
// confirm bolus
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER);
|
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER);
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
if (cancelRequested) {
|
|
||||||
scripter.goToMainTypeScreen(MenuType.MAIN_MENU, 30_000);
|
|
||||||
progressReportCallback.progress(CANCELLED, 0, 0);
|
|
||||||
return new CommandResult().success(true).enacted(false).message("Bolus cancelled as per user request with no insulin delivered");
|
|
||||||
}
|
|
||||||
progressReportCallback.progress(BOLUSING, 0, 0);
|
|
||||||
|
|
||||||
// the pump displays the entered bolus and waits a bit to let user check and cancel
|
// the pump displays the entered bolus and waits a few seconds to let user check and cancel
|
||||||
// TODO pressing up (and possible other keys) cancels the bolus
|
|
||||||
scripter.waitForMenuToBeLeft(MenuType.BOLUS_ENTER);
|
|
||||||
while (scripter.currentMenu.getType() == MenuType.BOLUS_ENTER) {
|
while (scripter.currentMenu.getType() == MenuType.BOLUS_ENTER) {
|
||||||
if (cancelRequested) {
|
if (cancelRequested) {
|
||||||
|
progressReportCallback.report(STOPPING, 0, 0);
|
||||||
scripter.pressUpKey();
|
scripter.pressUpKey();
|
||||||
// TODO deal with error; write a method to wait for and cancel a specific alarm
|
// wait up to 1s for a BOLUS_CANCELLED alert, if it doesn't happen we missed
|
||||||
// wait happens if the keypress comes too late? just try agoin below?
|
// the window, simply continue and let the next cancel attempt try its luck
|
||||||
|
boolean alertWasCancelled = confirmAlert("BOLUS CANCELLED", 1000);
|
||||||
|
if (alertWasCancelled) {
|
||||||
|
progressReportCallback.report(STOPPED, 0, 0);
|
||||||
|
return new CommandResult().success(true).enacted(false)
|
||||||
|
.message("Bolus cancelled as per user request with no insulin delivered");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SystemClock.sleep(50);
|
SystemClock.sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU,
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU,
|
||||||
"Pump did not return to MAIN_MEU from BOLUS_ENTER to deliver bolus. "
|
"Pump did not return to MAIN_MEU from BOLUS_ENTER to deliver bolus. "
|
||||||
+ "Check pump manually, the bolus might not have been delivered.");
|
+ "Check pump manually, the bolus might not have been delivered.");
|
||||||
|
|
||||||
// wait for bolus delivery to complete; the remaining units to deliver are counted
|
progressReportCallback.report(DELIVERING, 0, 0);
|
||||||
// down and are displayed on the main menu.
|
|
||||||
Double bolusRemaining = (Double) scripter.currentMenu.getAttribute(MenuAttribute.BOLUS_REMAINING);
|
Double bolusRemaining = (Double) scripter.currentMenu.getAttribute(MenuAttribute.BOLUS_REMAINING);
|
||||||
double lastBolusReported = 0;
|
double lastBolusReported = 0;
|
||||||
|
// wait for bolus delivery to complete; the remaining units to deliver are counted
|
||||||
|
// down and are displayed on the main menu.
|
||||||
while (bolusRemaining != null) {
|
while (bolusRemaining != null) {
|
||||||
if (cancelRequested) {
|
if (cancelRequested) {
|
||||||
|
progressReportCallback.report(STOPPING, 0, 0);
|
||||||
// TODO press up 3s, deal with bolus cancelled error, retrieved amount actually delivered from history and return it
|
// TODO press up 3s, deal with bolus cancelled error, retrieved amount actually delivered from history and return it
|
||||||
// since the cancellation takes three seconds some insulin will have definately been delivered (delivery speed is roughly 0.1U/s)
|
// since the cancellation takes three seconds some insulin will have definately been delivered (delivery speed is roughly 0.1U/s)
|
||||||
|
progressReportCallback.report(STOPPED, 0, 0);
|
||||||
}
|
}
|
||||||
if (lastBolusReported != bolusRemaining) {
|
if (lastBolusReported != bolusRemaining) {
|
||||||
log.debug("Delivering bolus, remaining: " + bolusRemaining);
|
log.debug("Delivering bolus, remaining: " + bolusRemaining);
|
||||||
int percentDelivered = (int) (100 - (bolusRemaining / bolus * 100));
|
int percentDelivered = (int) (100 - (bolusRemaining / bolus * 100));
|
||||||
progressReportCallback.progress(BOLUSING, percentDelivered, bolus - bolusRemaining);
|
progressReportCallback.report(DELIVERING, percentDelivered, bolus - bolusRemaining);
|
||||||
lastBolusReported = bolusRemaining;
|
lastBolusReported = bolusRemaining;
|
||||||
}
|
}
|
||||||
// TODO deal with alarms that can arise; an oclussion with raise an oclussion alert as well as a bolus cancelled alert
|
// TODO deal with alarms that can arise; an oclussion with raise an oclussion alert as well as a bolus cancelled alert
|
||||||
|
// occlusion cancels the bolus -> abort routine to report back delivered bolus;
|
||||||
|
// low cartridge alert lets bolus run out
|
||||||
|
// also, any other error or warning can occur and we should return in a controlled fashion -
|
||||||
|
// communicating back what was actually delivered.
|
||||||
|
// generally: cancel an alert on the pump and raise the error in AAPS?
|
||||||
|
// letting the alert go off disrupts comms if the user interacts with the pump,
|
||||||
|
// then we need to schedule a history read in the near future, let thee user know
|
||||||
|
// the data will be out of sync for a bit.
|
||||||
|
// how does the dana handle pump errors? has no vibration, but sound i guess
|
||||||
|
// should this be configurabe? initially?
|
||||||
|
if (scripter.currentMenu.getType() == MenuType.WARNING_OR_ERROR) {
|
||||||
|
|
||||||
|
}
|
||||||
SystemClock.sleep(50);
|
SystemClock.sleep(50);
|
||||||
bolusRemaining = (Double) scripter.currentMenu.getAttribute(MenuAttribute.BOLUS_REMAINING);
|
bolusRemaining = (Double) scripter.currentMenu.getAttribute(MenuAttribute.BOLUS_REMAINING);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +126,7 @@ public class BolusCommand implements Command {
|
||||||
"Bolus delivery did not complete as expected. "
|
"Bolus delivery did not complete as expected. "
|
||||||
+ "Check pump manually, the bolus might not have been delivered.");
|
+ "Check pump manually, the bolus might not have been delivered.");
|
||||||
|
|
||||||
progressReportCallback.progress(FINISHED, 100, bolus);
|
progressReportCallback.report(DELIVERED, 100, bolus);
|
||||||
|
|
||||||
// read last bolus record; those menus display static data and therefore
|
// read last bolus record; those menus display static data and therefore
|
||||||
// only a single menu update is sent
|
// only a single menu update is sent
|
||||||
|
@ -130,12 +150,11 @@ public class BolusCommand implements Command {
|
||||||
}
|
}
|
||||||
log.debug("Bolus record in history confirms delivered bolus");
|
log.debug("Bolus record in history confirms delivered bolus");
|
||||||
|
|
||||||
// leave menu to go back to main menu
|
if (!scripter.goToMainTypeScreen(MenuType.MAIN_MENU, 15 * 1000)) {
|
||||||
scripter.pressCheckKey();
|
throw new CommandException().success(false).enacted(true)
|
||||||
scripter.waitForMenuToBeLeft(MenuType.BOLUS_DATA);
|
.message("Bolus was correctly delivered and checked against history, but we "
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU,
|
+ "did not return the main menu successfully.");
|
||||||
"Bolus was correctly delivered and checked against history, but we "
|
}
|
||||||
+ "did not return the main menu successfully.");
|
|
||||||
|
|
||||||
return new CommandResult().success(true).enacted(true)
|
return new CommandResult().success(true).enacted(true)
|
||||||
.message(String.format(Locale.US, "Delivered %02.1f U", bolus));
|
.message(String.format(Locale.US, "Delivered %02.1f U", bolus));
|
||||||
|
@ -144,6 +163,10 @@ public class BolusCommand implements Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean confirmAlert(String alertText, int maxWaitTillExpectedAlert) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void enterBolusMenu(RuffyScripter scripter) {
|
private void enterBolusMenu(RuffyScripter scripter) {
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
||||||
scripter.navigateToMenu(MenuType.BOLUS_MENU);
|
scripter.navigateToMenu(MenuType.BOLUS_MENU);
|
||||||
|
@ -198,7 +221,7 @@ public class BolusCommand implements Command {
|
||||||
|
|
||||||
public void requestCancellation() {
|
public void requestCancellation() {
|
||||||
cancelRequested = true;
|
cancelRequested = true;
|
||||||
progressReportCallback.progress(CANCELLING, 0, 0);
|
progressReportCallback.report(STOPPING, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,12 +2,11 @@ package de.jotomo.ruffyscripter.commands;
|
||||||
|
|
||||||
public interface ProgressReportCallback {
|
public interface ProgressReportCallback {
|
||||||
enum State {
|
enum State {
|
||||||
PREPARING,
|
DELIVERING,
|
||||||
BOLUSING,
|
DELIVERED,
|
||||||
CANCELLING,
|
STOPPING,
|
||||||
FINISHED,
|
STOPPED
|
||||||
CANCELLED
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void progress(State state, int percent, double delivered);
|
void report(State state, int percent, double delivered);
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,23 +368,20 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
private static ProgressReportCallback bolusProgressReportCallback = new ProgressReportCallback() {
|
private static ProgressReportCallback bolusProgressReportCallback = new ProgressReportCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void progress(ProgressReportCallback.State state, int percent, double delivered) {
|
public void report(ProgressReportCallback.State state, int percent, double delivered) {
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
switch (state) {
|
switch (state) {
|
||||||
// TODO move into enum as toString or so and make it translateb
|
// TODO move into enum as toString or so and make it translateb
|
||||||
case BOLUSING:
|
case DELIVERING:
|
||||||
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivered);
|
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivered);
|
||||||
break;
|
break;
|
||||||
case PREPARING:
|
case DELIVERED:
|
||||||
bolusingEvent.status = "Preparing pump for bolus";
|
|
||||||
break;
|
|
||||||
case FINISHED:
|
|
||||||
bolusingEvent.status = "Bolus delivery finished successfully";
|
bolusingEvent.status = "Bolus delivery finished successfully";
|
||||||
break;
|
break;
|
||||||
case CANCELLED:
|
case STOPPED:
|
||||||
bolusingEvent.status = "Bolus delivery was cancelled";
|
bolusingEvent.status = "Bolus delivery was cancelled";
|
||||||
break;
|
break;
|
||||||
case CANCELLING:
|
case STOPPING:
|
||||||
bolusingEvent.status = "Cancelling bolus delivery";
|
bolusingEvent.status = "Cancelling bolus delivery";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -402,7 +399,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
// bolus needed, ask pump to deliver it
|
// bolus needed, ask pump to deliver it
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
// TODO move into enum as toString or so and make it translateb
|
|
||||||
runningBolusCommand = new BolusCommand(detailedBolusInfo.insulin, bolusProgressReportCallback);
|
runningBolusCommand = new BolusCommand(detailedBolusInfo.insulin, bolusProgressReportCallback);
|
||||||
CommandResult bolusCmdResult = runCommand(runningBolusCommand);
|
CommandResult bolusCmdResult = runCommand(runningBolusCommand);
|
||||||
runningBolusCommand = null;
|
runningBolusCommand = null;
|
||||||
|
@ -433,6 +429,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
// TODO the ui freezes when the calculator issues a carb-only treatment
|
// TODO the ui freezes when the calculator issues a carb-only treatment
|
||||||
// so just wait, yeah, this is dumb. for now; proper fix via GL#10
|
// so just wait, yeah, this is dumb. for now; proper fix via GL#10
|
||||||
// info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog.scheduleDismiss()
|
// info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog.scheduleDismiss()
|
||||||
|
// send event to indicate popup can be dismissed?
|
||||||
SystemClock.sleep(6000);
|
SystemClock.sleep(6000);
|
||||||
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||||
pumpEnactResult.success = true;
|
pumpEnactResult.success = true;
|
||||||
|
|
Loading…
Reference in a new issue