From 3f10c316a40a16f0d7b0323f48d5422788d545ed Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 23 Nov 2017 01:47:14 +0100 Subject: [PATCH] combo set basal: account for different granularity > 1 U/h --- TODO-Combo.md | 2 ++ .../plugins/PumpCombo/ComboPlugin.java | 17 ++++++++++++++++- .../commands/SetBasalProfileCommand.java | 15 +++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/TODO-Combo.md b/TODO-Combo.md index 3c37507d89..703a61aa3b 100644 --- a/TODO-Combo.md +++ b/TODO-Combo.md @@ -44,6 +44,7 @@ - [x] Raise a warning if time clock is off - [-] Ruffy: support reading date/time menus - [ ] Setting pump basal profile + - [ ] Overview notification on updated/failed basal profile - [-] Pairing (and sourcing ruffy) - [x] Run readReservoirAndBolusLevel after SetTbr too so boluses on the pump are caught sooner? Currently the pump gets to know such a record when bolusing or when refresh() is called @@ -92,3 +93,4 @@ - Application shut down is broken with PersistentNotification (never shut down) and WearPlugin - Android logs it as crashed and restarts it, thereby restarting the app (or just keeping it alive, also causes errors with the DB as there were attemtps to open a closed DB instance/ref. + - [ ] Check if TBRs are set to often from ConfigBuilder on high base basal rates (basalstep is 0.01; in reality larger on >1U/h base basal) 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 bcc94c5d6c..c2a7faa79a 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 @@ -245,7 +245,22 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private BasalProfile convertProfileToComboProfile(Profile profile) { BasalProfile basalProfile = new BasalProfile(); for (int i = 0; i < 24; i++) { - basalProfile.hourlyRates[i] = profile.getBasal(Integer.valueOf(i * 60 * 60)); + double rate = profile.getBasal(Integer.valueOf(i * 60 * 60)); + + /*The Combo pump does hava a different granularity for basal rate: + * 0.01 - if below 1U/h + * 0.05 - if above 1U/h + * */ + + if(rate < 1){ + //round to 0.01 granularity; + rate = Math.round(rate/0.01)*0.01; + } else { + //round to 0.05 granularity; + rate = Math.round(rate/0.05)*0.05; + } + + basalProfile.hourlyRates[i] = rate; } return basalProfile; } diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java index f9a291527a..ee99acd8c8 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetBasalProfileCommand.java @@ -81,8 +81,7 @@ public class SetBasalProfileCommand extends BaseCommand { return null; } log.debug("Current rate: " + currentRate + ", requested: " + requestedRate); - double change = requestedRate - currentRate; - long steps = Math.round(change * 100); + long steps = stepsUpToOne(currentRate) - stepsUpToOne(requestedRate); boolean increasing = steps > 0; log.debug("Pressing " + (increasing ? "up" : "down") + " " + Math.abs(steps) + " times"); for (int i = 0; i < Math.abs(steps); i++) { @@ -95,6 +94,14 @@ public class SetBasalProfileCommand extends BaseCommand { return increasing; } + /*Steps UP to 1.0 + * May return a negative value for steps down*/ + private long stepsUpToOne(double rate){ + double change = (1.0-rate); + if (rate > 1) return Math.round(change/0.05); + return Math.round(change/0.01); + } + private void verifyDisplayedRate(double requestedRate, boolean increasingPercentage) { scripter.verifyMenuIsDisplayed(MenuType.BASAL_SET); // wait up to 5s for any scrolling to finish @@ -110,7 +117,7 @@ public class SetBasalProfileCommand extends BaseCommand { displayedRate = scripter.readBlinkingValue(Double.class, MenuAttribute.BASAL_RATE); } log.debug("Final displayed basal rate: " + displayedRate); - if (displayedRate != requestedRate) { + if (Math.abs(displayedRate - requestedRate) > 0.001) { throw new CommandException("Failed to set basal rate, requested: " + requestedRate + ", actual: " + displayedRate); } @@ -120,7 +127,7 @@ public class SetBasalProfileCommand extends BaseCommand { SystemClock.sleep(1000); scripter.verifyMenuIsDisplayed(MenuType.BASAL_SET); double refreshedDisplayedRate = scripter.readBlinkingValue(Double.class, MenuAttribute.BASAL_RATE); - if (displayedRate != refreshedDisplayedRate) { + if (Math.abs(displayedRate - refreshedDisplayedRate) > 0.001) { throw new CommandException("Failed to set basal rate: " + "percentage changed after input stopped from " + displayedRate + " -> " + refreshedDisplayedRate);