diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
index 9e72063911..14465ccdc9 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
@@ -366,7 +366,7 @@ public class DataService extends IntentService {
String activeProfile = bundles.getString("activeprofile");
String profile = bundles.getString("profile");
ProfileStore profileStore = new ProfileStore(new JSONObject(profile));
- NSProfilePlugin.storeNewProfile(profileStore);
+ NSProfilePlugin.getPlugin().storeNewProfile(profileStore);
MainApp.bus().post(new EventNSProfileUpdateGUI());
// if there are no profile switches this should lead to profile update
if (MainApp.getConfigBuilder().getProfileSwitchesFromHistory().size() == 0)
diff --git a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java
index 3f4c2fc563..9aa09244aa 100644
--- a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java
+++ b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java
@@ -22,8 +22,8 @@ public class PumpEnactResult {
// Result of basal change
public Integer duration = -1; // duration set [minutes]
- public Double absolute = -1d; // absolute rate [U/h] , isPercent = false
- public Integer percent = -1; // percent of current basal [%] (100% = current basal), isPercent = true
+ public double absolute = -1d; // absolute rate [U/h] , isPercent = false
+ public int percent = -1; // percent of current basal [%] (100% = current basal), isPercent = true
public boolean isPercent = false; // if true percent is used, otherwise absolute
public boolean isTempCancel = false; // if true we are caceling temp basal
// Result of treatment delivery
@@ -47,17 +47,17 @@ public class PumpEnactResult {
return this;
}
- public PumpEnactResult duration(Integer duration) {
+ public PumpEnactResult duration(int duration) {
this.duration = duration;
return this;
}
- public PumpEnactResult absolute(Double absolute) {
+ public PumpEnactResult absolute(double absolute) {
this.absolute = absolute;
return this;
}
- public PumpEnactResult percent(Integer percent) {
+ public PumpEnactResult percent(int percent) {
this.percent = percent;
return this;
}
@@ -72,12 +72,12 @@ public class PumpEnactResult {
return this;
}
- public PumpEnactResult bolusDelivered(Double bolusDelivered) {
+ public PumpEnactResult bolusDelivered(double bolusDelivered) {
this.bolusDelivered = bolusDelivered;
return this;
}
- public PumpEnactResult carbsDelivered(Double carbsDelivered) {
+ public PumpEnactResult carbsDelivered(double carbsDelivered) {
this.carbsDelivered = carbsDelivered;
return this;
}
@@ -94,7 +94,11 @@ public class PumpEnactResult {
public String toString() {
String ret = MainApp.sResources.getString(R.string.success) + ": " + success;
if (enacted) {
- if (isTempCancel) {
+ if (bolusDelivered > 0) {
+ ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
+ ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
+ ret += "\n" + MainApp.sResources.getString(R.string.smb_shortname) + ": " + bolusDelivered + "U";
+ } else if (isTempCancel) {
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment + "\n" +
MainApp.sResources.getString(R.string.canceltemp);
@@ -120,7 +124,11 @@ public class PumpEnactResult {
if (queued) {
ret = MainApp.sResources.getString(R.string.waitingforpumpresult);
} else if (enacted) {
- if (isTempCancel) {
+ if (bolusDelivered > 0) {
+ ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
+ ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
+ ret += "
" + MainApp.sResources.getString(R.string.smb_shortname) + ": " + bolusDelivered + "U";
+ } else if (isTempCancel) {
ret += "
" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "
" + MainApp.sResources.getString(R.string.comment) + ": " + comment +
"
" + MainApp.sResources.getString(R.string.canceltemp);
@@ -147,15 +155,17 @@ public class PumpEnactResult {
public PumpEnactResult() {
}
- public JSONObject json() {
+ public JSONObject json(Profile profile) {
JSONObject result = new JSONObject();
try {
- if (isTempCancel) {
+ if (bolusDelivered > 0) {
+ result.put("smb", bolusDelivered);
+ } else if (isTempCancel) {
result.put("rate", 0);
result.put("duration", 0);
} else if (isPercent) {
// Nightscout is expecting absolute value
- Double abs = Round.roundTo(MainApp.getConfigBuilder().getProfile().getBasal() * percent / 100, 0.01);
+ Double abs = Round.roundTo(profile.getBasal() * percent / 100, 0.01);
result.put("rate", abs);
result.put("duration", duration);
} else {
diff --git a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java
index 806f65704a..9679a5e63d 100644
--- a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java
+++ b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java
@@ -262,13 +262,13 @@ public class TemporaryBasal implements Interval {
return (remainingMin < 0) ? 0 : Math.round(remainingMin);
}
- public double tempBasalConvertedToAbsolute(long time) {
+ public double tempBasalConvertedToAbsolute(long time, Profile profile) {
if(isFakeExtended){
- return MainApp.getConfigBuilder().getProfile(time).getBasal(time) + netExtendedRate;
+ return profile.getBasal(time) + netExtendedRate;
} else if (isAbsolute) {
return absoluteRate;
} else {
- return MainApp.getConfigBuilder().getProfile(time).getBasal(time) * percentRate / 100;
+ return profile.getBasal(time) * percentRate / 100;
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java
index 0114b8a48d..f7be6883e9 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java
@@ -3,6 +3,7 @@ package info.nightscout.androidaps.interfaces;
import java.util.Date;
import info.nightscout.androidaps.data.Iob;
+import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Treatment;
/**
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
index 4358e884ae..45666cf4ae 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java
@@ -44,7 +44,7 @@ public interface PumpInterface {
PumpEnactResult cancelExtendedBolus();
// Status to be passed to NS
- JSONObject getJSONStatus();
+ JSONObject getJSONStatus(Profile profile, String profileName);
String deviceID();
// Pump capabilities
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java
index 134b419240..129e54b50b 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java
@@ -41,8 +41,6 @@ public interface TreatmentsInterface {
// basal that can be faked by extended boluses
boolean isTempBasalInProgress();
TemporaryBasal getTempBasalFromHistory(long time);
- double getTempBasalAbsoluteRateHistory();
- double getTempBasalRemainingMinutesFromHistory();
Intervals getTemporaryBasalsFromHistory();
boolean isInHistoryExtendedBoluslInProgress();
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 92b6fabe8f..0917c8b639 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
@@ -354,10 +354,12 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
/**
* expect absolute request and allow both absolute and percent response based on pump capabilities
*/
- public void applyAPSRequest(APSResult request, Callback callback) {
+ public void applyTBRRequest(APSResult request, Profile profile, Callback callback) {
PumpInterface pump = getActivePump();
request.rate = applyBasalConstraints(request.rate);
+ long now = System.currentTimeMillis();
+
if (!pump.isInitialized()) {
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
if (callback != null) {
@@ -378,8 +380,9 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
log.debug("applyAPSRequest: " + request.toString());
if (request.tempBasalReqested) {
+ TemporaryBasal activeTemp = getTempBasalFromHistory(now);
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) {
- if (isTempBasalInProgress()) {
+ if (activeTemp != null) {
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: cancelTempBasal()");
getCommandQueue().cancelTempBasal(false, callback);
@@ -390,13 +393,13 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run();
}
}
- } else if (isTempBasalInProgress()
- && getTempBasalRemainingMinutesFromHistory() > 5
- && Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < pump.getPumpDescription().basalStep) {
+ } else if (activeTemp != null
+ && activeTemp.getPlannedRemainingMinutes() > 5
+ && Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) {
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: Temp basal set correctly");
if (callback != null) {
- callback.result(new PumpEnactResult().absolute(getTempBasalAbsoluteRateHistory()).duration(getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run();
+ callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile)).duration(activeTemp.getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run();
}
} else {
if (Config.logCongigBuilderActions)
@@ -404,6 +407,29 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback);
}
}
+ }
+
+ public void applySMBRequest(APSResult request, Callback callback) {
+ PumpInterface pump = getActivePump();
+
+ if (!pump.isInitialized()) {
+ log.debug("applySMBRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
+ if (callback != null) {
+ callback.result(new PumpEnactResult().comment(MainApp.sResources.getString(R.string.pumpNotInitialized)).enacted(false).success(false)).run();
+ }
+ return;
+ }
+
+ if (pump.isSuspended()) {
+ log.debug("applySMBRequest: " + MainApp.sResources.getString(R.string.pumpsuspended));
+ if (callback != null) {
+ callback.result(new PumpEnactResult().comment(MainApp.sResources.getString(R.string.pumpsuspended)).enacted(false).success(false)).run();
+ }
+ return;
+ }
+
+ if (Config.logCongigBuilderActions)
+ log.debug("applySMBRequest: " + request.toString());
if (request.bolusRequested) {
long lastBolusTime = getLastBolusTime();
@@ -622,16 +648,6 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
return activeTreatments != null ? activeTreatments.getTempBasalFromHistory(time) : null;
}
- @Override
- public double getTempBasalAbsoluteRateHistory() {
- return activeTreatments.getTempBasalAbsoluteRateHistory();
- }
-
- @Override
- public double getTempBasalRemainingMinutesFromHistory() {
- return activeTreatments.getTempBasalRemainingMinutesFromHistory();
- }
-
@Override
public Intervals getTemporaryBasalsFromHistory() {
return activeTreatments.getTemporaryBasalsFromHistory();
@@ -767,6 +783,14 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
return "Default";
}
+ public boolean isProfileValid(String from) {
+ return getProfile() != null && getProfile().isValid(from) &&
+ activeProfile != null &&
+ activeProfile.getProfile() != null &&
+ activeProfile.getProfile().getDefaultProfile() != null &&
+ activeProfile.getProfile().getDefaultProfile().isValid(from);
+ }
+
@Nullable
public Profile getProfile() {
return getProfile(System.currentTimeMillis());
@@ -779,8 +803,10 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
@Nullable
public Profile getProfile(long time) {
- if (activeTreatments == null)
+ if (activeTreatments == null) {
+ log.debug("getProfile activeTreatments == null: returning null");
return null; //app not initialized
+ }
//log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time));
boolean ignoreProfileSwitchEvents = SP.getBoolean(R.string.key_do_not_track_profile_switch, false);
if (!ignoreProfileSwitchEvents) {
@@ -796,8 +822,10 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
}
}
// Unable to determine profile, failover to default
- if (activeProfile.getProfile() == null)
+ if (activeProfile.getProfile() == null) {
+ log.debug("getProfile activeProfile.getProfile() == null: returning null (activeProfile=" + activeProfile.getClass().getSimpleName() + ")");
return null; //app not initialized
+ }
Profile defaultProfile = activeProfile.getProfile().getDefaultProfile();
if (defaultProfile != null)
return defaultProfile;
@@ -815,6 +843,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
+ log.debug("getProfile at the end: returning null");
return null;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java
index 4155a9be56..d336786f49 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java
@@ -4,6 +4,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
+import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java
index 83f71c2430..c60991253c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java
@@ -389,11 +389,12 @@ public class IobCobCalculatorPlugin implements PluginBase {
BasalData retval = basalDataTable.get(time);
if (retval == null) {
retval = new BasalData();
+ Profile profile = MainApp.getConfigBuilder().getProfile(time);
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time);
- retval.basal = MainApp.getConfigBuilder().getProfile(time).getBasal(time);
+ retval.basal = profile.getBasal(time);
if (tb != null) {
retval.isTempBasalRunning = true;
- retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time);
+ retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time, profile);
} else {
retval.isTempBasalRunning = false;
retval.tempBasalAbsolute = retval.basal;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java
index e2e97715f7..c492aae400 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java
@@ -59,7 +59,7 @@ public class IobCobThread extends Thread {
log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from);
return; // app still initializing
}
- if (MainApp.getConfigBuilder().getProfile() == null) {
+ if (!MainApp.getConfigBuilder().isProfileValid("IobCobThread")) {
log.debug("Aborting calculation thread (No profile): " + from);
return; // app still initializing
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java
index 55038520a4..c9b60ab3d6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java
@@ -15,6 +15,9 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
@@ -22,16 +25,25 @@ import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
import info.nightscout.utils.FabricPrivacy;
-public class LoopFragment extends SubscriberFragment implements View.OnClickListener {
+public class LoopFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(LoopFragment.class);
+ @BindView(R.id.loop_run)
Button runNowButton;
+ @BindView(R.id.loop_lastrun)
TextView lastRunView;
+ @BindView(R.id.loop_lastenact)
TextView lastEnactView;
+ @BindView(R.id.loop_source)
TextView sourceView;
+ @BindView(R.id.loop_request)
TextView requestView;
+ @BindView(R.id.loop_constraintsprocessed)
TextView constraintsProcessedView;
- TextView setByPumpView;
+ @BindView(R.id.loop_tbrsetbypump)
+ TextView tbrSetByPumpView;
+ @BindView(R.id.loop_smbsetbypump)
+ TextView smbSetByPumpView;
@Override
@@ -39,41 +51,19 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.loop_fragment, container, false);
-
- lastRunView = (TextView) view.findViewById(R.id.loop_lastrun);
- lastEnactView = (TextView) view.findViewById(R.id.loop_lastenact);
- sourceView = (TextView) view.findViewById(R.id.loop_source);
- requestView = (TextView) view.findViewById(R.id.loop_request);
- constraintsProcessedView = (TextView) view.findViewById(R.id.loop_constraintsprocessed);
- setByPumpView = (TextView) view.findViewById(R.id.loop_setbypump);
- runNowButton = (Button) view.findViewById(R.id.loop_run);
- runNowButton.setOnClickListener(this);
-
- updateGUI();
+ unbinder = ButterKnife.bind(this, view);
return view;
} catch (Exception e) {
FabricPrivacy.logException(e);
}
-
return null;
}
- @Override
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.loop_run:
- lastRunView.setText(MainApp.sResources.getString(R.string.executing));
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- LoopPlugin.getPlugin().invoke("Loop button", true);
- }
- });
- thread.start();
- FabricPrivacy.getInstance().logCustom(new CustomEvent("Loop_Run"));
- break;
- }
-
+ @OnClick(R.id.loop_run)
+ void onRunClick() {
+ lastRunView.setText(MainApp.sResources.getString(R.string.executing));
+ new Thread(() -> LoopPlugin.getPlugin().invoke("Loop button", true)).start();
+ FabricPrivacy.getInstance().logCustom(new CustomEvent("Loop_Run"));
}
@Subscribe
@@ -86,12 +76,7 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
clearGUI();
final Activity activity = getActivity();
if (activity != null)
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- lastRunView.setText(ev.text);
- }
- });
+ activity.runOnUiThread(() -> lastRunView.setText(ev.text));
}
@@ -99,17 +84,15 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- if (LoopPlugin.lastRun != null) {
- requestView.setText(LoopPlugin.lastRun.request != null ? LoopPlugin.lastRun.request.toSpanned() : "");
- constraintsProcessedView.setText(LoopPlugin.lastRun.constraintsProcessed != null ? LoopPlugin.lastRun.constraintsProcessed.toSpanned() : "");
- setByPumpView.setText(LoopPlugin.lastRun.setByPump != null ? LoopPlugin.lastRun.setByPump.toSpanned() : "");
- sourceView.setText(LoopPlugin.lastRun.source != null ? LoopPlugin.lastRun.source : "");
- lastRunView.setText(LoopPlugin.lastRun.lastAPSRun != null && LoopPlugin.lastRun.lastAPSRun.getTime() != 0 ? LoopPlugin.lastRun.lastAPSRun.toLocaleString() : "");
- lastEnactView.setText(LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.toLocaleString() : "");
- }
+ activity.runOnUiThread(() -> {
+ if (LoopPlugin.lastRun != null) {
+ requestView.setText(LoopPlugin.lastRun.request != null ? LoopPlugin.lastRun.request.toSpanned() : "");
+ constraintsProcessedView.setText(LoopPlugin.lastRun.constraintsProcessed != null ? LoopPlugin.lastRun.constraintsProcessed.toSpanned() : "");
+ sourceView.setText(LoopPlugin.lastRun.source != null ? LoopPlugin.lastRun.source : "");
+ lastRunView.setText(LoopPlugin.lastRun.lastAPSRun != null && LoopPlugin.lastRun.lastAPSRun.getTime() != 0 ? LoopPlugin.lastRun.lastAPSRun.toLocaleString() : "");
+ lastEnactView.setText(LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.toLocaleString() : "");
+ tbrSetByPumpView.setText(LoopPlugin.lastRun.tbrSetByPump != null ? LoopPlugin.lastRun.tbrSetByPump.toSpanned() : "");
+ smbSetByPumpView.setText(LoopPlugin.lastRun.smbSetByPump != null ? LoopPlugin.lastRun.smbSetByPump.toSpanned() : "");
}
});
}
@@ -117,16 +100,14 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
void clearGUI() {
Activity activity = getActivity();
if (activity != null)
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- requestView.setText("");
- constraintsProcessedView.setText("");
- setByPumpView.setText("");
- sourceView.setText("");
- lastRunView.setText("");
- lastEnactView.setText("");
- }
+ activity.runOnUiThread(() -> {
+ requestView.setText("");
+ constraintsProcessedView.setText("");
+ sourceView.setText("");
+ lastRunView.setText("");
+ lastEnactView.setText("");
+ tbrSetByPumpView.setText("");
+ smbSetByPumpView.setText("");
});
}
}
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 2fff17a9e7..12db67534b 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
@@ -21,6 +21,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange;
@@ -30,7 +31,6 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
-import info.nightscout.androidaps.plugins.Loop.events.EventLoopResult;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
@@ -65,7 +65,8 @@ public class LoopPlugin implements PluginBase {
public class LastRun {
public APSResult request = null;
public APSResult constraintsProcessed = null;
- public PumpEnactResult setByPump = null;
+ public PumpEnactResult tbrSetByPump = null;
+ public PumpEnactResult smbSetByPump = null;
public String source = null;
public Date lastAPSRun = null;
public Date lastEnact = null;
@@ -266,7 +267,9 @@ public class LoopPlugin implements PluginBase {
if (!isEnabled(PluginBase.LOOP))
return;
- if (MainApp.getConfigBuilder().getProfile() == null) {
+ Profile profile = MainApp.getConfigBuilder().getProfile();
+
+ if (!MainApp.getConfigBuilder().isProfileValid("Loop")) {
log.debug(MainApp.sResources.getString(R.string.noprofileselected));
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected)));
return;
@@ -304,7 +307,8 @@ public class LoopPlugin implements PluginBase {
lastRun.constraintsProcessed = resultAfterConstraints;
lastRun.lastAPSRun = new Date();
lastRun.source = ((PluginBase) usedAPS).getName();
- lastRun.setByPump = null;
+ lastRun.tbrSetByPump = null;
+ lastRun.smbSetByPump = null;
NSUpload.uploadDeviceStatus();
@@ -320,31 +324,36 @@ public class LoopPlugin implements PluginBase {
return;
}
- MainApp.bus().post(new EventLoopResult(resultAfterConstraints));
-
if (constraintsInterface.isClosedModeEnabled()) {
if (result.isChangeRequested()) {
final PumpEnactResult waiting = new PumpEnactResult();
- final PumpEnactResult previousResult = lastRun.setByPump;
waiting.queued = true;
- lastRun.setByPump = waiting;
+ lastRun.tbrSetByPump = waiting;
MainApp.bus().post(new EventLoopUpdateGui());
- MainApp.getConfigBuilder().applyAPSRequest(resultAfterConstraints, new Callback() {
+ FabricPrivacy.getInstance().logCustom(new CustomEvent("APSRequest"));
+ MainApp.getConfigBuilder().applyTBRRequest(resultAfterConstraints, profile, new Callback() {
@Override
public void run() {
- FabricPrivacy.getInstance().logCustom(new CustomEvent("APSRequest"));
if (result.enacted || result.success) {
- lastRun.setByPump = result;
+ lastRun.tbrSetByPump = result;
+ lastRun.lastEnact = lastRun.lastAPSRun;
+ }
+ 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;
- } else {
- lastRun.setByPump = previousResult;
}
MainApp.bus().post(new EventLoopUpdateGui());
}
});
} else {
- lastRun.setByPump = null;
- lastRun.source = null;
+ lastRun.tbrSetByPump = null;
+ lastRun.smbSetByPump = null;
}
} else {
if (result.isChangeRequested() && allowNotification) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopResult.java
deleted file mode 100644
index 5cbb24ea22..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopResult.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package info.nightscout.androidaps.plugins.Loop.events;
-
-import info.nightscout.androidaps.plugins.Loop.APSResult;
-
-public class EventLoopResult {
- public final APSResult apsResult;
-
- public EventLoopResult(APSResult apsResult) {
- this.apsResult = apsResult;
- }
-}
-
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
index 7f6df8466d..5372f66b03 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java
@@ -217,12 +217,14 @@ public class DetermineBasalAdapterAMAJS {
if (units.equals(Constants.MMOL)) {
mProfile.put("out_units", "mmol/L");
}
-
+
+ long now = System.currentTimeMillis();
+ TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
mCurrentTemp = new JSONObject();
mCurrentTemp.put("temp", "absolute");
- mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
- mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
+ mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
+ mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
// as we have non default temps longer than 30 mintues
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
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 40dbf711ad..6ac207ab80 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
@@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget;
+import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
@@ -248,11 +249,13 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
determineBasalResultAMA.tempBasalReqested = false;
// limit requests on openloop mode
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
- if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) {
+ long now = System.currentTimeMillis();
+ TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
+ if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) {
// going to cancel
- } else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) {
+ } else if (activeTemp != null && Math.abs(determineBasalResultAMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) {
determineBasalResultAMA.tempBasalReqested = false;
- } else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
+ } else if (activeTemp == null && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
determineBasalResultAMA.tempBasalReqested = false;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
index 723b224f90..e7bd0c86fd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java
@@ -23,6 +23,7 @@ import info.nightscout.androidaps.data.GlucoseStatus;
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.plugins.Loop.ScriptReader;
import info.nightscout.utils.SP;
@@ -179,9 +180,12 @@ public class DetermineBasalAdapterMAJS {
mProfile.put("out_units", "mmol/L");
}
+ long now = System.currentTimeMillis();
+ TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
+
mCurrentTemp = new JSONObject();
- mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
- mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
+ mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
+ mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
mIobData = new JSONObject();
mIobData.put("iob", iobData.iob); //netIob
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 0b49f7a1e4..7f8b56f021 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
@@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget;
+import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
@@ -173,8 +174,6 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
String units = profile.getUnits();
- Date now = new Date();
-
double maxIob = SP.getDouble("openapsma_max_iob", 1.5d);
double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
double minBg = Profile.toMgdl(profile.getTargetLow(), units);
@@ -231,17 +230,20 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
Profiler.log(log, "MA calculation", start);
+ long now = System.currentTimeMillis();
+
DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke();
// Fix bug determinef basal
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultMA.tempBasalReqested = false;
// limit requests on openloop mode
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
- if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) {
+ TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
+ if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) {
// going to cancel
- } else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) {
+ } else if (activeTemp != null && Math.abs(determineBasalResultMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) {
determineBasalResultMA.tempBasalReqested = false;
- } else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
+ } else if (activeTemp == null && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
determineBasalResultMA.tempBasalReqested = false;
}
@@ -255,7 +257,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
lastAPSResult = determineBasalResultMA;
- lastAPSRun = now;
+ lastAPSRun = new Date(now);
MainApp.bus().post(new EventOpenAPSUpdateGui());
}
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 41fea12940..64f8a155fd 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
@@ -246,11 +246,12 @@ 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);
- mProfile.put("enableSMB_with_COB", SP.getBoolean(R.string.key_use_smb, false) && SP.getBoolean(R.string.key_enableSMB_with_COB, false));
- mProfile.put("enableSMB_with_temptarget", SP.getBoolean(R.string.key_use_smb, false) && SP.getBoolean(R.string.key_enableSMB_with_temptarget, false));
- mProfile.put("allowSMB_with_high_temptarget", SP.getBoolean(R.string.key_use_smb, false) && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
- mProfile.put("enableSMB_always", SP.getBoolean(R.string.key_use_smb, false) && SP.getBoolean(R.string.key_enableSMB_always, false) && ConfigBuilderPlugin.getActiveBgSource().advancedFilteringSupported());
- mProfile.put("enableSMB_after_carbs", SP.getBoolean(R.string.key_use_smb, false) && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && ConfigBuilderPlugin.getActiveBgSource().advancedFilteringSupported());
+ boolean SMBEnabled = SP.getBoolean(R.string.key_use_smb, false) && MainApp.getConfigBuilder().isClosedModeEnabled();
+ 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));
+ mProfile.put("enableSMB_always", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_always, false) && ConfigBuilderPlugin.getActiveBgSource().advancedFilteringSupported());
+ mProfile.put("enableSMB_after_carbs", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_after_carbs, false) && ConfigBuilderPlugin.getActiveBgSource().advancedFilteringSupported());
mProfile.put("maxSMBBasalMinutes", SP.getInt("key_smbmaxminutes", SMBDefaults.maxSMBBasalMinutes));
mProfile.put("carbsReqThreshold", SMBDefaults.carbsReqThreshold);
@@ -263,10 +264,13 @@ public class DetermineBasalAdapterSMBJS {
}
+ long now = System.currentTimeMillis();
+ TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
+
mCurrentTemp = new JSONObject();
mCurrentTemp.put("temp", "absolute");
- mCurrentTemp.put("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory());
- mCurrentTemp.put("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory());
+ mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
+ mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
// as we have non default temps longer than 30 mintues
TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
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 2fbb7777d1..91aa4ef515 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
@@ -15,6 +15,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget;
+import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
@@ -243,6 +244,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
return;
}
+ long now = System.currentTimeMillis();
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
Profiler.log(log, "SMB calculation", start);
@@ -252,17 +254,16 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
determineBasalResultSMB.tempBasalReqested = false;
// limit requests on openloop mode
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
- if (MainApp.getConfigBuilder().isTempBasalInProgress() && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) {
+ TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
+ if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) {
// going to cancel
- } else if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1) {
+ } else if (activeTemp != null && Math.abs(determineBasalResultSMB.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) {
determineBasalResultSMB.tempBasalReqested = false;
- } else if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - pump.getBaseBasalRate()) < 0.1) {
+ } else if (activeTemp == null && Math.abs(determineBasalResultSMB.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
determineBasalResultSMB.tempBasalReqested = false;
- }
}
determineBasalResultSMB.iob = iobArray[0];
- Date now = new Date();
try {
determineBasalResultSMB.json.put("timestamp", DateUtil.toISOString(now));
@@ -272,7 +273,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS;
lastAPSResult = determineBasalResultSMB;
- lastAPSRun = now;
+ lastAPSRun = new Date(now);
MainApp.bus().post(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultAMA.json;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
index 29d23050de..ac03ff2e9e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
@@ -404,6 +404,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
if (profile == null) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
+ dismiss();
return;
}
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 ab56e2fbb2..2b59aad3ce 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
@@ -627,7 +627,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
private void onClickAcceptTemp() {
- if (ConfigBuilderPlugin.getActiveLoop() != null) {
+ Profile profile = MainApp.getConfigBuilder().getProfile();
+
+ if (ConfigBuilderPlugin.getActiveLoop() != null && profile != null) {
ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false);
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.isChangeRequested()) {
@@ -638,11 +640,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public void onClick(DialogInterface dialog, int id) {
hideTempRecommendation();
clearNotification();
- MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed, new Callback() {
+ MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() {
@Override
public void run() {
if (result.enacted) {
- finalLastRun.setByPump = result;
+ finalLastRun.tbrSetByPump = result;
finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus();
@@ -670,7 +672,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory();
final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
- if (quickWizardEntry != null && actualBg != null) {
+ if (quickWizardEntry != null && actualBg != null && profile != null) {
quickWizardButton.setVisibility(View.VISIBLE);
final BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, actualBg, true);
@@ -946,7 +948,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (timeView != null) { //must not exists
timeView.setText(DateUtil.timeString(new Date()));
}
- if (MainApp.getConfigBuilder().getProfile() == null) {// app not initialized yet
+ if (!MainApp.getConfigBuilder().isProfileValid("Overview")) {// app not initialized yet
pumpStatusView.setText(R.string.noprofileset);
pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE);
@@ -962,16 +964,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
- Profile profile = MainApp.getConfigBuilder().getProfile();
- String units = profile.getUnits();
-
- if (units == null) {
+ final Profile profile = MainApp.getConfigBuilder().getProfile();
+ if (profile == null) {
pumpStatusView.setText(R.string.noprofileset);
pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE);
return;
}
+ final String units = profile.getUnits();
final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units);
final double highLine = OverviewPlugin.getPlugin().determineHighLine(units);
@@ -1090,12 +1091,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (activeTemp != null) {
basalText = "T: " + activeTemp.toStringVeryShort();
} else {
- basalText = DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h";
+ basalText = DecimalFormatter.to2Decimal(profile.getBasal()) + "U/h";
}
baseBasalView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- String fullText = MainApp.sResources.getString(R.string.pump_basebasalrate_label) + ": " + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h\n";
+ String fullText = MainApp.sResources.getString(R.string.pump_basebasalrate_label) + ": " + DecimalFormatter.to2Decimal(profile.getBasal()) + "U/h\n";
if (activeTemp != null) {
fullText += MainApp.sResources.getString(R.string.pump_tempbasal_label) + ": " + activeTemp.toStringFull();
}
@@ -1108,7 +1109,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
basalText = activeTemp.toStringFull() + " ";
}
if (Config.NSCLIENT || Config.G5UPLOADER)
- basalText += "(" + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h)";
+ basalText += "(" + DecimalFormatter.to2Decimal(profile.getBasal()) + " U/h)";
else if (pump.getPumpDescription().isTempBasalCapable) {
basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)";
}
@@ -1369,7 +1370,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
// add target line
- graphData.addTargetLine(fromTime, toTime);
+ graphData.addTargetLine(fromTime, toTime, profile);
// **** NOW line ****
graphData.addNowLine(now);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java
index b13ab19219..07c6e8bf96 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java
@@ -221,12 +221,7 @@ public class GraphData {
addSeries(absoluteBasalsLineSeries);
}
- public void addTargetLine(long fromTime, long toTime) {
- Profile profile = MainApp.getConfigBuilder().getProfile();
- if (profile == null) {
- return;
- }
-
+ public void addTargetLine(long fromTime, long toTime, Profile profile) {
LineGraphSeries targetsSeries;
Scale targetsScale = new Scale();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java
index 558d01b94d..26d5851865 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java
@@ -119,7 +119,7 @@ public class PersistentNotificationPlugin implements PluginBase {
String line1 = ctx.getString(R.string.noprofile);
- if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || MainApp.getConfigBuilder().getProfile() == null)
+ if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || !MainApp.getConfigBuilder().isProfileValid("Notificiation"))
return;
String units = MainApp.getConfigBuilder().getProfileUnits();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java
index d3fedfd9c8..4911187db4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java
@@ -46,7 +46,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
private boolean fragmentEnabled = true;
private boolean fragmentVisible = true;
- private static ProfileStore profile = null;
+ private ProfileStore profile = null;
private NSProfilePlugin() {
MainApp.bus().register(this);
@@ -116,24 +116,26 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
}
@Subscribe
- public static void storeNewProfile(ProfileStore newProfile) {
+ public void storeNewProfile(ProfileStore newProfile) {
profile = new ProfileStore(newProfile.getData());
storeNSProfile();
MainApp.bus().post(new EventNSProfileUpdateGUI());
- ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() {
- @Override
- public void run() {
- if (result.enacted) {
- SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
- if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
- smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
+ if (MainApp.getConfigBuilder().isProfileValid("storeNewProfile")) {
+ ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() {
+ @Override
+ public void run() {
+ if (result.enacted) {
+ SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
+ if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
+ smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
+ }
}
}
- }
- });
+ });
+ }
}
- private static void storeNSProfile() {
+ private void storeNSProfile() {
SP.putString("profile", profile.getData().toString());
if (Config.logPrefsChange)
log.debug("Storing profile");
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 fb04b0e105..758f872ffe 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
@@ -228,7 +228,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
}
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
- TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
+ long now = System.currentTimeMillis();
+ TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false;
result.success = true;
@@ -236,7 +237,6 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set");
@@ -251,7 +251,6 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK");
@@ -365,7 +364,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
}
@Override
- public JSONObject getJSONStatus() {
+ public JSONObject getJSONStatus(Profile profile, String profilename) {
+ long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
return null;
}
@@ -383,13 +383,13 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", pump.lastBolusAmount);
}
- TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
+ TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
if (tb != null) {
- extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
+ extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
- ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
+ ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
@@ -397,7 +397,7 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
}
extended.put("BaseBasalRate", getBaseBasalRate());
try {
- extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
+ extended.put("ActiveProfile", profilename);
} catch (Exception e) {
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
index 289e10c518..7be12e0cb5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
@@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
+import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
@@ -178,15 +179,19 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses;
+ long now = System.currentTimeMillis();
+ TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
+ ExtendedBolus activeExtended = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
+
if (doTempOff) {
// If extended in progress
- if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
+ if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
return cancelExtendedBolus();
}
// If temp in progress
- if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
+ if (activeTemp != null) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
return cancelRealTempBasal();
@@ -212,7 +217,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
// If extended in progress
- if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
+ if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
result = cancelExtendedBolus();
@@ -222,20 +227,18 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
}
}
// Check if some temp is already in progress
- if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
+ if (activeTemp != null) {
// Correct basal already set ?
- TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (Config.logPumpActions)
- log.debug("setTempBasalAbsolute: currently running: " + running.toString());
- if (running.percentRate == percentRate) {
+ log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
+ if (activeTemp.percentRate == percentRate) {
if (enforceNew) {
cancelTempBasal(true);
} else {
result.success = true;
result.percent = percentRate;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false;
- result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
+ result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true;
result.isTempCancel = false;
if (Config.logPumpActions)
@@ -251,7 +254,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
}
if (doExtendedTemp) {
// Check if some temp is already in progress
- if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
+ if (activeTemp != null) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
result = cancelRealTempBasal();
@@ -272,12 +275,12 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
// What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) {
- log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
+ log.debug("setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
}
// Compare with extended rate in progress
- if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
+ if (activeExtended != null && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set
result.success = true;
result.absolute = pump.extendedBolusAbsoluteRate;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java
index 9bdc0f8b59..d8157281bd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java
@@ -85,12 +85,6 @@ public class ProfileViewDialog extends DialogFragment {
}
private void setContent() {
-// if (profile == null) {
-// noProfile.setVisibility(View.VISIBLE);
-// return;
-// } else {
-// noProfile.setVisibility(View.GONE);
-// }
ProfileStore store = ((ProfileInterface)MainApp.getConfigBuilder().getActivePump()).getProfile();
if (store != null) {
noProfile.setVisibility(View.GONE);
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
index 81e8aad052..0a35d56a17 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
@@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
+import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
@@ -179,15 +180,19 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses;
+ long now = System.currentTimeMillis();
+ TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
+ ExtendedBolus activeExtended = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
+
if (doTempOff) {
// If extended in progress
- if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
+ if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
return cancelExtendedBolus();
}
// If temp in progress
- if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
+ if (activeTemp != null) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
return cancelRealTempBasal();
@@ -213,7 +218,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
// If extended in progress
- if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
+ if (activeExtended != null && useExtendedBoluses) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
result = cancelExtendedBolus();
@@ -223,20 +228,18 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
}
}
// Check if some temp is already in progress
- if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
+ if (activeTemp != null) {
// Correct basal already set ?
- TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (Config.logPumpActions)
- log.debug("setTempBasalAbsolute: currently running: " + running.toString());
- if (running.percentRate == percentRate) {
+ log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
+ if (activeTemp.percentRate == percentRate) {
if (enforceNew) {
cancelTempBasal(true);
} else {
result.success = true;
result.percent = percentRate;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false;
- result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
+ result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true;
result.isTempCancel = false;
if (Config.logPumpActions)
@@ -252,7 +255,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
}
if (doExtendedTemp) {
// Check if some temp is already in progress
- if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
+ if (activeTemp != null) {
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
result = cancelRealTempBasal();
@@ -273,12 +276,12 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
// What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) {
- log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
+ log.debug("setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
}
// Compare with extended rate in progress
- if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
+ if (activeExtended != null && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set
result.success = true;
result.absolute = pump.extendedBolusAbsoluteRate;
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 20e17af20e..437e528441 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
@@ -554,15 +554,17 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
if (percentRate > 500) // Special high temp 500/15min
percentRate = 500;
// Check if some temp is already in progress
- if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
+ TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
+ if (activeTemp != null) {
+ if (Config.logPumpActions)
+ log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString());
// Correct basal already set ?
- if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
+ if (activeTemp.percentRate == percentRate) {
if (!enforceNew) {
result.success = true;
result.percent = percentRate;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false;
- result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
+ result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true;
result.isTempCancel = false;
if (Config.logPumpActions)
@@ -606,7 +608,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
}
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
- TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
+ long now = System.currentTimeMillis();
+ TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false;
result.success = true;
@@ -614,7 +617,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set");
@@ -634,7 +636,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK");
@@ -760,7 +761,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
}
@Override
- public JSONObject getJSONStatus() {
+ public JSONObject getJSONStatus(Profile profile, String profileName) {
+ long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
return null;
}
@@ -778,13 +780,13 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", pump.lastBolusAmount);
}
- TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
+ TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (tb != null) {
- extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
+ extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
- ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
+ ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
@@ -800,7 +802,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
pumpjson.put("status", status);
pumpjson.put("extended", extended);
pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
- pumpjson.put("clock", DateUtil.toISOString(new Date()));
+ pumpjson.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
index 817df68855..c1a6bb54da 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
@@ -225,15 +225,15 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (percentRate > 500) // Special high temp 500/15min
percentRate = 500;
// Check if some temp is already in progress
- if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
+ TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
+ if (activeTemp != null) {
// Correct basal already set ?
- if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
+ if (activeTemp.percentRate == percentRate) {
if (!enforceNew) {
result.success = true;
result.percent = percentRate;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.enacted = false;
- result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutesFromHistory()).intValue();
+ result.duration = activeTemp.getPlannedRemainingMinutes();
result.isPercent = true;
result.isTempCancel = false;
if (Config.logPumpActions)
@@ -277,7 +277,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
}
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
- TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
+ long now = System.currentTimeMillis();
+ TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now);
if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false;
result.success = true;
@@ -285,7 +286,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set");
@@ -305,7 +305,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
- result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory();
result.isPercent = true;
if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK");
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 98785f2ff2..a7c7cb52f4 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
@@ -790,8 +790,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
}
@Override
- public JSONObject getJSONStatus() {
-
+ public JSONObject getJSONStatus(Profile profile, String profileName) {
+ long now = System.currentTimeMillis();
if (Helpers.msSince(connector.getLastContactTime()) > (60 * 60 * 1000)) {
log("getJSONStatus not returning as data likely stale");
return null;
@@ -810,26 +810,26 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
} catch (Exception e) {
}
- TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
+ TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (tb != null) {
- extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
+ extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
- ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
+ ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
}
extended.put("BaseBasalRate", getBaseBasalRate());
- status.put("timestamp", DateUtil.toISOString(new Date()));
+ status.put("timestamp", DateUtil.toISOString(now));
pump.put("battery", battery);
pump.put("status", status);
pump.put("extended", extended);
pump.put("reservoir", reservoirInUnits);
- pump.put("clock", DateUtil.toISOString(new Date()));
+ pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java
index 564d29d53b..0d726b5dcd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java
@@ -244,7 +244,8 @@ public class MDIPlugin implements PluginBase, PumpInterface {
}
@Override
- public JSONObject getJSONStatus() {
+ public JSONObject getJSONStatus(Profile profile, String profileName) {
+ long now = System.currentTimeMillis();
JSONObject pump = new JSONObject();
JSONObject status = new JSONObject();
JSONObject extended = new JSONObject();
@@ -252,14 +253,14 @@ public class MDIPlugin implements PluginBase, PumpInterface {
status.put("status", "normal");
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
try {
- extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
+ extended.put("ActiveProfile", profileName);
} catch (Exception e) {
}
- status.put("timestamp", DateUtil.toISOString(new Date()));
+ status.put("timestamp", DateUtil.toISOString(now));
pump.put("status", status);
pump.put("extended", extended);
- pump.put("clock", DateUtil.toISOString(new Date()));
+ pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) {
}
return pump;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java
index 2ceefcb4c3..46e90184fc 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java
@@ -409,7 +409,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
}
@Override
- public JSONObject getJSONStatus() {
+ public JSONObject getJSONStatus(Profile profile, String profileName) {
+ long now = System.currentTimeMillis();
if (!SP.getBoolean("virtualpump_uploadstatus", false)) {
return null;
}
@@ -422,28 +423,28 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
status.put("status", "normal");
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
try {
- extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
+ extended.put("ActiveProfile", profileName);
} catch (Exception e) {
}
- TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
+ TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (tb != null) {
- extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
+ extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
- ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
+ ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now);
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
}
- status.put("timestamp", DateUtil.toISOString(new Date()));
+ status.put("timestamp", DateUtil.toISOString(now));
pump.put("battery", battery);
pump.put("status", status);
pump.put("extended", extended);
pump.put("reservoir", reservoirInUnits);
- pump.put("clock", DateUtil.toISOString(new Date()));
+ pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java
index ebe8ddfe31..067ecdef8f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java
@@ -114,6 +114,13 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{
if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4;
int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours);
+ Profile profile = MainApp.getConfigBuilder().getProfile();
+
+ if (profile == null) {
+ log.debug("No profile");
+ return new AutosensResult();
+ }
+
if (autosensDataTable == null || autosensDataTable.size() < 4) {
log.debug("No autosens data available");
return new AutosensResult();
@@ -159,8 +166,6 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{
Double[] deviations = new Double[deviationsArray.size()];
deviations = deviationsArray.toArray(deviations);
- Profile profile = MainApp.getConfigBuilder().getProfile();
-
double sens = profile.getIsf();
String ratioLimit = "";
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java
index 91053e2654..d80510d8a8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java
@@ -124,6 +124,13 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
}
+ Profile profile = MainApp.getConfigBuilder().getProfile();
+ if (profile == null) {
+ if (Config.logAutosensData)
+ log.debug("No profile available");
+ return new AutosensResult();
+ }
+
String pastSensitivity = "";
int index = 0;
LongSparseArray data = new LongSparseArray<>();
@@ -181,8 +188,6 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
return new AutosensResult();
}
- Profile profile = MainApp.getConfigBuilder().getProfile();
-
double sens = profile.getIsf();
String ratioLimit = "";
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java
index 1842d3b504..82c513cbb9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java
@@ -346,7 +346,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
if (!t.isEndingEvent()) {
total.lastTempDate = t.date;
total.lastTempDuration = t.durationInMinutes;
- total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date);
+ Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
+ total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date, profile);
}
}
@@ -363,7 +364,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
if (!t.isEndingEvent() && t.date > total.lastTempDate) {
total.lastTempDate = t.date;
total.lastTempDuration = t.durationInMinutes;
- total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date);
+ Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
+ total.lastTempRate = t.tempBasalConvertedToAbsolute(t.date, profile);
}
}
}
@@ -410,34 +412,6 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
return extendedBoluses;
}
- @Override
- public double getTempBasalAbsoluteRateHistory() {
- TemporaryBasal tb = getTempBasalFromHistory(System.currentTimeMillis());
- if (tb != null) {
- if (tb.isFakeExtended) {
- double baseRate = ConfigBuilderPlugin.getActivePump().getBaseBasalRate();
- double tempRate = baseRate + tb.netExtendedRate;
- return tempRate;
- } else if (tb.isAbsolute) {
- return tb.absoluteRate;
- } else {
- double baseRate = ConfigBuilderPlugin.getActivePump().getBaseBasalRate();
- double tempRate = baseRate * (tb.percentRate / 100d);
- return tempRate;
- }
- }
- return 0;
- }
-
- @Override
- public double getTempBasalRemainingMinutesFromHistory() {
- TemporaryBasal activeTemp = getTempBasalFromHistory(System.currentTimeMillis());
- if (activeTemp != null) {
- return activeTemp.getPlannedRemainingMinutes();
- }
- return 0;
- }
-
@Override
public Intervals getTemporaryBasalsFromHistory() {
return tempBasals;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java
index c883bc8757..8f838ee45a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
+import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventNewBG;
@@ -86,8 +87,14 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
}
holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.durationInMinutes) + " min");
if (tempBasal.isAbsolute) {
- holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date)) + " U/h");
- holder.percent.setText("");
+ Profile profile = MainApp.getConfigBuilder().getProfile(tempBasal.date);
+ if (profile != null) {
+ holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile)) + " U/h");
+ holder.percent.setText("");
+ } else {
+ holder.absolute.setText(MainApp.gs(R.string.noprofile));
+ holder.percent.setText("");
+ }
} else {
holder.absolute.setText("");
holder.percent.setText(DecimalFormatter.to0Decimal(tempBasal.percentRate) + "%");
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 270051fbb6..30d0060682 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
@@ -332,16 +332,16 @@ public class ActionStringHandler {
private static String generateTDDMessage(List historyList, List dummies) {
- ProfileInterface activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
+ Profile profile = MainApp.getConfigBuilder().getProfile();
- if (activeProfile == null) {
+ if (profile == null) {
return "No profile loaded :(";
}
DateFormat df = new SimpleDateFormat("dd.MM.");
String message = "";
- double refTDD = activeProfile.getProfile().getDefaultProfile().baseBasalSum() * 2;
+ double refTDD = profile.baseBasalSum() * 2;
int i = 0;
double sum = 0d;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
index a254221a3e..e75e6ec1ef 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java
@@ -388,13 +388,14 @@ public class WatchUpdaterService extends WearableListenerService implements
if (tb1 != null) {
tb_before = beginBasalValue;
- tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime);
+ Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
+ tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime, profileTB);
tb_start = runningTime;
}
for (; runningTime < now; runningTime += 5 * 60 * 1000) {
-
+ Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
//basal rate
endBasalValue = profile.getBasal(runningTime);
if (endBasalValue != beginBasalValue) {
@@ -422,10 +423,10 @@ public class WatchUpdaterService extends WearableListenerService implements
tb1 = tb2;
tb_start = runningTime;
tb_before = endBasalValue;
- tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime);
+ tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime, profileTB);
} else if (tb1 != null && tb2 != null) {
- double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime);
+ double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime, profileTB);
if (currentAmount != tb_amount) {
temps.add(tempDatamap(tb_start, tb_before, runningTime, currentAmount, tb_amount));
tb_start = runningTime;
@@ -446,7 +447,8 @@ public class WatchUpdaterService extends WearableListenerService implements
temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount));
} else {
//express currently running temp by painting it a bit into the future
- double currentAmount = tb2.tempBasalConvertedToAbsolute(now);
+ Profile profileNow = MainApp.getConfigBuilder().getProfile(now);
+ double currentAmount = tb2.tempBasalConvertedToAbsolute(now, profileNow);
if (currentAmount != tb_amount) {
temps.add(tempDatamap(tb_start, tb_before, now, tb_amount, tb_amount));
temps.add(tempDatamap(now, tb_amount, runningTime + 5 * 60 * 1000, currentAmount, currentAmount));
@@ -458,7 +460,8 @@ public class WatchUpdaterService extends WearableListenerService implements
tb2 = MainApp.getConfigBuilder().getTempBasalFromHistory(now); //use "now" to express current situation
if (tb2 != null) {
//onset at the end
- double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime);
+ Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime);
+ double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime, profileTB);
temps.add(tempDatamap(now - 1 * 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount));
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java
index 7e9619dfb3..76e8ac9e4d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java
@@ -149,14 +149,13 @@ public class StatuslinePlugin implements PluginBase {
private void sendStatus() {
-
-
String status = ""; // sent once on disable
- if (fragmentEnabled) {
- status = buildStatusString();
- }
+ Profile profile = MainApp.getConfigBuilder().getProfile();
+ if (fragmentEnabled && profile != null) {
+ status = buildStatusString(profile);
+ }
//sendData
final Bundle bundle = new Bundle();
@@ -168,7 +167,7 @@ public class StatuslinePlugin implements PluginBase {
}
@NonNull
- private String buildStatusString() {
+ private String buildStatusString(Profile profile) {
String status = "";
LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
@@ -200,10 +199,6 @@ public class StatuslinePlugin implements PluginBase {
+ DecimalFormatter.to2Decimal(bolusIob.iob) + "|"
+ DecimalFormatter.to2Decimal(basalIob.basaliob) + ")";
}
- Profile profile = MainApp.getConfigBuilder().getProfile();
-
- if (profile == null)
- return status;
if (!mPrefs.getBoolean("xdripstatus_showbgi", false)) {
return status;
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
index 2502f1f5cf..6e8f6cb6a0 100644
--- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
+++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
@@ -419,10 +419,11 @@ public class CommandQueue {
public boolean isThisProfileSet(Profile profile) {
PumpInterface activePump = ConfigBuilderPlugin.getActivePump();
- if (activePump != null) {
+ Profile current = MainApp.getConfigBuilder().getProfile();
+ if (activePump != null && current != null) {
boolean result = activePump.isThisProfileSet(profile);
if (!result) {
- log.debug("Current profile: " + MainApp.getConfigBuilder().getProfile().getData().toString());
+ log.debug("Current profile: " + current.getData().toString());
log.debug("New profile: " + profile.getData().toString());
}
return result;
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java
index e037f0b869..15f8849cd2 100644
--- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java
+++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java
@@ -4,7 +4,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
-import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.queue.Callback;
diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java
index 690b239128..a75377aae1 100644
--- a/app/src/main/java/info/nightscout/utils/NSUpload.java
+++ b/app/src/main/java/info/nightscout/utils/NSUpload.java
@@ -34,8 +34,6 @@ import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
-import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
-import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA;
/**
* Created by mike on 26.05.2017.
@@ -190,6 +188,14 @@ public class NSUpload {
}
public static void uploadDeviceStatus() {
+ Profile profile = MainApp.getConfigBuilder().getProfile();
+ String profileName = MainApp.getConfigBuilder().getProfileName();
+
+ if (profile == null || profileName == null) {
+ log.error("Profile is null. Skipping upload");
+ return;
+ }
+
DeviceStatus deviceStatus = new DeviceStatus();
try {
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
@@ -202,22 +208,31 @@ public class NSUpload {
deviceStatus.iob = lastRun.request.iob.json();
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
- if (lastRun.setByPump != null && lastRun.setByPump.enacted) { // enacted
+ JSONObject requested = new JSONObject();
+
+ if (lastRun.tbrSetByPump != null && lastRun.tbrSetByPump.enacted) { // enacted
deviceStatus.enacted = lastRun.request.json();
- deviceStatus.enacted.put("rate", lastRun.setByPump.json().get("rate"));
- deviceStatus.enacted.put("duration", lastRun.setByPump.json().get("duration"));
+ deviceStatus.enacted.put("rate", lastRun.tbrSetByPump.json(profile).get("rate"));
+ deviceStatus.enacted.put("duration", lastRun.tbrSetByPump.json(profile).get("duration"));
deviceStatus.enacted.put("recieved", true);
- JSONObject requested = new JSONObject();
requested.put("duration", lastRun.request.duration);
requested.put("rate", lastRun.request.rate);
requested.put("temp", "absolute");
deviceStatus.enacted.put("requested", requested);
}
+ if (lastRun.smbSetByPump != null && lastRun.smbSetByPump.enacted) { // enacted
+ if (deviceStatus.enacted == null) {
+ deviceStatus.enacted = lastRun.request.json();
+ }
+ deviceStatus.enacted.put("smb", lastRun.smbSetByPump.bolusDelivered);
+ requested.put("smb", lastRun.request.smb);
+ deviceStatus.enacted.put("requested", requested);
+ }
} else {
log.debug("OpenAPS data too old to upload");
}
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
- JSONObject pumpstatus = ConfigBuilderPlugin.getActivePump().getJSONStatus();
+ JSONObject pumpstatus = ConfigBuilderPlugin.getActivePump().getJSONStatus(profile, profileName);
if (pumpstatus != null) {
deviceStatus.pump = pumpstatus;
}
diff --git a/app/src/main/res/layout/loop_fragment.xml b/app/src/main/res/layout/loop_fragment.xml
index fb6038dcb3..36f310cc81 100644
--- a/app/src/main/res/layout/loop_fragment.xml
+++ b/app/src/main/res/layout/loop_fragment.xml
@@ -256,7 +256,7 @@
android:layout_weight="2"
android:gravity="end"
android:paddingRight="5dp"
- android:text="@string/loop_setbypump_label"
+ android:text="@string/loop_tbrsetbypump_label"
android:textSize="14sp" />
+
+
+
+
+
+
+
+
+
+
+
+ Loop
APS
След ограничения
- Зададено на помпата
Последно зададено
OK
Откажи
diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml
index 0934cf6c9b..2852581e11 100644
--- a/app/src/main/res/values-cs/strings.xml
+++ b/app/src/main/res/values-cs/strings.xml
@@ -68,7 +68,8 @@
Smyčka
APS
Po zpracování omezení
- Nastaveno pumpou
+ Bazál nastavený pumpou
+ SMB provedené pumpou
SMYČKA ZAKÁZÁNA OMEZENÍM
Ručně spuštěno
Minimální trvání
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 97b17ecd30..ed22759365 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -160,7 +160,6 @@
Beschränkungen angewendet!
Beschränkungen wurden verletzt oder Limit erreicht
Czech
- Gesetzt durch Pumpe
LOOP DEAKTIVIERT DURCH BESCHRÄNKUNGEN
Beschränkungen angewendet
Loop
diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml
index 000edd9587..dd8db5a980 100644
--- a/app/src/main/res/values-el/strings.xml
+++ b/app/src/main/res/values-el/strings.xml
@@ -100,7 +100,6 @@
Κύκλωμα
APS
Μετά από επεξεργασία περιορισμών
- Ρυθμίστε με αντλία
Τελευταία Εφαρμογή
ΟΚ
Ακύρωση
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 6482fde307..02519f5604 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -92,7 +92,6 @@
Lazo
APS
Tras procesar limitaciones
- Definido por la bomba
Última aceptada
OK
Cancelar
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index b83c59b50d..5d4b74043b 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -95,7 +95,6 @@
Loop
APS
Après traitement des restrictions
- "Défini par pompe "
Dérnière mise en marche
OK
Annuler
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index 49af1e4af4..3bca4483a0 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -188,7 +188,6 @@
Delta acg. esteso
Loop
APS
- Set Micro
Loop
Loop disabilitato da vincolo
Loop menu
diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml
index 3a859e961c..fa801d9151 100644
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -98,7 +98,6 @@
Loop
APS
제약 적용 후
- 펌프 설정
최근 주입
OK
취소
diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml
index a26b0ca172..456135f751 100644
--- a/app/src/main/res/values-nl/strings.xml
+++ b/app/src/main/res/values-nl/strings.xml
@@ -218,7 +218,6 @@
Loop
APS
Berekening met toepassing van limieten
- Gedefinieerd door de pomp
LOOP
Italiano
Nederlands
diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml
index 588fc2ceb5..645c71bcc6 100644
--- a/app/src/main/res/values-ro/strings.xml
+++ b/app/src/main/res/values-ro/strings.xml
@@ -98,7 +98,6 @@
Loop
APS
Constrângeri după procesare
- Setat de pompă
Ultima acțiune
Doriți reîncărcarea tratamentelor din Nightscout
Doriți reîncărcarea țintelor temporare din Nightscout
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index fd5f55df01..ca91df2ea3 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -233,7 +233,6 @@
замкнутый цикл
APS
после наложенных ограничений
- задано помпой
ЗЦ
ЗЦ ОТМЕНЕН ОГРАНИЧЕНИЯМИ
меню ЗЦ
diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml
index 000dd10c9a..da1e8a4dcf 100644
--- a/app/src/main/res/values-sv/strings.xml
+++ b/app/src/main/res/values-sv/strings.xml
@@ -217,7 +217,6 @@
Loop
APS
Efter avklarade begränsningar
- Inställning i pump
LOOP
LOOP STOPPAD PGA BEGRÄNSNINGAR
Loop meny
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9a908aa45f..b3a822ecfd 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -104,7 +104,7 @@
Loop
APS
After processed constraints
- Set by pump
+ Temp basal set by pump
Last enacted
OK
Cancel
@@ -985,6 +985,7 @@
Bolus will be recorded only
Autobackfill missig BGs from NS
ns_autobackfill
+ SMB set by pump
%.2f U/h
Reading basal profile
The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait two minutes since boluses with the same amount are blocked when requested with less than two minutes between them for safety (regardless of whether they were administered or not).