From 44ba10e00ccd7220bb190c03e4ef1a214cfb0137 Mon Sep 17 00:00:00 2001 From: Jamorham Date: Mon, 5 Feb 2018 11:33:00 +0000 Subject: [PATCH 1/2] Insight treat 100% TBR from absolute as cancel --- .../androidaps/plugins/PumpInsight/InsightPumpPlugin.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java index 67cea869e2..0e5b37291f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java @@ -463,6 +463,11 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints log("Calculated requested rate: " + absoluteRate + " base rate: " + base_basal + " percentage: " + amount + "%"); amount = (int) Math.round(((double) amount) / 10d) * 10; log("Calculated final rate: " + amount + "%"); + + if (amount == 100) { + return cancelTempBasal(false); + } + if (amount > 250) amount = 250; final SetTBRTaskRunner task = new SetTBRTaskRunner(connector.getServiceConnector(), amount, durationInMinutes); From 6a9b293e4946a3abf655bb134a50199a79c24133 Mon Sep 17 00:00:00 2001 From: Jamorham Date: Mon, 5 Feb 2018 14:39:55 +0000 Subject: [PATCH 2/2] Improved TBR cancelling --- .../PumpInsight/InsightPumpPlugin.java | 16 ++---- .../connector/SetTBRTaskRunner.java | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java index 0e5b37291f..3180e7d320 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpInsight.connector.AbsoluteTBRTaskRunner; import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelBolusTaskRunner; import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector; +import info.nightscout.androidaps.plugins.PumpInsight.connector.SetTBRTaskRunner; import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpCallback; import info.nightscout.androidaps.plugins.PumpInsight.events.EventInsightPumpUpdateGui; import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver; @@ -52,7 +53,6 @@ import sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMess import sugar.free.sightparser.applayer.messages.remote_control.StandardBolusMessage; import sugar.free.sightparser.handling.SingleMessageTaskRunner; import sugar.free.sightparser.handling.TaskRunner; -import sugar.free.sightparser.handling.taskrunners.SetTBRTaskRunner; import sugar.free.sightparser.handling.taskrunners.StatusTaskRunner; import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.getRecordUniqueID; @@ -85,8 +85,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints private long statusResultTime = -1; private Date lastDataTime = new Date(0); private TaskRunner taskRunner; - private boolean fragmentEnabled = true; - private boolean fragmentVisible = true; + private boolean fragmentEnabled = false; + private boolean fragmentVisible = false; private boolean fauxTBRcancel = true; private PumpDescription pumpDescription = new PumpDescription(); private double basalRate = 0; @@ -615,15 +615,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints final UUID cmd; if (fauxTBRcancel) { - final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); - // I'm not totally sure whether based on the times that this cancellation will occur - // whether the logic should actually be inverted as we are reversing a decision. - // I believe it also affects at most 2.5% of an hourly basal rate and the pump only - // delivers basal every 3 minutes when > 0.19U per hour, below that unspecified. - final int faux_percent = (activeTemp == null) ? 90 : (activeTemp.percentRate > 100) ? 110 : 90; - - final int faux_duration = 15; - cmd = aSyncTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), faux_percent, 15), "Faux Cancel TBR - setting " + faux_percent + "%" + " " + faux_duration + "m"); + cmd = aSyncTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), 100, 1), "Faux Cancel TBR - setting " + "90%" + " 1m"); } else { cmd = aSyncSingleCommand(new CancelTBRMessage(), "Cancel Temp Basal"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java new file mode 100644 index 0000000000..5d22feba8f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/connector/SetTBRTaskRunner.java @@ -0,0 +1,51 @@ +package info.nightscout.androidaps.plugins.PumpInsight.connector; + +import sugar.free.sightparser.applayer.messages.AppLayerMessage; +import sugar.free.sightparser.applayer.messages.remote_control.ChangeTBRMessage; +import sugar.free.sightparser.applayer.messages.remote_control.SetTBRMessage; +import sugar.free.sightparser.applayer.messages.status.CurrentTBRMessage; +import sugar.free.sightparser.handling.SightServiceConnector; +import sugar.free.sightparser.handling.TaskRunner; + +// from Tebbe - note this uses 1 minute duration to silently cancel existing TBR + +public class SetTBRTaskRunner extends TaskRunner { + + private int amount; + private int duration; + + public SetTBRTaskRunner(SightServiceConnector serviceConnector, int amount, int duration) { + super(serviceConnector); + this.amount = amount; + this.duration = duration; + } + + @Override + protected AppLayerMessage run(AppLayerMessage message) throws Exception { + if (message == null) return new CurrentTBRMessage(); + else if (message instanceof CurrentTBRMessage) { + if (((CurrentTBRMessage) message).getPercentage() == 100) { + if (amount == 100) finish(amount); + else { + SetTBRMessage setTBRMessage = new SetTBRMessage(); + setTBRMessage.setDuration((short) duration); + setTBRMessage.setAmount((short) amount); + return setTBRMessage; + } + } else { + if (amount == 100) { + ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage(); + changeTBRMessage.setDuration((short) 1); + changeTBRMessage.setAmount((short) 90); + return changeTBRMessage; + } else { + ChangeTBRMessage changeTBRMessage = new ChangeTBRMessage(); + changeTBRMessage.setDuration((short) duration); + changeTBRMessage.setAmount((short) amount); + return changeTBRMessage; + } + } + } else if (message instanceof SetTBRMessage) finish(amount); + return null; + } +}