unsafe usage checks update.

This commit is contained in:
Johannes Mockenhaupt 2017-11-06 23:15:16 +01:00
parent 8b7725c076
commit be5f7e68a7
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 20 additions and 8 deletions

View file

@ -640,7 +640,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
private void checkForUnsupportedBoluses(CommandResult commandResult) { private void checkForUnsupportedBoluses(CommandResult commandResult) {
long lastViolation = 0; 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; lastViolation = commandResult.lastBolus.timestamp;
} else if (commandResult.history != null) { } else if (commandResult.history != null) {
for (Bolus bolus : commandResult.history.bolusHistory) { for (Bolus bolus : commandResult.history.bolusHistory) {
@ -649,16 +652,17 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
} }
} }
if (lastViolation > 0) { if (lastViolation > 0) {
closedLoopDisabledUntil = lastViolation + 6 * 60 * 60 * 1000; 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 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, Notification n = new Notification(Notification.COMBO_PUMP_ALARM,
MainApp.sResources.getString(R.string.combo_force_disabled), MainApp.sResources.getString(R.string.combo_force_disabled),
Notification.URGENT); Notification.URGENT);
n.soundId = R.raw.alarm; n.soundId = R.raw.alarm;
MainApp.bus().post(new EventNewNotification(n)); MainApp.bus().post(new EventNewNotification(n));
violationWarningRaisedFor = closedLoopDisabledUntil;
} }
} }
} }
@ -920,15 +924,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// Constraints interface // Constraints interface
private long closedLoopDisabledUntil = 0; private long closedLoopDisabledUntil = 0;
private long violationWarningRaisedFor = 0;
@Override @Override
public boolean isLoopEnabled() { public boolean isLoopEnabled() {
return true; return closedLoopDisabledUntil < System.currentTimeMillis();
} }
@Override @Override
public boolean isClosedModeEnabled() { public boolean isClosedModeEnabled() {
return closedLoopDisabledUntil < System.currentTimeMillis(); return true;
} }
@Override @Override

View file

@ -794,11 +794,11 @@
<string name="enable_pump_unreachable_alert">Alert if pump unreachable for 30 min</string> <string name="enable_pump_unreachable_alert">Alert if pump unreachable for 30 min</string>
<string name="combo_pump_never_connected">Never</string> <string name="combo_pump_never_connected">Never</string>
<string name="combo_reservoir_level_insufficant_for_bolus">Not enough insulin left in reservoir for bolus</string> <string name="combo_reservoir_level_insufficant_for_bolus">Not enough insulin left in reservoir for bolus</string>
<string name="combo_pump_bolus_history_state_mismatch">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.</string> <string name="combo_pump_bolus_history_state_mismatch">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.</string>
<string name="combo_pump_bolus_verification_failed">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.</string> <string name="combo_pump_bolus_verification_failed">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.</string>
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string> <string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
<string name="combo_bolus_bolus_delivery_failed">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.</string> <string name="combo_bolus_bolus_delivery_failed">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.</string>
<string name="combo_force_disabled">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.</string> <string name="combo_force_disabled">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.</string>
<string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string> <string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string>
</resources> </resources>

View file

@ -31,6 +31,8 @@ public class PumpState {
public int insulinState = UNKNOWN; public int insulinState = UNKNOWN;
public int activeBasalProfileNumber; public int activeBasalProfileNumber;
/** True if use of an extended or multiwave bolus has been detected */
public boolean unsafeUsageDetected;
public PumpState menu(String menu) { public PumpState menu(String menu) {
this.menu = menu; this.menu = menu;

View file

@ -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.Menu;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; 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.MenuType;
import org.monkey.d.ruffy.ruffy.driver.display.menu.BolusType;
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -440,7 +441,11 @@ public class RuffyScripter implements RuffyCommands {
if (menuType == MenuType.MAIN_MENU) { if (menuType == MenuType.MAIN_MENU) {
Double tbrPercentage = (Double) menu.getAttribute(MenuAttribute.TBR); 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; state.tbrActive = true;
Double displayedTbr = (Double) menu.getAttribute(MenuAttribute.TBR); Double displayedTbr = (Double) menu.getAttribute(MenuAttribute.TBR);
state.tbrPercent = displayedTbr.intValue(); state.tbrPercent = displayedTbr.intValue();