From d851637d4f88e066791869f3b3b8397d3cdf9360 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 18 Aug 2017 11:54:57 +0200 Subject: [PATCH] more --- .../ruffyscripter/commands/BolusCommand.java | 37 ++++++++++++++++--- .../commands/ProgressReportCallback.java | 12 ------ .../plugins/PumpCombo/ComboPlugin.java | 7 ++-- 3 files changed, 34 insertions(+), 22 deletions(-) delete mode 100644 app/src/main/java/de/jotomo/ruffyscripter/commands/ProgressReportCallback.java diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java index b9f54205d2..cc03ab0f86 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java @@ -14,10 +14,10 @@ import java.util.Locale; import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.RuffyScripter; -import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.DELIVERING; -import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.STOPPED; -import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.STOPPING; -import static de.jotomo.ruffyscripter.commands.ProgressReportCallback.State.DELIVERED; +import static de.jotomo.ruffyscripter.commands.BolusCommand.ProgressReportCallback.State.DELIVERING; +import static de.jotomo.ruffyscripter.commands.BolusCommand.ProgressReportCallback.State.STOPPED; +import static de.jotomo.ruffyscripter.commands.BolusCommand.ProgressReportCallback.State.STOPPING; +import static de.jotomo.ruffyscripter.commands.BolusCommand.ProgressReportCallback.State.DELIVERED; public class BolusCommand implements Command { private static final Logger log = LoggerFactory.getLogger(BolusCommand.class); @@ -86,11 +86,23 @@ public class BolusCommand implements Command { double lastBolusReported = 0; // wait for bolus delivery to complete; the remaining units to deliver are counted // down and are displayed on the main menu. + // TODO extract into method while (bolusRemaining != null) { if (cancelRequested) { progressReportCallback.report(STOPPING, 0, 0); + // TODO just press up 3s in a separated thread and let this loop run + // and at the end handle the outcome and returned raise alarms, whether cancel was reuqested etc + // 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 definitely been delivered (delivery speed is roughly 0.1U/s), + // but the pump may also finish delivering the bolus while we try to cancel it + // so, press a button, keep it press and deal with three outcomes: + // * delivery finished (no more remaining bolus displayed) + // * bolus was cancelled (warning raised) + // * any other error (low cartridge, occlusion, both will also trigger 'bolus cancelled' errors) + // cancelBolusInDelivery() + // TODO new thread to press button and then deal with outcomes below, since all errors can occur at all time, pressing + // abort just forces an error (if keyrpess is in time) progressReportCallback.report(STOPPED, 0, 0); } if (lastBolusReported != bolusRemaining) { @@ -111,7 +123,7 @@ public class BolusCommand implements Command { // 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) { - + // see errors being dealt with trying to cancel } SystemClock.sleep(50); bolusRemaining = (Double) scripter.currentMenu.getAttribute(MenuAttribute.BOLUS_REMAINING); @@ -162,6 +174,8 @@ public class BolusCommand implements Command { } } + // TODO confirmAlarms? and report back which were cancelled? + private boolean confirmAlert(String alertText, int maxWaitTillExpectedAlert) { // TODO return false; @@ -230,4 +244,15 @@ public class BolusCommand implements Command { "bolus=" + bolus + '}'; } + + public interface ProgressReportCallback { + enum State { + DELIVERING, + DELIVERED, + STOPPING, + STOPPED + } + + void report(State state, int percent, double delivered); + } } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ProgressReportCallback.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ProgressReportCallback.java deleted file mode 100644 index 4491da501d..0000000000 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/ProgressReportCallback.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.jotomo.ruffyscripter.commands; - -public interface ProgressReportCallback { - enum State { - DELIVERING, - DELIVERED, - STOPPING, - STOPPED - } - - void report(State state, int percent, double delivered); -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index c2c7076e6c..8d9344d98c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -31,7 +31,6 @@ import de.jotomo.ruffyscripter.commands.BolusCommand; import de.jotomo.ruffyscripter.commands.CancelTbrCommand; import de.jotomo.ruffyscripter.commands.Command; import de.jotomo.ruffyscripter.commands.CommandResult; -import de.jotomo.ruffyscripter.commands.ProgressReportCallback; import de.jotomo.ruffyscripter.commands.DetermineCapabilitiesCommand; import de.jotomo.ruffyscripter.commands.ReadPumpStateCommand; import de.jotomo.ruffyscripter.commands.SetTbrCommand; @@ -366,9 +365,9 @@ public class ComboPlugin implements PluginBase, PumpInterface { return basal; } - private static ProgressReportCallback bolusProgressReportCallback = new ProgressReportCallback() { + private static BolusCommand.ProgressReportCallback bolusProgressReportCallback = new BolusCommand.ProgressReportCallback() { @Override - public void report(ProgressReportCallback.State state, int percent, double delivered) { + public void report(BolusCommand.ProgressReportCallback.State state, int percent, double delivered) { EventOverviewBolusProgress enent = EventOverviewBolusProgress.getInstance(); switch (state) { case DELIVERING: @@ -399,7 +398,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { // TODO read history to ensure there are no boluses delivered on the pump we aren't // aware of and haven't included in the bolus calulation - // Note that the BolusCommand send progress updates to the bolusProgressReporterCallback, + // Note that the BolusCommand sends progress updates to the bolusProgressReporterCallback, // which then posts appropriate events on the bus, so in this branch no posts are needed runningBolusCommand = new BolusCommand(detailedBolusInfo.insulin, bolusProgressReportCallback); CommandResult bolusCmdResult = runCommand(runningBolusCommand);