safety run if SMB fails
This commit is contained in:
parent
4217e82e0a
commit
a6a4a8837d
9 changed files with 45 additions and 32 deletions
|
@ -11,5 +11,5 @@ public interface APSInterface {
|
|||
public APSResult getLastAPSResult();
|
||||
public Date getLastAPSRun();
|
||||
|
||||
public void invoke(String initiator);
|
||||
public void invoke(String initiator, boolean safety);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.app.TaskStackBuilder;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
|
@ -253,7 +254,11 @@ public class LoopPlugin extends PluginBase {
|
|||
return isDisconnected;
|
||||
}
|
||||
|
||||
public void invoke(String initiator, boolean allowNotification) {
|
||||
public void invoke(String initiator, boolean allowNotification){
|
||||
invoke(initiator, allowNotification, false);
|
||||
}
|
||||
|
||||
public void invoke(String initiator, boolean allowNotification, boolean safety) {
|
||||
try {
|
||||
if (Config.logFunctionCalls)
|
||||
log.debug("invoke from " + initiator);
|
||||
|
@ -284,7 +289,7 @@ public class LoopPlugin extends PluginBase {
|
|||
|
||||
APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS();
|
||||
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginType.APS)) {
|
||||
usedAPS.invoke(initiator);
|
||||
usedAPS.invoke(initiator, safety);
|
||||
result = usedAPS.getLastAPSResult();
|
||||
}
|
||||
|
||||
|
@ -348,16 +353,24 @@ public class LoopPlugin extends PluginBase {
|
|||
if (result.enacted || result.success) {
|
||||
lastRun.tbrSetByPump = result;
|
||||
lastRun.lastEnact = lastRun.lastAPSRun;
|
||||
|
||||
MainApp.getConfigBuilder().applySMBRequest(resultAfterConstraints, new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
//Callback is only called if a bolus was acutally requested
|
||||
if (result.enacted || result.success) {
|
||||
lastRun.smbSetByPump = result;
|
||||
lastRun.lastEnact = lastRun.lastAPSRun;
|
||||
} else {
|
||||
new Thread(() -> {
|
||||
SystemClock.sleep(1000);
|
||||
LoopPlugin.getPlugin().invoke("safety", allowNotification, true);
|
||||
}).start();
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("Loop_Run_Safety"));
|
||||
}
|
||||
MainApp.bus().post(new EventLoopUpdateGui());
|
||||
}
|
||||
});
|
||||
MainApp.getConfigBuilder().applySMBRequest(resultAfterConstraints, new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (result.enacted || result.success) {
|
||||
lastRun.smbSetByPump = result;
|
||||
lastRun.lastEnact = lastRun.lastAPSRun;
|
||||
}
|
||||
MainApp.bus().post(new EventLoopUpdateGui());
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
|||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.openapsma_run:
|
||||
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button");
|
||||
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button", false);
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("OpenAPS_AMA_Run"));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -88,8 +88,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String initiator) {
|
||||
log.debug("invoke from " + initiator);
|
||||
public void invoke(String initiator, boolean safety) {
|
||||
log.debug("invoke from " + initiator + " safety: " + safety);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
|
||||
try {
|
||||
|
|
|
@ -66,7 +66,7 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
|
|||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.openapsma_run:
|
||||
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button");
|
||||
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button", false);
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("OpenAPS_MA_Run"));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -88,8 +88,8 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String initiator) {
|
||||
log.debug("invoke from " + initiator);
|
||||
public void invoke(String initiator, boolean safety) {
|
||||
log.debug("invoke from " + initiator + " safety: " + safety);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = null;
|
||||
try {
|
||||
|
|
|
@ -214,7 +214,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
double autosensDataRatio,
|
||||
boolean tempTargetSet,
|
||||
boolean microBolusAllowed,
|
||||
boolean smbAlwaysAllowed
|
||||
boolean advancedFiltering
|
||||
) throws JSONException {
|
||||
|
||||
String units = profile.getUnits();
|
||||
|
@ -250,13 +250,13 @@ 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", SP.getBoolean(R.string.key_use_uam, false)&& advancedFiltering);
|
||||
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));
|
||||
mProfile.put("allowSMB_with_high_temptarget", SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
|
||||
mProfile.put("enableSMB_always", SP.getBoolean(R.string.key_enableSMB_always, false) && smbAlwaysAllowed);
|
||||
mProfile.put("enableSMB_after_carbs", SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && smbAlwaysAllowed);
|
||||
mProfile.put("enableSMB_always", SP.getBoolean(R.string.key_enableSMB_always, false) && advancedFiltering);
|
||||
mProfile.put("enableSMB_after_carbs", SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && advancedFiltering);
|
||||
mProfile.put("maxSMBBasalMinutes", SP.getInt("key_smbmaxminutes", SMBDefaults.maxSMBBasalMinutes));
|
||||
mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold);
|
||||
|
||||
|
@ -315,7 +315,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
mAutosensData.put("ratio", 1.0);
|
||||
}
|
||||
mMicrobolusAllowed = microBolusAllowed;
|
||||
mSMBAlwaysAllowed = smbAlwaysAllowed;
|
||||
mSMBAlwaysAllowed = advancedFiltering;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
|
|||
|
||||
@OnClick(R.id.openapsma_run)
|
||||
public void onRunClick() {
|
||||
OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button");
|
||||
OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button", false);
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("OpenAPS_SMB_Run"));
|
||||
}
|
||||
|
||||
|
|
|
@ -91,8 +91,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String initiator) {
|
||||
log.debug("invoke from " + initiator);
|
||||
public void invoke(String initiator, boolean safety) {
|
||||
log.debug("invoke from " + initiator + " safety: " + safety);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = null;
|
||||
try {
|
||||
|
@ -184,13 +184,13 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
lastAutosensResult = new AutosensResult();
|
||||
}
|
||||
|
||||
Constraint<Boolean> smbAllowed = new Constraint<>(true);
|
||||
Constraint<Boolean> smbAllowed = new Constraint<>(!safety);
|
||||
MainApp.getConstraintChecker().isSMBModeEnabled(smbAllowed);
|
||||
inputConstraints.copyReasons(smbAllowed);
|
||||
|
||||
Constraint<Boolean> smbAlwaysEnabled = new Constraint<>(true);
|
||||
MainApp.getConstraintChecker().isAdvancedFilteringEnabled(smbAlwaysEnabled);
|
||||
inputConstraints.copyReasons(smbAlwaysEnabled);
|
||||
Constraint<Boolean> advancedFiltering = new Constraint<>(!safety);
|
||||
MainApp.getConstraintChecker().isAdvancedFilteringEnabled(advancedFiltering);
|
||||
inputConstraints.copyReasons(advancedFiltering);
|
||||
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
Profiler.log(log, "SMB data gathering", start);
|
||||
|
@ -201,7 +201,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
lastAutosensResult.ratio, //autosensDataRatio
|
||||
isTempTarget,
|
||||
smbAllowed.value(),
|
||||
smbAlwaysEnabled.value()
|
||||
advancedFiltering.value()
|
||||
);
|
||||
} catch (JSONException e) {
|
||||
log.error(e.getMessage());
|
||||
|
|
Loading…
Reference in a new issue