diff --git a/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java b/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java index fc37f5f2a5..ceb85c6967 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java @@ -42,6 +42,10 @@ public class ConstraintChecker implements ConstraintsInterface { return isSMBModeEnabled(new Constraint<>(true)); } + public Constraint isUAMEnabled() { + return isUAMEnabled(new Constraint<>(true)); + } + public Constraint isAdvancedFilteringEnabled() { return isAdvancedFilteringEnabled(new Constraint<>(true)); } @@ -130,6 +134,18 @@ public class ConstraintChecker implements ConstraintsInterface { return value; } + @Override + public Constraint isUAMEnabled(Constraint value) { + + ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); + for (PluginBase p : constraintsPlugins) { + ConstraintsInterface constraint = (ConstraintsInterface) p; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; + constraint.isUAMEnabled(value); + } + return value; + } + @Override public Constraint isAdvancedFilteringEnabled(Constraint value) { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); 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 310c94ac20..5ac8cc83f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java @@ -27,6 +27,10 @@ public interface ConstraintsInterface { return value; } + default Constraint isUAMEnabled(Constraint value) { + return value; + } + default Constraint isAdvancedFilteringEnabled(Constraint value) { return value; } 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 9229164eb0..a1a9d5ff6e 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 @@ -18,6 +18,7 @@ import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.HardLimits; import info.nightscout.utils.Round; @@ -94,6 +95,17 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface { return value; } + @Override + public Constraint isUAMEnabled(Constraint value) { + boolean enabled = SP.getBoolean(R.string.key_use_uam, false); + if (!enabled) + value.set(false, MainApp.gs(R.string.uamdisabledinpreferences), this); + boolean oref1Enabled = SensitivityOref1Plugin.getPlugin().isEnabled(PluginType.SENSITIVITY); + if (!oref1Enabled) + value.set(false, MainApp.gs(R.string.uamdisabledoref1notselected), this); + return value; + } + @Override public Constraint isAdvancedFilteringEnabled(Constraint value) { BgSourceInterface bgSource = ConfigBuilderPlugin.getPlugin().getActiveBgSource(); 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 f974ff472e..bdd06372d9 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 @@ -211,6 +211,7 @@ public class DetermineBasalAdapterSMBJS { double autosensDataRatio, boolean tempTargetSet, boolean microBolusAllowed, + boolean uamAllowed, boolean advancedFiltering ) throws JSONException { @@ -247,7 +248,7 @@ public class DetermineBasalAdapterSMBJS { // mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact)); //} mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap); - mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false)); + mProfile.put("enableUAM", uamAllowed); mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable); mProfile.put("enableSMB_with_COB", SP.getBoolean(R.string.key_enableSMB_with_COB, false)); mProfile.put("enableSMB_with_temptarget", SP.getBoolean(R.string.key_enableSMB_with_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 d42ca9e89f..1d6b558c74 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 @@ -198,6 +198,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { MainApp.getConstraintChecker().isAdvancedFilteringEnabled(advancedFiltering); inputConstraints.copyReasons(advancedFiltering); + Constraint uam = new Constraint<>(true); + MainApp.getConstraintChecker().isUAMEnabled(uam); + inputConstraints.copyReasons(uam); + if (L.isEnabled(L.APS)) Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart); if (L.isEnabled(L.APS)) @@ -209,6 +213,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { lastAutosensResult.ratio, //autosensDataRatio isTempTarget, smbAllowed.value(), + uam.value(), advancedFiltering.value() ); } catch (JSONException e) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9feaff5e6c..7846abd514 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1007,6 +1007,8 @@ Closed loop mode disabled in preferences Autosens disabled in preferences SMB disabled in preferences + UAM disabled in preferences + UAM disabled because it rely on Oref1 sensitivity plugin Limiting max basal rate to %1$.2f U/h because of %2$s pump limit openapsma_max_basal