From 8b21bb120384d00a60ec9e0cdad709acacb31261 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 15 Jul 2017 11:50:29 +0200 Subject: [PATCH] Skip TBR changes smaller than 20%. ~50 TBR changes in a 6 hour night seem excessive, even if pump was handicapped by not being connected and thus not having any effect to work with. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 9033faffe2..fbc18fc760 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 @@ -51,6 +51,9 @@ public class ComboPlugin implements PluginBase, PumpInterface { PumpDescription pumpDescription = new PumpDescription(); + // TODO quick hack until pump state is more thoroughly supported + int activeTbrPercentage = -1; + private RuffyScripter ruffyScripter; private Date lastCmdTime = new Date(0); private ServiceConnection mRuffyServiceConnection; @@ -329,6 +332,15 @@ public class ComboPlugin implements PluginBase, PumpInterface { log.debug("Rounded requested percentage from " + percent + " to " + rounded); percent = rounded; } + if (activeTbrPercentage != -1 && Math.abs(activeTbrPercentage - percent) <= 20) { + log.debug("Not bothering the pump for a small TBR change from " + activeTbrPercentage + "% -> " + percent + "%"); + PumpEnactResult pumpEnactResult = new PumpEnactResult(); + pumpEnactResult.success = true; + pumpEnactResult.enacted = false; + pumpEnactResult.percent = activeTbrPercentage; + pumpEnactResult.comment = "TBR change too small, skipping"; + return pumpEnactResult; + } MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); CommandResult commandResult = runCommand(new SetTbrCommand(percent, durationInMinutes)); if (commandResult.enacted) { @@ -339,6 +351,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { tempStart.source = Source.USER; ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder(); treatmentsInterface.addToHistoryTempBasal(tempStart); + activeTbrPercentage = percent; } PumpEnactResult pumpEnactResult = new PumpEnactResult(); @@ -369,6 +382,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { tempStop.source = Source.USER; ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder(); treatmentsInterface.addToHistoryTempBasal(tempStop); + activeTbrPercentage = 100; } PumpEnactResult pumpEnactResult = new PumpEnactResult();