Merge remote-tracking branch 'origin/dev' into combo-dev-merge
* origin/dev: check for null profile remove profile dependency from pump drivers, TRB optimalization split enacting TRB and SMB
This commit is contained in:
commit
8457cd3843
57 changed files with 414 additions and 338 deletions
|
@ -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)
|
||||
|
|
|
@ -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 += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.smb_shortname) + "</b>: " + bolusDelivered + "U";
|
||||
} else if (isTempCancel) {
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment +
|
||||
"<br>" + 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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<TemporaryBasal> getTemporaryBasalsFromHistory();
|
||||
|
||||
boolean isInHistoryExtendedBoluslInProgress();
|
||||
|
|
|
@ -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<TemporaryBasal> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
@OnClick(R.id.loop_run)
|
||||
void onRunClick() {
|
||||
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();
|
||||
new Thread(() -> LoopPlugin.getPlugin().invoke("Loop button", true)).start();
|
||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("Loop_Run"));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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() {
|
||||
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() : "");
|
||||
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() : "");
|
||||
}
|
||||
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() {
|
||||
activity.runOnUiThread(() -> {
|
||||
requestView.setText("");
|
||||
constraintsProcessedView.setText("");
|
||||
setByPumpView.setText("");
|
||||
sourceView.setText("");
|
||||
lastRunView.setText("");
|
||||
lastEnactView.setText("");
|
||||
}
|
||||
tbrSetByPumpView.setText("");
|
||||
smbSetByPumpView.setText("");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -218,11 +218,13 @@ public class DetermineBasalAdapterAMAJS {
|
|||
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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<DataPoint> targetsSeries;
|
||||
|
||||
Scale targetsScale = new Scale();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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,10 +116,11 @@ 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());
|
||||
if (MainApp.getConfigBuilder().isProfileValid("storeNewProfile")) {
|
||||
ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -132,8 +133,9 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void storeNSProfile() {
|
||||
private void storeNSProfile() {
|
||||
SP.putString("profile", profile.getData().toString());
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Storing profile");
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 = "";
|
||||
|
|
|
@ -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<Double> 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 = "";
|
||||
|
|
|
@ -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<TemporaryBasal> getTemporaryBasalsFromHistory() {
|
||||
return tempBasals;
|
||||
|
|
|
@ -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");
|
||||
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) + "%");
|
||||
|
|
|
@ -332,16 +332,16 @@ public class ActionStringHandler {
|
|||
|
||||
private static String generateTDDMessage(List<DanaRHistoryRecord> historyList, List<DanaRHistoryRecord> 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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
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("recieved", true);
|
||||
JSONObject requested = new JSONObject();
|
||||
|
||||
if (lastRun.tbrSetByPump != null && lastRun.tbrSetByPump.enacted) { // enacted
|
||||
deviceStatus.enacted = lastRun.request.json();
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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" />
|
||||
|
||||
<TextView
|
||||
|
@ -270,7 +270,52 @@
|
|||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loop_setbypump"
|
||||
android:id="@+id/loop_tbrsetbypump"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="start"
|
||||
android:paddingLeft="5dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:background="@color/listdelimiter" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/loop_smbsetbypump_label"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="5dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingEnd="2dp"
|
||||
android:paddingStart="2dp"
|
||||
android:text=":"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loop_smbsetbypump"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
|
|
@ -98,7 +98,6 @@
|
|||
<string name="configbuilder_loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">След ограничения</string>
|
||||
<string name="loop_setbypump_label">Зададено на помпата</string>
|
||||
<string name="openapsma_lastenact_label">Последно зададено</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Откажи</string>
|
||||
|
|
|
@ -68,7 +68,8 @@
|
|||
<string name="loop">Smyčka</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">Po zpracování omezení</string>
|
||||
<string name="loop_setbypump_label">Nastaveno pumpou</string>
|
||||
<string name="loop_tbrsetbypump_label">Bazál nastavený pumpou</string>
|
||||
<string name="loop_smbsetbypump_label">SMB provedené pumpou</string>
|
||||
<string name="loopdisabled">SMYČKA ZAKÁZÁNA OMEZENÍM</string>
|
||||
<string name="objectives_manualenacts">Ručně spuštěno</string>
|
||||
<string name="objectives_minimalduration">Minimální trvání</string>
|
||||
|
|
|
@ -160,7 +160,6 @@
|
|||
<string name="constraintapllied">Beschränkungen angewendet!</string>
|
||||
<string name="constraints_violation">Beschränkungen wurden verletzt oder Limit erreicht</string>
|
||||
<string name="cs_lang">Czech</string>
|
||||
<string name="loop_setbypump_label">Gesetzt durch Pumpe</string>
|
||||
<string name="loopdisabled">LOOP DEAKTIVIERT DURCH BESCHRÄNKUNGEN</string>
|
||||
<string name="loop_constraintsprocessed_label">Beschränkungen angewendet</string>
|
||||
<string name="loop">Loop</string>
|
||||
|
|
|
@ -100,7 +100,6 @@
|
|||
<string name="configbuilder_loop">Κύκλωμα</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">Μετά από επεξεργασία περιορισμών</string>
|
||||
<string name="loop_setbypump_label">Ρυθμίστε με αντλία</string>
|
||||
<string name="openapsma_lastenact_label">Τελευταία Εφαρμογή</string>
|
||||
<string name="ok">ΟΚ</string>
|
||||
<string name="cancel">Ακύρωση</string>
|
||||
|
|
|
@ -92,7 +92,6 @@
|
|||
<string name="configbuilder_loop">Lazo</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">Tras procesar limitaciones</string>
|
||||
<string name="loop_setbypump_label">Definido por la bomba</string>
|
||||
<string name="openapsma_lastenact_label">Última aceptada</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Cancelar</string>
|
||||
|
|
|
@ -95,7 +95,6 @@
|
|||
<string name="configbuilder_loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">Après traitement des restrictions</string>
|
||||
<string name="loop_setbypump_label">"Défini par pompe "</string>
|
||||
<string name="openapsma_lastenact_label">Dérnière mise en marche</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Annuler</string>
|
||||
|
|
|
@ -188,7 +188,6 @@
|
|||
<string name="long_avgdelta">Delta acg. esteso</string>
|
||||
<string name="loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_setbypump_label">Set Micro</string>
|
||||
<string name="loop_shortname">Loop</string>
|
||||
<string name="loopdisabled">Loop disabilitato da vincolo</string>
|
||||
<string name="loopmenu">Loop menu</string>
|
||||
|
|
|
@ -98,7 +98,6 @@
|
|||
<string name="configbuilder_loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">제약 적용 후</string>
|
||||
<string name="loop_setbypump_label">펌프 설정</string>
|
||||
<string name="openapsma_lastenact_label">최근 주입</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">취소</string>
|
||||
|
|
|
@ -218,7 +218,6 @@
|
|||
<string name="loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">Berekening met toepassing van limieten</string>
|
||||
<string name="loop_setbypump_label">Gedefinieerd door de pomp</string>
|
||||
<string name="loop_shortname">LOOP</string>
|
||||
<string name="it_lang">Italiano</string>
|
||||
<string name="nl_lang">Nederlands</string>
|
||||
|
|
|
@ -98,7 +98,6 @@
|
|||
<string name="configbuilder_loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">Constrângeri după procesare<string>
|
||||
<string name="loop_setbypump_label">Setat de pompă</string>
|
||||
<string name="openapsma_lastenact_label">Ultima acțiune</string>
|
||||
<string name="refreshtreatmentsfromnightscout">Doriți reîncărcarea tratamentelor din Nightscout</string>
|
||||
<string name="refreshtemptargetsfromnightscout">Doriți reîncărcarea țintelor temporare din Nightscout</string>
|
||||
|
|
|
@ -233,7 +233,6 @@
|
|||
<string name="loop">замкнутый цикл</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">после наложенных ограничений</string>
|
||||
<string name="loop_setbypump_label">задано помпой</string>
|
||||
<string name="loop_shortname">ЗЦ</string>
|
||||
<string name="loopdisabled">ЗЦ ОТМЕНЕН ОГРАНИЧЕНИЯМИ</string>
|
||||
<string name="loopmenu">меню ЗЦ</string>
|
||||
|
|
|
@ -217,7 +217,6 @@
|
|||
<string name="loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">Efter avklarade begränsningar</string>
|
||||
<string name="loop_setbypump_label">Inställning i pump</string>
|
||||
<string name="loop_shortname">LOOP</string>
|
||||
<string name="loopdisabled">LOOP STOPPAD PGA BEGRÄNSNINGAR</string>
|
||||
<string name="loopmenu">Loop meny</string>
|
||||
|
|
|
@ -104,7 +104,7 @@
|
|||
<string name="configbuilder_loop">Loop</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
<string name="loop_constraintsprocessed_label">After processed constraints</string>
|
||||
<string name="loop_setbypump_label">Set by pump</string>
|
||||
<string name="loop_tbrsetbypump_label">Temp basal set by pump</string>
|
||||
<string name="openapsma_lastenact_label">Last enacted</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
|
@ -985,6 +985,7 @@
|
|||
<string name="bolusrecordedonly">Bolus will be recorded only</string>
|
||||
<string name="ns_autobackfill">Autobackfill missig BGs from NS</string>
|
||||
<string name="key_ns_autobackfill" translatable="false">ns_autobackfill</string>
|
||||
<string name="loop_smbsetbypump_label">SMB set by pump</string>
|
||||
<string name="pump_basebasalrate">%.2f U/h</string>
|
||||
<string name="combo_actvity_reading_basal_profile">Reading basal profile</string>
|
||||
<string name="combo_bolus_rejected_due_to_pump_history_change">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).</string>
|
||||
|
|
Loading…
Reference in a new issue