From 4185bb347dfc9fb3b00c31dded23e59be8dc7a03 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 Dec 2017 19:34:01 +0100 Subject: [PATCH] handle bolus stop prior to delivery correctly --- .../plugins/Overview/Dialogs/BolusProgressDialog.java | 3 +++ .../plugins/PumpDanaR/services/DanaRExecutionService.java | 6 ++++-- .../services/DanaRKoreanExecutionService.java | 6 ++++-- .../plugins/PumpDanaRS/services/DanaRSService.java | 6 ++++-- .../PumpDanaRv2/services/DanaRv2ExecutionService.java | 6 ++++-- .../java/info/nightscout/androidaps/queue/QueueThread.java | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index 2567c49868..35906187a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -35,6 +35,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL static double amount; public static boolean bolusEnded = false; public static boolean running = true; + public static boolean stopPressed = false; public BolusProgressDialog() { super(); @@ -62,6 +63,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL progressBar.setMax(100); statusView.setText(MainApp.sResources.getString(R.string.waitingforpump)); setCancelable(false); + stopPressed = false; return view; } @@ -95,6 +97,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL switch (view.getId()) { case R.id.overview_bolusprogress_stop: log.debug("Stop bolus delivery button pressed"); + stopPressed = true; stopPressedView.setVisibility(View.VISIBLE); stopButton.setVisibility(View.INVISIBLE); ConfigBuilderPlugin.getActivePump().stopBolusDelivering(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index b3cc11cf2f..a025e1fc61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; @@ -365,6 +366,9 @@ public class DanaRExecutionService extends Service { } public boolean bolus(double amount, int carbs, final Treatment t) { + if (!isConnected()) return false; + if (BolusProgressDialog.stopPressed) return false; + bolusingTreatment = t; int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0); MessageBase start; @@ -374,8 +378,6 @@ public class DanaRExecutionService extends Service { start = new MsgBolusStartWithSpeed(amount, preferencesSpeed); MsgBolusStop stop = new MsgBolusStop(amount, t); - if (!isConnected()) return false; - if (carbs > 0) { mSerialIOThread.sendMessage(new MsgSetCarbsEntry(System.currentTimeMillis(), carbs)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index 9d656e47e5..92137481dc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; @@ -358,12 +359,13 @@ public class DanaRKoreanExecutionService extends Service { } public boolean bolus(double amount, int carbs, final Treatment t) { + if (!isConnected()) return false; + if (BolusProgressDialog.stopPressed) return false; + bolusingTreatment = t; MsgBolusStart start = new MsgBolusStart(amount); MsgBolusStop stop = new MsgBolusStop(amount, t); - if (!isConnected()) return false; - if (carbs > 0) { mSerialIOThread.sendMessage(new MsgSetCarbsEntry(System.currentTimeMillis(), carbs)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index e5ad663bae..f927c107f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; @@ -191,6 +192,9 @@ public class DanaRSService extends Service { public boolean bolus(final double insulin, int carbs, long carbtime, Treatment t) { + if (!isConnected()) return false; + if (BolusProgressDialog.stopPressed) return false; + MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus))); bolusingTreatment = t; final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0); @@ -198,8 +202,6 @@ public class DanaRSService extends Service { DanaRS_Packet_Bolus_Set_Step_Bolus_Stop stop = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(insulin, t); // initialize static variables DanaRS_Packet_Notify_Delivery_Complete complete = new DanaRS_Packet_Notify_Delivery_Complete(insulin, t); // initialize static variables - if (!isConnected()) return false; - if (carbs > 0) { // MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs); #### // bleComm.sendMessage(msg); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 664ff3743a..2020e6d14d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; @@ -357,6 +358,9 @@ public class DanaRv2ExecutionService extends Service { } public boolean bolus(final double amount, int carbs, long carbtime, final Treatment t) { + if (!isConnected()) return false; + if (BolusProgressDialog.stopPressed) return false; + MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus))); bolusingTreatment = t; final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0); @@ -367,8 +371,6 @@ public class DanaRv2ExecutionService extends Service { start = new MsgBolusStartWithSpeed(amount, preferencesSpeed); MsgBolusStop stop = new MsgBolusStop(amount, t); - if (!isConnected()) return false; - if (carbs > 0) { MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs); mSerialIOThread.sendMessage(msg); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 90c571c68e..7baa6a313b 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -97,8 +97,8 @@ public class QueueThread extends Thread { if (queue.performing() == null) { // Pickup 1st command and set performing variable if (queue.size() > 0) { - log.debug("State: performing " + queue.performing().status()); queue.pickup(); + log.debug("State: performing " + queue.performing().status()); MainApp.bus().post(new EventQueueChanged()); queue.performing().execute(); queue.resetPerforming();