From 81b97b5278227149582fd29b08177a2e1cf56acc Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 31 Aug 2017 23:26:55 +0200 Subject: [PATCH] Add option to ignore setting a TBR as long as it does't occur twice in a row. (cherry picked from commit 238e85c) --- .../plugins/PumpCombo/ComboPlugin.java | 20 +++++++++++++++++-- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_combo.xml | 4 ++++ 3 files changed, 24 insertions(+), 2 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 b800404c3f..6eed939412 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 @@ -67,6 +67,8 @@ public class ComboPlugin implements PluginBase, PumpInterface { private ComboPump pump = new ComboPump(); + private boolean ignoreLastSetTbrFailure = false; + @Nullable private volatile BolusCommand runningBolusCommand; @@ -98,7 +100,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { pumpDescription.isTempBasalCapable = true; pumpDescription.tempBasalStyle = PumpDescription.PERCENT; - pumpDescription.maxTempPercent = SP.getInt(COMBO_MAX_TEMP_PERCENT_SP, 500); + pumpDescription.maxTempPercent = 500; pumpDescription.tempPercentStep = 10; pumpDescription.tempDurationStep = 15; @@ -139,7 +141,8 @@ public class ComboPlugin implements PluginBase, PumpInterface { long now = System.currentTimeMillis(); long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000); boolean loopEnabled = ConfigBuilderPlugin.getActiveLoop() != null; - if (now > fiveMinutesSinceLastAlarm && loopEnabled) { + if (now > fiveMinutesSinceLastAlarm && loopEnabled + && !(SP.getBoolean(R.string.key_combo_ignore_transient_tbr_errors, false) && localLastCmd instanceof SetTbrCommand && ignoreLastSetTbrFailure)) { log.error("Command failed: " + localLastCmd); log.error("Command result: " + localLastCmdResult); PumpState localPumpState = pump.state; @@ -505,6 +508,19 @@ public class ComboPlugin implements PluginBase, PumpInterface { log.error("Exception received from pump", commandResult.exception); } + // error tolerance + if (commandResult.success) ignoreLastSetTbrFailure = false; + + if (command instanceof SetTbrCommand) { + if (!commandResult.success && !ignoreLastSetTbrFailure) { + // ignore this once + ignoreLastSetTbrFailure = true; + } else { + // second failure in a row + ignoreLastSetTbrFailure = false; + } + } + pump.lastCmd = command; pump.lastCmdTime = new Date(); pump.lastCmdResult = commandResult; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6c9385bdd1..4d0ea04beb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -718,5 +718,7 @@ Experimental bolus combo_experimental_split_bolus Experimental split bolus feature + combo_ignore_transient_tbr_errors + Ignore transient TBR errors diff --git a/app/src/main/res/xml/pref_combo.xml b/app/src/main/res/xml/pref_combo.xml index b527a14b51..857281b097 100644 --- a/app/src/main/res/xml/pref_combo.xml +++ b/app/src/main/res/xml/pref_combo.xml @@ -18,6 +18,10 @@ android:defaultValue="false" android:key="@string/key_combo_enable_experimental_split_bolus" android:title="@string/combo_enable_experimental_split_bolus" /> +