From 2a98a7e9ba1d348e326eca3adacc9c263833cd25 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 3 Oct 2017 21:47:36 +0200 Subject: [PATCH] RS bolus code --- .../plugins/PumpDanaRS/DanaRSPlugin.java | 17 +++++++++++++++-- .../DanaRS_Packet_Notify_Delivery_Complete.java | 3 +++ .../plugins/PumpDanaRS/services/BLEComm.java | 1 + .../PumpDanaRS/services/DanaRSService.java | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 1f3b99bd1a..859b88e434 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -436,9 +436,22 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin); if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history + int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0); + int speed = 12; + switch (preferencesSpeed) { + case 0: + speed = 12; + break; + case 1: + speed = 30; + break; + case 2: + speed = 60; + break; + } // v2 stores end time for bolus, we need to adjust time - // delivery speed is 12 U/min - detailedBolusInfo.date += detailedBolusInfo.insulin / 12d * 60 * 1000; + // default delivery speed is 12 U/min + detailedBolusInfo.date += detailedBolusInfo.insulin / speed * 60d * 1000; // clean carbs to prevent counting them as twice because they will picked up as another record // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records double carbs = detailedBolusInfo.carbs; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java index 88327e1201..0139b12197 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Notify_Delivery_Complete.java @@ -17,6 +17,7 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet { private static Treatment t; private static double amount; + public static boolean done; public DanaRS_Packet_Notify_Delivery_Complete() { super(); @@ -28,6 +29,7 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet { this(); this.amount = amount; this.t = t; + done = false; } @Override @@ -40,6 +42,7 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet { bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), deliveredInsulin); bolusingEvent.t = t; bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100); + done = true; MainApp.bus().post(bolusingEvent); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java index abd7049364..3fe3707bca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/BLEComm.java @@ -695,6 +695,7 @@ public class BLEComm { Runnable task = new DisconnectRunnable(); final int sec = 5; scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS); + log.debug("Disconnection scheduled"); } } 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 e1fa03ea4f..539f846773 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 @@ -214,7 +214,7 @@ public class DanaRSService extends Service { t.insulin = 0d; return false; } - while (!stop.stopped && !start.failed) { + while (!stop.stopped && !start.failed && !complete.done) { SystemClock.sleep(100); if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm stop.stopped = true; @@ -225,6 +225,7 @@ public class DanaRSService extends Service { } SystemClock.sleep(3000); bolusingTreatment = null; + DanaRSPlugin.connectIfNotConnected("ReadHistoryAfterBolus"); loadEvents(); return true; }