more
This commit is contained in:
parent
fabaf7c2ef
commit
d851637d4f
3 changed files with 34 additions and 22 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue