From 326229ebbb0667ef3ce7844ada58d6ffcb6af1a2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 19 Mar 2018 17:06:22 +0100 Subject: [PATCH] limitClosedLoop & remove openloop flavor --- app/build.gradle | 18 ------------------ .../info/nightscout/androidaps/MainApp.java | 6 +++++- .../interfaces/ConstraintsInterface.java | 2 +- .../ConfigBuilder/ConfigBuilderPlugin.java | 12 +++++------- .../ObjectivesPlugin.java | 14 ++++++++------ .../ConstraintsSafety/SafetyPlugin.java | 10 ++++++---- .../androidaps/plugins/Loop/LoopPlugin.java | 9 ++++++--- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 5 ++++- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 5 ++++- .../OpenAPSSMB/DetermineBasalAdapterSMBJS.java | 8 +++++--- .../plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 5 ++++- .../plugins/Overview/OverviewFragment.java | 8 ++++++-- .../plugins/PumpCombo/ComboPlugin.java | 3 +-- .../plugins/PumpDanaR/AbstractDanaRPlugin.java | 3 +-- .../plugins/PumpDanaRS/DanaRSPlugin.java | 3 +-- .../plugins/PumpInsight/InsightPumpPlugin.java | 3 +-- .../plugins/Wear/ActionStringHandler.java | 7 ++++--- app/src/main/res/values/strings.xml | 3 ++- 18 files changed, 64 insertions(+), 60 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 00c78fe077..e6efea8288 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -97,21 +97,6 @@ android { buildConfigField "boolean", "APS", "true" buildConfigField "boolean", "PUMPDRIVERS", "true" buildConfigField "boolean", "NSCLIENTOLNY", "false" - buildConfigField "boolean", "CLOSEDLOOP", "true" - buildConfigField "boolean", "G5UPLOADER", "false" - buildConfigField "boolean", "PUMPCONTROL", "false" - } - openloop { - dimension "standard" - resValue "string", "app_name", "AndroidAPS" - versionName version - manifestPlaceholders = [ - appIcon: "@mipmap/blueowl" - ] - buildConfigField "boolean", "APS", "true" - buildConfigField "boolean", "PUMPDRIVERS", "true" - buildConfigField "boolean", "NSCLIENTOLNY", "false" - buildConfigField "boolean", "CLOSEDLOOP", "false" buildConfigField "boolean", "G5UPLOADER", "false" buildConfigField "boolean", "PUMPCONTROL", "false" } @@ -125,7 +110,6 @@ android { buildConfigField "boolean", "APS", "false" buildConfigField "boolean", "PUMPDRIVERS", "true" buildConfigField "boolean", "NSCLIENTOLNY", "false" - buildConfigField "boolean", "CLOSEDLOOP", "false" buildConfigField "boolean", "G5UPLOADER", "false" buildConfigField "boolean", "PUMPCONTROL", "true" } @@ -139,7 +123,6 @@ android { buildConfigField "boolean", "APS", "false" buildConfigField "boolean", "PUMPDRIVERS", "false" buildConfigField "boolean", "NSCLIENTOLNY", "true" - buildConfigField "boolean", "CLOSEDLOOP", "false" buildConfigField "boolean", "G5UPLOADER", "false" buildConfigField "boolean", "PUMPCONTROL", "false" } @@ -153,7 +136,6 @@ android { buildConfigField "boolean", "APS", "false" buildConfigField "boolean", "PUMPDRIVERS", "false" buildConfigField "boolean", "NSCLIENTOLNY", "false" - buildConfigField "boolean", "CLOSEDLOOP", "false" buildConfigField "boolean", "G5UPLOADER", "true" buildConfigField "boolean", "PUMPCONTROL", "false" } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 5087fefefa..9b30f48ea2 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -28,6 +28,7 @@ import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.Actions.ActionsFragment; import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; @@ -191,13 +192,16 @@ public class MainApp extends Application { MainApp.getConfigBuilder().initialize(); } NSUpload.uploadAppStart(); + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + if (Config.NSCLIENT) FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-NSClient")); else if (Config.G5UPLOADER) FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-G5Uploader")); else if (Config.PUMPCONTROL) FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-PumpControl")); - else if (MainApp.getConfigBuilder().isClosedModeEnabled()) + else if (closedLoopEnabled.get()) FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-ClosedLoop")); else FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop")); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java index 471b7735cf..442bf914b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java @@ -9,7 +9,7 @@ public interface ConstraintsInterface { void limitRunningLoop(BooleanConstraint value); - boolean isClosedModeEnabled(); + void limitClosedLoop(BooleanConstraint value); boolean isAutosensModeEnabled(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 3f5283ec48..c88b369b25 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -453,23 +453,21 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { - ConstraintsInterface constrain = (ConstraintsInterface) p; + ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; - constrain.limitRunningLoop(value); + constraint.limitRunningLoop(value); } } @Override - public boolean isClosedModeEnabled() { - boolean result = true; + public void limitClosedLoop(BooleanConstraint value) { ArrayList constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { - ConstraintsInterface constrain = (ConstraintsInterface) p; + ConstraintsInterface constraint = (ConstraintsInterface) p; if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; - result = result && constrain.isClosedModeEnabled(); + constraint.limitClosedLoop(value); } - return result; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index 0516cdda51..cd80cffebf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -15,9 +15,9 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.APSInterface; -import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; @@ -183,8 +183,9 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { case 2: return new RequirementResult(true, ""); case 3: - boolean closedModeEnabled = SafetyPlugin.getPlugin().isClosedModeEnabled(); - return new RequirementResult(closedModeEnabled, MainApp.sResources.getString(R.string.closedmodeenabled) + ": " + yesOrNo(closedModeEnabled)); + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + SafetyPlugin.getPlugin().limitClosedLoop(closedLoopEnabled); + return new RequirementResult(closedLoopEnabled.get(), MainApp.sResources.getString(R.string.closedmodeenabled) + ": " + yesOrNo(closedLoopEnabled.get())); case 4: double maxIOB = MainApp.getConfigBuilder().applyMaxIOBConstraints(1000d); boolean maxIobSet = maxIOB > 0; @@ -296,12 +297,13 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { @Override public void limitRunningLoop(BooleanConstraint value) { if (objectives.get(0).started.getTime() == 0) - value.set(false, MainApp.gs(R.string.objective1notstarted)); + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1)); } @Override - public boolean isClosedModeEnabled() { - return objectives.get(3).started.getTime() > 0; + public void limitClosedLoop(BooleanConstraint value) { + if (objectives.get(3).started.getTime() == 0) + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4)); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java index 4062836c48..1b39a8bc9c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java @@ -5,7 +5,6 @@ import org.slf4j.LoggerFactory; import java.util.Objects; -import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; @@ -103,10 +102,13 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { * Constraints interface **/ @Override - public boolean isClosedModeEnabled() { - if (!MainApp.isEngineeringModeOrRelease()) return false; + public void limitClosedLoop(BooleanConstraint value) { + if (!MainApp.isEngineeringModeOrRelease()) + value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch)); + String mode = SP.getString("aps_mode", "open"); - return mode.equals("closed") && BuildConfig.CLOSEDLOOP; + if (!mode.equals("closed")) + value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences)); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index a1ca643adc..3452a2ff3f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -26,9 +26,9 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.APSInterface; -import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; @@ -152,7 +152,7 @@ public class LoopPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventTreatmentChange ev) { - if (ev.treatment == null || !ev.treatment.isSMB){ + if (ev.treatment == null || !ev.treatment.isSMB) { invoke("EventTreatmentChange", true); } } @@ -331,7 +331,10 @@ public class LoopPlugin implements PluginBase { return; } - if (MainApp.getConfigBuilder().isClosedModeEnabled()) { + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + + if (closedLoopEnabled.get()) { if (result.isChangeRequested()) { final PumpEnactResult waiting = new PumpEnactResult(); waiting.queued = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index dfab195125..97fedba4a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -248,7 +249,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) determineBasalResultAMA.tempBasalReqested = false; // limit requests on openloop mode - if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + if (!closedLoopEnabled.get()) { long now = System.currentTimeMillis(); TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 76df63e752..3d9cf3ea4d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.ScriptReader; @@ -237,7 +238,9 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) determineBasalResultMA.tempBasalReqested = false; // limit requests on openloop mode - if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + if (!closedLoopEnabled.get()) { TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) { // going to cancel diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java index 9df54b34d3..5de8676973 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java @@ -27,12 +27,11 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback; -import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; @@ -217,6 +216,9 @@ public class DetermineBasalAdapterSMBJS { String units = profile.getUnits(); + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + mProfile = new JSONObject(); mProfile.put("max_iob", maxIob); @@ -246,7 +248,7 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap); mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false)); mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable); - boolean SMBEnabled = SP.getBoolean(R.string.key_use_smb, false) && MainApp.getConfigBuilder().isClosedModeEnabled(); + boolean SMBEnabled = SP.getBoolean(R.string.key_use_smb, false) && closedLoopEnabled.get(); mProfile.put("enableSMB_with_COB", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_with_COB, false)); mProfile.put("enableSMB_with_temptarget", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_with_temptarget, false)); mProfile.put("allowSMB_with_high_temptarget", SMBEnabled && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java index f10e6cb0be..3c76698289 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -253,7 +254,9 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) determineBasalResultSMB.tempBasalReqested = false; // limit requests on openloop mode - if (!MainApp.getConfigBuilder().isClosedModeEnabled()) { + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + if (!closedLoopEnabled.get()) { TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) { // going to cancel diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index e90a77c524..c4b2bb97d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -87,6 +87,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; @@ -1016,6 +1017,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } } + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + // open loop mode final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; if (Config.APS && pump.getPumpDescription().isTempBasalCapable) { @@ -1036,7 +1040,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, apsModeView.setText(MainApp.sResources.getString(R.string.pumpsuspended)); apsModeView.setTextColor(Color.WHITE); } else if (activeloop != null && activeloop.isEnabled(activeloop.getType())) { - if (MainApp.getConfigBuilder().isClosedModeEnabled()) { + if (closedLoopEnabled.get()) { apsModeView.setText(MainApp.sResources.getString(R.string.closedloop)); } else { apsModeView.setText(MainApp.sResources.getString(R.string.openloop)); @@ -1066,7 +1070,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // **** Temp button **** if (acceptTempLayout != null) { - boolean showAcceptButton = !MainApp.getConfigBuilder().isClosedModeEnabled(); // Open mode needed + boolean showAcceptButton = !closedLoopEnabled.get(); // Open mode needed showAcceptButton = showAcceptButton && finalLastRun != null && finalLastRun.lastAPSRun != null; // aps result must exist showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.isChangeRequested(); // change is requested 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 85a2dbbf55..9a8293f091 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 @@ -1428,8 +1428,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } @Override - public boolean isClosedModeEnabled() { - return true; + public void limitClosedLoop(BooleanConstraint value) { } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index 111919c47d..70eddecf85 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java @@ -441,8 +441,7 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface, } @Override - public boolean isClosedModeEnabled() { - return true; + public void limitClosedLoop(BooleanConstraint value) { } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 1bc785352d..2604c4e1ed 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -279,8 +279,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, } @Override - public boolean isClosedModeEnabled() { - return true; + public void limitClosedLoop(BooleanConstraint value) { } @Override 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 9889c9723c..6dd70ba38e 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 @@ -1084,8 +1084,7 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints } @Override - public boolean isClosedModeEnabled() { - return true; + public void limitClosedLoop(BooleanConstraint value) { } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index b304490e22..d912c2a8d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.Wear; -import android.Manifest; import android.os.HandlerThread; import android.support.annotation.NonNull; @@ -27,8 +26,8 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; @@ -436,7 +435,9 @@ public class ActionStringHandler { // decide if enabled/disabled closed/open; what Plugin as APS? final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); if (activeloop != null && activeloop.isEnabled(activeloop.getType())) { - if (MainApp.getConfigBuilder().isClosedModeEnabled()) { + BooleanConstraint closedLoopEnabled = new BooleanConstraint(true); + MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled); + if (closedLoopEnabled.get()) { ret += "CLOSED LOOP\n"; } else { ret += "OPEN LOOP\n"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1eff2b796e..c962481eaf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -962,8 +962,9 @@ ProfileSwitch missing. Please do a profile switch or press \"Activate Profile\" in the LocalProfile. Bolus count TBR count - Objective 1 not started + Objective %d not started Pump is not temp basal capable No valid basal rate read from pump + Closed loop mode disabled in preferences