From be5f7e68a7f4e95152d2fada8f6cf22f7f2901eb Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 6 Nov 2017 23:15:16 +0100 Subject: [PATCH] unsafe usage checks update. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 15 ++++++++++----- app/src/main/res/values/strings.xml | 4 ++-- .../main/java/de/jotomo/ruffy/spi/PumpState.java | 2 ++ .../de/jotomo/ruffyscripter/RuffyScripter.java | 7 ++++++- 4 files changed, 20 insertions(+), 8 deletions(-) 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 3fefbf9f0a..85226b3c0c 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 @@ -640,7 +640,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf private void checkForUnsupportedBoluses(CommandResult commandResult) { long lastViolation = 0; - if (commandResult.lastBolus != null && !commandResult.lastBolus.isValid) { + if (commandResult.state.unsafeUsageDetected) { + lastViolation = System.currentTimeMillis(); + } + if (commandResult.lastBolus != null && !commandResult.lastBolus.isValid) { lastViolation = commandResult.lastBolus.timestamp; } else if (commandResult.history != null) { for (Bolus bolus : commandResult.history.bolusHistory) { @@ -649,16 +652,17 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } } - if (lastViolation > 0) { closedLoopDisabledUntil = lastViolation + 6 * 60 * 60 * 1000; - if (closedLoopDisabledUntil > System.currentTimeMillis()) { + if (closedLoopDisabledUntil > System.currentTimeMillis() && violationWarningRaisedFor != closedLoopDisabledUntil) { // TODO add message to either Combo tab or its errors popup + // TODO warn once; after that the user gets suggesiotn from open loop mode as a reminder... Notification n = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_force_disabled), Notification.URGENT); n.soundId = R.raw.alarm; MainApp.bus().post(new EventNewNotification(n)); + violationWarningRaisedFor = closedLoopDisabledUntil; } } } @@ -920,15 +924,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // Constraints interface private long closedLoopDisabledUntil = 0; + private long violationWarningRaisedFor = 0; @Override public boolean isLoopEnabled() { - return true; + return closedLoopDisabledUntil < System.currentTimeMillis(); } @Override public boolean isClosedModeEnabled() { - return closedLoopDisabledUntil < System.currentTimeMillis(); + return true; } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 35498ff6a9..8ac69ff8d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -794,11 +794,11 @@ Alert if pump unreachable for 30 min Never Not enough insulin left in reservoir for bolus - A bolus has been given recently on the pump directly of which AndroidAPS has only just become aware of. The pump\'s history is currently being read. Please check the Combo page, verify the last bolus and IOB and bolus again if needed. No bolus has been given. + A bolus has been delivered directly on the pump recently, of which AndroidAPS has only just become aware of. The pump\'s history is currently being read. Please check the Combo page, verify the last bolus and IOB and bolus again if needed. No bolus has been delivered. Bolus delivery verification failed. The pump history will be read again on the next loop run or when refreshing from the Combo page. Please check and bolus again if needed. Requested operation not supported by pump Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please check the Combo page and bolus again as needed. - Unsafe usage: extended or multiwave boluses have been delivered within the last 6h. Closed loop mode forcefully disabled. Only normal boluses are supported when running in closed loop mode. + Unsafe usage: extended or multiwave boluses have been delivered within the last 6 hours. Loop mode has been disabled until 6 hours after the last unsupported bolus. Only normal boluses are supported in loop mode. A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed. diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java index ad863766ff..2b238615de 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/PumpState.java @@ -31,6 +31,8 @@ public class PumpState { public int insulinState = UNKNOWN; public int activeBasalProfileNumber; + /** True if use of an extended or multiwave bolus has been detected */ + public boolean unsafeUsageDetected; public PumpState menu(String menu) { this.menu = menu; diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index a98f6b22fd..1429ef6456 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -17,6 +17,7 @@ import org.monkey.d.ruffy.ruffy.driver.IRuffyService; import org.monkey.d.ruffy.ruffy.driver.display.Menu; import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; import org.monkey.d.ruffy.ruffy.driver.display.MenuType; +import org.monkey.d.ruffy.ruffy.driver.display.menu.BolusType; import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -440,7 +441,11 @@ public class RuffyScripter implements RuffyCommands { if (menuType == MenuType.MAIN_MENU) { Double tbrPercentage = (Double) menu.getAttribute(MenuAttribute.TBR); - if (tbrPercentage != 100) { + BolusType bolusType = (BolusType) menu.getAttribute(MenuAttribute.BOLUS_TYPE); + if (bolusType != null && bolusType != BolusType.NORMAL) { + // unsupported Extended/Multiwave bolus running + state.unsafeUsageDetected = true; + } else if (tbrPercentage != 100) { state.tbrActive = true; Double displayedTbr = (Double) menu.getAttribute(MenuAttribute.TBR); state.tbrPercent = displayedTbr.intValue();