diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index 2b085007e3..45efe4722d 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -31,6 +31,7 @@ import info.nightscout.androidaps.queue.commands.CommandExtendedBolus; import info.nightscout.androidaps.queue.commands.CommandLoadEvents; import info.nightscout.androidaps.queue.commands.CommandLoadHistory; import info.nightscout.androidaps.queue.commands.CommandReadStatus; +import info.nightscout.androidaps.queue.commands.CommandSMBBolus; import info.nightscout.androidaps.queue.commands.CommandSetProfile; import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute; import info.nightscout.androidaps.queue.commands.CommandTempBasalPercent; @@ -65,7 +66,6 @@ import info.nightscout.androidaps.queue.commands.CommandTempBasalPercent; * connect() is called again * * when queue is empty, disconnect is called - * */ public class CommandQueue { @@ -141,17 +141,22 @@ public class CommandQueue { // returns true if command is queued public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) { - if (isRunning(Command.CommandType.BOLUS)) { + Command.CommandType type = detailedBolusInfo.isSMB ? Command.CommandType.SMB_BOLUS : Command.CommandType.BOLUS; + + if (isRunning(type)) { if (callback != null) callback.result(executingNowError()).run(); return false; } // remove all unfinished boluses - removeAll(Command.CommandType.BOLUS); + removeAll(type); // add new command to queue - add(new CommandBolus(detailedBolusInfo, callback)); + if (detailedBolusInfo.isSMB) + add(new CommandSMBBolus(detailedBolusInfo, callback)); + else + add(new CommandBolus(detailedBolusInfo, callback)); notifyAboutNewCommand(); @@ -162,7 +167,7 @@ public class CommandQueue { detailedBolusInfo.insulin = MainApp.getConfigBuilder().applyBolusConstraints(detailedBolusInfo.insulin); detailedBolusInfo.carbs = MainApp.getConfigBuilder().applyCarbsConstraints((int) detailedBolusInfo.carbs); - BolusProgressDialog bolusProgressDialog = null; + BolusProgressDialog bolusProgressDialog; if (detailedBolusInfo.context != null) { bolusProgressDialog = new BolusProgressDialog(); bolusProgressDialog.setInsulin(detailedBolusInfo.insulin); @@ -228,7 +233,7 @@ public class CommandQueue { return false; } - Double rateAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); + Double rateAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); // remove all unfinished removeAll(Command.CommandType.EXTENDEDBOLUS); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java index 4624e2385f..9c5a8cf6ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java @@ -11,6 +11,7 @@ import info.nightscout.androidaps.queue.Callback; public abstract class Command { public enum CommandType { BOLUS, + SMB_BOLUS, TEMPBASAL, EXTENDEDBOLUS, BASALPROFILE, diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java new file mode 100644 index 0000000000..4d3fc92883 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java @@ -0,0 +1,39 @@ +package info.nightscout.androidaps.queue.commands; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; +import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; +import info.nightscout.androidaps.queue.Callback; +import info.nightscout.utils.DecimalFormatter; + +/** + * Created by mike on 09.11.2017. + */ + +public class CommandSMBBolus extends Command { + DetailedBolusInfo detailedBolusInfo; + + public CommandSMBBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) { + commandType = CommandType.SMB_BOLUS; + this.detailedBolusInfo = detailedBolusInfo; + this.callback = callback; + } + + @Override + public void execute() { + PumpEnactResult r = ConfigBuilderPlugin.getActivePump().deliverTreatment(detailedBolusInfo); + + BolusProgressDialog.bolusEnded = true; + MainApp.bus().post(new EventDismissBolusprogressIfRunning(r)); + + if (callback != null) + callback.result(r).run(); + } + + public String status() { + return "SMBBOLUS " + DecimalFormatter.to1Decimal(detailedBolusInfo.insulin) + "U"; + } +}