move part of PumpInterface to TreatmentInterface

This commit is contained in:
Milos Kozak 2017-05-12 21:07:29 +02:00
parent 22bb49aa60
commit 52177cead1
32 changed files with 299 additions and 446 deletions

View file

@ -114,71 +114,6 @@ public class TempBasal {
return result; return result;
} }
/*
public IobTotal old_iobCalc(long time) {
IobTotal result = new IobTotal(time);
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
if (profile == null)
return result;
Double basalRate = profile.getBasal(NSProfile.secondsFromMidnight(time));
if (basalRate == null)
return result;
int realDuration = getDurationToTime(time);
if (realDuration > 0) {
Double netBasalRate = 0d;
Double tempBolusSize = 0.05;
if (isExtended) {
netBasalRate = this.absolute;
} else {
if (this.isAbsolute) {
netBasalRate = this.absolute - basalRate;
} else {
netBasalRate = (this.percent - 100) / 100d * basalRate;
}
}
result.netRatio = netBasalRate;
Double netBasalAmount = Math.round(netBasalRate * realDuration * 10 / 6) / 100d;
result.netInsulin = netBasalAmount;
if (netBasalAmount < 0.1) {
tempBolusSize = 0.01;
}
if (netBasalRate < 0) {
tempBolusSize = -tempBolusSize;
}
Long tempBolusCount = Math.round(netBasalAmount / tempBolusSize);
if (tempBolusCount > 0) {
Long tempBolusSpacing = realDuration / tempBolusCount;
for (Long j = 0L; j < tempBolusCount; j++) {
Treatment tempBolusPart = new Treatment(insulinInterface);
tempBolusPart.insulin = tempBolusSize;
Long date = this.timeStart.getTime() + j * tempBolusSpacing * 60 * 1000;
tempBolusPart.created_at = new Date(date);
Iob aIOB = insulinInterface.iobCalc(tempBolusPart, time, profile.getDia());
result.basaliob += aIOB.iobContrib;
result.activity += aIOB.activityContrib;
Double dia_ago = time - profile.getDia() * 60 * 60 * 1000;
if (date > dia_ago && date <= time) {
result.netbasalinsulin += tempBolusPart.insulin;
if (tempBolusPart.insulin > 0) {
result.hightempinsulin += tempBolusPart.insulin;
}
}
}
}
}
return result;
}
*/
// Determine end of basal // Determine end of basal
public long getTimeEnd() { public long getTimeEnd() {
long tempBasalTimePlannedEnd = getPlannedTimeEnd(); long tempBasalTimePlannedEnd = getPlannedTimeEnd();
@ -203,7 +138,7 @@ public class TempBasal {
return Math.round(msecs / 60f / 1000); return Math.round(msecs / 60f / 1000);
} }
public int getDurationToTime(long time) { private int getDurationToTime(long time) {
long endTime = Math.min(time, getTimeEnd()); long endTime = Math.min(time, getTimeEnd());
long msecs = endTime - timeStart.getTime(); long msecs = endTime - timeStart.getTime();
return Math.round(msecs / 60f / 1000); return Math.round(msecs / 60f / 1000);
@ -220,33 +155,31 @@ public class TempBasal {
} }
public boolean isInProgress() { public boolean isInProgress() {
return isInProgress(new Date()); return isInProgress(new Date().getTime());
} }
public double tempBasalConvertedToAbsolute(Date time) { public double tempBasalConvertedToAbsolute(Date time) {
if (isExtended) { if (isExtended) {
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
double absval = profile.getBasal(NSProfile.secondsFromMidnight(time)) + absolute; return profile.getBasal(NSProfile.secondsFromMidnight(time)) + absolute;
return absval;
} else { } else {
if (isAbsolute) return absolute; if (isAbsolute) return absolute;
else { else {
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
double absval = profile.getBasal(NSProfile.secondsFromMidnight(time)) * percent / 100; return profile.getBasal(NSProfile.secondsFromMidnight(time)) * percent / 100;
return absval;
} }
} }
} }
public boolean isInProgress(Date time) { public boolean isInProgress(long time) {
if (timeStart.getTime() > time.getTime()) return false; // in the future if (timeStart.getTime() > time) return false; // in the future
if (timeEnd == null) { // open end if (timeEnd == null) { // open end
if (timeStart.getTime() < time.getTime() && getPlannedTimeEnd() > time.getTime()) if (timeStart.getTime() < time && getPlannedTimeEnd() > time)
return true; // in interval return true; // in interval
return false; return false;
} }
// closed end // closed end
if (timeStart.getTime() < time.getTime() && timeEnd.getTime() > time.getTime()) if (timeStart.getTime() < time && timeEnd.getTime() > time)
return true; // in interval return true; // in interval
return false; return false;
} }

View file

@ -19,9 +19,6 @@ public interface PumpInterface {
boolean isSuspended(); boolean isSuspended();
boolean isBusy(); boolean isBusy();
boolean isTempBasalInProgress();
boolean isExtendedBoluslInProgress();
// Upload to pump new basal profile // Upload to pump new basal profile
int SUCCESS = 0; int SUCCESS = 0;
int FAILED = 1; int FAILED = 1;
@ -35,9 +32,6 @@ public interface PumpInterface {
double getBaseBasalRate(); // base basal rate, not temp basal double getBaseBasalRate(); // base basal rate, not temp basal
double getTempBasalAbsoluteRate(); double getTempBasalAbsoluteRate();
double getTempBasalRemainingMinutes(); double getTempBasalRemainingMinutes();
TempBasal getTempBasal(Date time);
TempBasal getTempBasal();
TempBasal getExtendedBolus();
PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context); PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context);
void stopBolusDelivering(); void stopBolusDelivering();

View file

@ -26,8 +26,11 @@ public interface TreatmentsInterface {
List<Treatment> getTreatments(); List<Treatment> getTreatments();
List<Treatment> getTreatments5MinBack(long time); List<Treatment> getTreatments5MinBack(long time);
TempBasal getTempBasal (Date time); boolean isTempBasalInProgress();
TempBasal getExtendedBolus (Date time); boolean isExtendedBoluslInProgress();
TempBasal getTempBasal (long time);
TempBasal getExtendedBolus (long time);
long oldestDataAvaialable(); long oldestDataAvaialable();

View file

@ -16,11 +16,14 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
@ -58,7 +61,7 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class ConfigBuilderPlugin implements PluginBase, PumpInterface, ConstraintsInterface { public class ConfigBuilderPlugin implements PluginBase, PumpInterface, ConstraintsInterface, TreatmentsInterface {
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class); private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
static BgSourceInterface activeBgSource; static BgSourceInterface activeBgSource;
@ -201,10 +204,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
return activeProfile; return activeProfile;
} }
public static TreatmentsInterface getActiveTreatments() {
return activeTreatments;
}
public static InsulinInterface getActiveInsulin() { public static InsulinInterface getActiveInsulin() {
return activeInsulin; return activeInsulin;
} }
@ -222,7 +221,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
log.debug(p.getName() + ":" + log.debug(p.getName() + ":" +
(p.isEnabled(1) ? " GENERAL" : "") + (p.isEnabled(1) ? " GENERAL" : "") +
(p.isEnabled(2) ? " TREATMENT" : "") + (p.isEnabled(2) ? " TREATMENT" : "") +
(p.isEnabled(3) ? " TEMPBASAL" : "") +
(p.isEnabled(4) ? " PROFILE" : "") + (p.isEnabled(4) ? " PROFILE" : "") +
(p.isEnabled(5) ? " APS" : "") + (p.isEnabled(5) ? " APS" : "") +
(p.isEnabled(6) ? " PUMP" : "") + (p.isEnabled(6) ? " PUMP" : "") +
@ -362,20 +360,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
else return false; else return false;
} }
@Override
public boolean isTempBasalInProgress() {
if (activePump != null)
return activePump.isTempBasalInProgress();
else return false;
}
@Override
public boolean isExtendedBoluslInProgress() {
if (activePump != null)
return activePump.isExtendedBoluslInProgress();
else return false;
}
@Override @Override
public int setNewBasalProfile(NSProfile profile) { public int setNewBasalProfile(NSProfile profile) {
// Compare with pump limits // Compare with pump limits
@ -444,30 +428,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
return 0d; return 0d;
} }
@Override
public TempBasal getTempBasal(Date time) {
if (activePump != null)
return activePump.getTempBasal(time);
else
return null;
}
@Override
public TempBasal getTempBasal() {
if (activePump != null)
return activePump.getTempBasal();
else
return null;
}
@Override
public TempBasal getExtendedBolus() {
if (activePump != null)
return activePump.getExtendedBolus();
else
return null;
}
public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) { public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
mWakeLock.acquire(); mWakeLock.acquire();
PumpEnactResult result; PumpEnactResult result;
@ -719,7 +679,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
} else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRate()) < 0.05) { } else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRate()) < 0.05) {
result = new PumpEnactResult(); result = new PumpEnactResult();
result.absolute = getTempBasalAbsoluteRate(); result.absolute = getTempBasalAbsoluteRate();
result.duration = activePump.getTempBasal().getPlannedRemainingMinutes(); result.duration = getTempBasal(new Date().getTime()).getPlannedRemainingMinutes();
result.enacted = false; result.enacted = false;
result.comment = "Temp basal set correctly"; result.comment = "Temp basal set correctly";
result.success = true; result.success = true;
@ -1187,4 +1147,74 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
} }
} }
// Treatments interface
@Override
public void updateTotalIOBTreatments() {
activeTreatments.updateTotalIOBTreatments();
}
@Override
public void updateTotalIOBTempBasals() {
activeTreatments.updateTotalIOBTempBasals();
}
@Override
public IobTotal getLastCalculationTreatments() {
return activeTreatments.getLastCalculationTreatments();
}
@Override
public IobTotal getCalculationToTimeTreatments(long time) {
return activeTreatments.getCalculationToTimeTreatments(time);
}
@Override
public IobTotal getLastCalculationTempBasals() {
return activeTreatments.getLastCalculationTempBasals();
}
@Override
public IobTotal getCalculationToTimeTempBasals(long time) {
return activeTreatments.getCalculationToTimeTempBasals(time);
}
@Override
public MealData getMealData() {
return activeTreatments.getMealData();
}
@Override
public List<Treatment> getTreatments() {
return activeTreatments.getTreatments();
}
@Override
public List<Treatment> getTreatments5MinBack(long time) {
return activeTreatments.getTreatments5MinBack(time);
}
@Override
public boolean isTempBasalInProgress() {
return activeTreatments.isTempBasalInProgress();
}
@Override
public boolean isExtendedBoluslInProgress() {
return activeTreatments.isExtendedBoluslInProgress();
}
@Override
public TempBasal getTempBasal(long time) {
return activeTreatments.getTempBasal(time);
}
@Override
public TempBasal getExtendedBolus(long time) {
return activeTreatments.getExtendedBolus(time);
}
@Override
public long oldestDataAvaialable() {
return activeTreatments.oldestDataAvaialable();
}
} }

View file

@ -238,12 +238,6 @@ public class IobCobCalculatorPlugin implements PluginBase {
return; return;
} }
if (ConfigBuilderPlugin.getActiveTreatments() == null) {
log.debug("calculateSensitivityData: No treatments plugin");
return;
}
TreatmentsInterface treatmentsInterface = ConfigBuilderPlugin.getActiveTreatments();
if (bucketed_data == null || bucketed_data.size() < 3) { if (bucketed_data == null || bucketed_data.size() < 3) {
log.debug("calculateSensitivityData: No bucketed data available"); log.debug("calculateSensitivityData: No bucketed data available");
return; return;
@ -286,7 +280,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
double bgi = -iob.activity * sens * 5; double bgi = -iob.activity * sens * 5;
double deviation = delta - bgi; double deviation = delta - bgi;
List<Treatment> recentTreatments = treatmentsInterface.getTreatments5MinBack(bgTime); List<Treatment> recentTreatments = MainApp.getConfigBuilder().getTreatments5MinBack(bgTime);
for (int ir = 0; ir < recentTreatments.size(); ir++) { for (int ir = 0; ir < recentTreatments.size(); ir++) {
autosensData.carbsFromBolus += recentTreatments.get(ir).carbs; autosensData.carbsFromBolus += recentTreatments.get(ir).carbs;
} }
@ -338,8 +332,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
} else { } else {
//log.debug(">>> Cache miss " + new Date(time).toLocaleString()); //log.debug(">>> Cache miss " + new Date(time).toLocaleString());
} }
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTimeTreatments(time).round(); IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round();
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTimeTempBasals(time).round(); IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round();
/* /*
if (basalIob.basaliob > 0) { if (basalIob.basaliob > 0) {
log.debug(new Date(time).toLocaleString() + " basaliob: " + basalIob.basaliob ); log.debug(new Date(time).toLocaleString() + " basaliob: " + basalIob.basaliob );

View file

@ -11,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
@ -231,7 +232,7 @@ public class DetermineBasalAdapterAMAJS {
mCurrentTemp.add("rate", pump.getTempBasalAbsoluteRate()); mCurrentTemp.add("rate", pump.getTempBasalAbsoluteRate());
// as we have non default temps longer than 30 mintues // as we have non default temps longer than 30 mintues
TempBasal tempBasal = pump.getTempBasal(); TempBasal tempBasal = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if(tempBasal != null){ if(tempBasal != null){
mCurrentTemp.add("minutesrunning", tempBasal.getRealDuration()); mCurrentTemp.add("minutesrunning", tempBasal.getRealDuration());
} }

View file

@ -191,7 +191,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
Profiler.log(log, "calculateIobArrayInDia()", startPart); Profiler.log(log, "calculateIobArrayInDia()", startPart);
startPart = new Date(); startPart = new Date();
MealData mealData = MainApp.getConfigBuilder().getActiveTreatments().getMealData(); MealData mealData = MainApp.getConfigBuilder().getMealData();
Profiler.log(log, "getMealData()", startPart); Profiler.log(log, "getMealData()", startPart);
maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob);
@ -222,7 +222,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTreatments().oldestDataAvaialable(); long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvaialable();
long getBGDataFrom = Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia()))); long getBGDataFrom = Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia())));
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());

View file

@ -186,15 +186,14 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
maxBg = Round.roundTo(maxBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d);
Date start = new Date(); Date start = new Date();
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments(); MainApp.getConfigBuilder().updateTotalIOBTreatments();
treatments.updateTotalIOBTreatments(); MainApp.getConfigBuilder().updateTotalIOBTempBasals();
treatments.updateTotalIOBTempBasals(); IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments();
IobTotal bolusIob = treatments.getLastCalculationTreatments(); IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals();
IobTotal basalIob = treatments.getLastCalculationTempBasals();
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round(); IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
MealData mealData = treatments.getMealData(); MealData mealData = MainApp.getConfigBuilder().getMealData();
maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob);
Profiler.log(log, "MA data gathering", start); Profiler.log(log, "MA data gathering", start);

View file

@ -211,8 +211,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Co
bgTrend = (TextView) view.findViewById(R.id.treatments_wizard_bgtrend); bgTrend = (TextView) view.findViewById(R.id.treatments_wizard_bgtrend);
bgTrendInsulin = (TextView) view.findViewById(R.id.treatments_wizard_bgtrendinsulin); bgTrendInsulin = (TextView) view.findViewById(R.id.treatments_wizard_bgtrendinsulin);
cobLayout = (LinearLayout) view.findViewById(R.id.treatments_wizard_cob_layout); cobLayout = (LinearLayout) view.findViewById(R.id.treatments_wizard_cob_layout);
cob = (TextView) view.findViewById(R.id.treatments_wizard_cob);; cob = (TextView) view.findViewById(R.id.treatments_wizard_cob);
cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin);; ;
cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin);
;
bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox); bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox);
bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox); bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox);
@ -409,14 +411,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Co
} }
// IOB calculation // IOB calculation
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments(); MainApp.getConfigBuilder().updateTotalIOBTreatments();
treatments.updateTotalIOBTreatments(); IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
IobTotal bolusIob = treatments.getLastCalculationTreatments(); MainApp.getConfigBuilder().updateTotalIOBTempBasals();
IobTotal basalIob = new IobTotal(new Date().getTime()); IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
if (treatments != null) {
treatments.updateTotalIOBTempBasals();
basalIob = treatments.getLastCalculationTempBasals().round();
}
bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U"); bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U");
basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U"); basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U");

View file

@ -483,7 +483,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
break; break;
case R.id.overview_canceltempbutton: case R.id.overview_canceltempbutton:
final PumpInterface pump = MainApp.getConfigBuilder(); final PumpInterface pump = MainApp.getConfigBuilder();
if (pump.isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
sHandler.post(new Runnable() { sHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -891,8 +891,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
calibrationButton.setVisibility(View.GONE); calibrationButton.setVisibility(View.GONE);
} }
TempBasal activeTemp = pump.getTempBasal(); TempBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (pump.isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
cancelTempButton.setVisibility(View.VISIBLE); cancelTempButton.setVisibility(View.VISIBLE);
cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort()); cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort());
runningTempView.setVisibility(View.VISIBLE); runningTempView.setVisibility(View.VISIBLE);
@ -1006,10 +1006,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
timeAgoView.setText(String.format(MainApp.sResources.getString(R.string.minago), agoMin)); timeAgoView.setText(String.format(MainApp.sResources.getString(R.string.minago), agoMin));
// iob // iob
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments(); MainApp.getConfigBuilder().updateTotalIOBTreatments();
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals(); MainApp.getConfigBuilder().updateTotalIOBTempBasals();
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round(); IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round(); IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " + getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
@ -1077,7 +1077,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
double lastBaseBasal = 0; double lastBaseBasal = 0;
double lastTempBasal = 0; double lastTempBasal = 0;
for (long time = fromTime; time < now; time += 5 * 60 * 1000L) { for (long time = fromTime; time < now; time += 5 * 60 * 1000L) {
TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date(time)); TempBasal tb = MainApp.getConfigBuilder().getTempBasal(time);
double baseBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))); double baseBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time)));
double baseLineValue = baseBasalValue; double baseLineValue = baseBasalValue;
double tempBasalValue = 0; double tempBasalValue = 0;
@ -1366,7 +1366,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// Treatments // Treatments
List<Treatment> treatments = MainApp.getConfigBuilder().getActiveTreatments().getTreatments(); List<Treatment> treatments = MainApp.getConfigBuilder().getTreatments();
List<Treatment> filteredTreatments = new ArrayList<Treatment>(); List<Treatment> filteredTreatments = new ArrayList<Treatment>();
for (int tx = 0; tx < treatments.size(); tx++) { for (int tx = 0; tx < treatments.size(); tx++) {

View file

@ -138,16 +138,16 @@ public class PersistentNotificationPlugin implements PluginBase{
PumpInterface pump = MainApp.getConfigBuilder(); PumpInterface pump = MainApp.getConfigBuilder();
if (pump.isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
TempBasal activeTemp = pump.getTempBasal(); TempBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
line1 += " " + activeTemp.toStringShort(); line1 += " " + activeTemp.toStringShort();
} }
//IOB //IOB
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments(); MainApp.getConfigBuilder().updateTotalIOBTreatments();
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals(); MainApp.getConfigBuilder().updateTotalIOBTempBasals();
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round(); IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round(); IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
String line2 = ctx.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" String line2 = ctx.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ ctx.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " + ctx.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "

View file

@ -219,13 +219,13 @@ public class DanaRFragment extends Fragment {
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
if (getPlugin().isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(getPlugin().getRealTempBasal().toString()); tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString());
} else { } else {
tempBasalView.setText(""); tempBasalView.setText("");
} }
if (getPlugin().isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
extendedBolusView.setText(getPlugin().getExtendedBolus().toString()); extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString());
} else { } else {
extendedBolusView.setText(""); extendedBolusView.setText("");
} }

View file

@ -139,7 +139,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
pumpDescription.highTempBasalStyle = useExtendedBoluses ? PumpDescription.EXTENDED : PumpDescription.PERCENT; pumpDescription.highTempBasalStyle = useExtendedBoluses ? PumpDescription.EXTENDED : PumpDescription.PERCENT;
if (useExtendedBoluses != previousValue && isExtendedBoluslInProgress()) { if (useExtendedBoluses != previousValue && MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
sExecutionService.extendedBolusStop(); sExecutionService.extendedBolusStop();
} }
} }
@ -240,22 +240,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
// Pump interface // Pump interface
@Override
public boolean isTempBasalInProgress() {
if (getRealTempBasal() != null) return true;
if (getExtendedBolus() != null && useExtendedBoluses) return true;
return false;
}
public boolean isRealTempBasalInProgress() {
return getRealTempBasal() != null; //TODO: crosscheck here
}
@Override
public boolean isExtendedBoluslInProgress() {
return getExtendedBolus() != null; //TODO: crosscheck here
}
@Override @Override
public int setNewBasalProfile(NSProfile profile) { public int setNewBasalProfile(NSProfile profile) {
if (sExecutionService == null) { if (sExecutionService == null) {
@ -321,7 +305,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public double getTempBasalAbsoluteRate() { public double getTempBasalAbsoluteRate() {
TempBasal tb = getRealTempBasal(); TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
if (tb.isAbsolute) { if (tb.isAbsolute) {
return tb.absolute; return tb.absolute;
@ -331,7 +315,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return tempRate; return tempRate;
} }
} }
TempBasal eb = getExtendedBolus(); TempBasal eb = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime());
if (eb != null && useExtendedBoluses) { if (eb != null && useExtendedBoluses) {
return getBaseBasalRate() + eb.absolute; return getBaseBasalRate() + eb.absolute;
} }
@ -340,39 +324,21 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public double getTempBasalRemainingMinutes() { public double getTempBasalRemainingMinutes() {
if (isRealTempBasalInProgress()) if (MainApp.getConfigBuilder().isTempBasalInProgress())
return getRealTempBasal().getPlannedRemainingMinutes(); return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes();
if (isExtendedBoluslInProgress() && useExtendedBoluses) if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses)
return getExtendedBolus().getPlannedRemainingMinutes(); return MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).getPlannedRemainingMinutes();
return 0; return 0;
} }
@Override public TempBasal getTempBasal(long time) {
public TempBasal getTempBasal() { TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time);
if (isRealTempBasalInProgress())
return getRealTempBasal();
if (isExtendedBoluslInProgress() && useExtendedBoluses)
return getExtendedBolus();
return null;
}
public TempBasal getTempBasal(Date time) {
TempBasal temp = MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time);
if (temp != null) return temp; if (temp != null) return temp;
if (useExtendedBoluses) if (useExtendedBoluses)
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time); return MainApp.getConfigBuilder().getExtendedBolus(time);
return null; return null;
} }
public TempBasal getRealTempBasal() {
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
}
@Override @Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
@ -429,13 +395,13 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (doTempOff) { if (doTempOff) {
// If extended in progress // If extended in progress
if (isExtendedBoluslInProgress() && useExtendedBoluses) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
return cancelExtendedBolus(); return cancelExtendedBolus();
} }
// If temp in progress // If temp in progress
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
return cancelRealTempBasal(); return cancelRealTempBasal();
@ -458,7 +424,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
percentRate = 200; percentRate = 200;
} }
// If extended in progress // If extended in progress
if (isExtendedBoluslInProgress() && useExtendedBoluses) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
result = cancelExtendedBolus(); result = cancelExtendedBolus();
@ -468,9 +434,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
} }
// Check if some temp is already in progress // Check if some temp is already in progress
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
// Correct basal already set ? // Correct basal already set ?
if (getRealTempBasal().percent == percentRate) { if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = getTempBasalAbsoluteRate(); result.absolute = getTempBasalAbsoluteRate();
@ -499,7 +465,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
if (doExtendedTemp) { if (doExtendedTemp) {
// Check if some temp is already in progress // Check if some temp is already in progress
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
result = cancelRealTempBasal(); result = cancelRealTempBasal();
@ -520,12 +486,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) { if (Config.logPumpActions) {
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min"); log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min");
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h"); log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
} }
// Compare with extended rate in progress // Compare with extended rate in progress
if (isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set // correct extended already set
result.success = true; result.success = true;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
@ -650,9 +616,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public PumpEnactResult cancelTempBasal() { public PumpEnactResult cancelTempBasal() {
if (isRealTempBasalInProgress()) if (MainApp.getConfigBuilder().isTempBasalInProgress())
return cancelRealTempBasal(); return cancelRealTempBasal();
if (isExtendedBoluslInProgress()) if (MainApp.getConfigBuilder().isExtendedBoluslInProgress())
return cancelExtendedBolus(); return cancelExtendedBolus();
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = true; result.success = true;
@ -740,7 +706,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
extended.put("PumpIOB", getDanaRPump().iob); extended.put("PumpIOB", getDanaRPump().iob);
extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount);
TempBasal tb = getTempBasal(); TempBasal tb = getTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate());
extended.put("TempBasalStart", tb.timeStart.toLocaleString()); extended.put("TempBasalStart", tb.timeStart.toLocaleString());
@ -867,11 +833,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (getDanaRPump().lastBolusTime.getTime() != 0) { if (getDanaRPump().lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n";
} }
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
ret += "Temp: " + getRealTempBasal().toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n";
} }
if (isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
ret += "Extended: " + getExtendedBolus().toString() + "\n"; ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n";
} }
if (!veryShort){ if (!veryShort){
ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n"; ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n";

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -63,14 +64,14 @@ public class MsgStatusBolusExtended extends MessageBase {
} }
public static void updateExtendedBolusInDB() { public static void updateExtendedBolusInDB() {
DanaRPlugin danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
Date now = new Date(); Date now = new Date();
try { try {
if (danaRPlugin.isExtendedBoluslInProgress()) { if (treatmentsInterface.isExtendedBoluslInProgress()) {
TempBasal extendedBolus = danaRPlugin.getExtendedBolus(); TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
if (pump.isExtendedInProgress) { if (pump.isExtendedInProgress) {
if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) { if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) {
// Close current extended // Close current extended

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -54,14 +55,14 @@ public class MsgStatusTempBasal extends MessageBase {
} }
public static void updateTempBasalInDB() { public static void updateTempBasalInDB() {
DanaRPlugin DanaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRPump danaRPump = DanaRPump.getInstance(); DanaRPump danaRPump = DanaRPump.getInstance();
Date now = new Date(); Date now = new Date();
try { try {
if (DanaRPlugin.isRealTempBasalInProgress()) { if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal tempBasal = DanaRPlugin.getRealTempBasal(); TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
if (danaRPump.isTempBasalInProgress) { if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percent != danaRPump.tempBasalPercent) { if (tempBasal.percent != danaRPump.tempBasalPercent) {
// Close current temp basal // Close current temp basal

View file

@ -217,13 +217,13 @@ public class DanaRKoreanFragment extends Fragment {
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h"); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h");
if (danaRKoreanPlugin.isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(danaRKoreanPlugin.getRealTempBasal().toString()); tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString());
} else { } else {
tempBasalView.setText(""); tempBasalView.setText("");
} }
if (danaRKoreanPlugin.isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
extendedBolusView.setText(danaRKoreanPlugin.getExtendedBolus().toString()); extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString());
} else { } else {
extendedBolusView.setText(""); extendedBolusView.setText("");
} }

View file

@ -141,7 +141,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
pumpDescription.highTempBasalStyle = useExtendedBoluses ? PumpDescription.EXTENDED : PumpDescription.PERCENT; pumpDescription.highTempBasalStyle = useExtendedBoluses ? PumpDescription.EXTENDED : PumpDescription.PERCENT;
if (useExtendedBoluses != previousValue && isExtendedBoluslInProgress()) { if (useExtendedBoluses != previousValue && MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
sExecutionService.extendedBolusStop(); sExecutionService.extendedBolusStop();
} }
} }
@ -242,22 +242,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
} }
// Pump interface // Pump interface
@Override
public boolean isTempBasalInProgress() { public boolean isTempBasalInProgress() {
if (getRealTempBasal() != null) return true; if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()) != null) return true;
if (getExtendedBolus() != null && useExtendedBoluses) return true; if (MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()) != null && useExtendedBoluses) return true;
return false; return false;
} }
public boolean isRealTempBasalInProgress() {
return getRealTempBasal() != null; //TODO: crosscheck here
}
@Override
public boolean isExtendedBoluslInProgress() {
return getExtendedBolus() != null; //TODO: crosscheck here
}
@Override @Override
public int setNewBasalProfile(NSProfile profile) { public int setNewBasalProfile(NSProfile profile) {
if (sExecutionService == null) { if (sExecutionService == null) {
@ -322,7 +312,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override @Override
public double getTempBasalAbsoluteRate() { public double getTempBasalAbsoluteRate() {
TempBasal tb = getRealTempBasal(); TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
if (tb.isAbsolute) { if (tb.isAbsolute) {
return tb.absolute; return tb.absolute;
@ -332,7 +322,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
return tempRate; return tempRate;
} }
} }
TempBasal eb = getExtendedBolus(); TempBasal eb = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime());
if (eb != null && useExtendedBoluses) { if (eb != null && useExtendedBoluses) {
return getBaseBasalRate() + eb.absolute; return getBaseBasalRate() + eb.absolute;
} }
@ -341,39 +331,21 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override @Override
public double getTempBasalRemainingMinutes() { public double getTempBasalRemainingMinutes() {
if (isRealTempBasalInProgress()) if (MainApp.getConfigBuilder().isTempBasalInProgress())
return getRealTempBasal().getPlannedRemainingMinutes(); return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes();
if (isExtendedBoluslInProgress() && useExtendedBoluses) if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses)
return getExtendedBolus().getPlannedRemainingMinutes(); return MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).getPlannedRemainingMinutes();
return 0; return 0;
} }
@Override public TempBasal getTempBasal(long time) {
public TempBasal getTempBasal() { TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time);
if (isRealTempBasalInProgress())
return getRealTempBasal();
if (isExtendedBoluslInProgress() && useExtendedBoluses)
return getExtendedBolus();
return null;
}
public TempBasal getTempBasal(Date time) {
TempBasal temp = MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time);
if (temp != null) return temp; if (temp != null) return temp;
if (useExtendedBoluses) if (useExtendedBoluses)
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time); return MainApp.getConfigBuilder().getExtendedBolus(time);
return null; return null;
} }
public TempBasal getRealTempBasal() {
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
}
@Override @Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
@ -430,13 +402,13 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
if (doTempOff) { if (doTempOff) {
// If extended in progress // If extended in progress
if (isExtendedBoluslInProgress() && useExtendedBoluses) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)");
return cancelExtendedBolus(); return cancelExtendedBolus();
} }
// If temp in progress // If temp in progress
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
return cancelRealTempBasal(); return cancelRealTempBasal();
@ -459,7 +431,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
percentRate = 200; percentRate = 200;
} }
// If extended in progress // If extended in progress
if (isExtendedBoluslInProgress() && useExtendedBoluses) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
result = cancelExtendedBolus(); result = cancelExtendedBolus();
@ -469,9 +441,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
} }
} }
// Check if some temp is already in progress // Check if some temp is already in progress
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
// Correct basal already set ? // Correct basal already set ?
if (getRealTempBasal().percent == percentRate) { if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = getTempBasalAbsoluteRate(); result.absolute = getTempBasalAbsoluteRate();
@ -500,7 +472,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
} }
if (doExtendedTemp) { if (doExtendedTemp) {
// Check if some temp is already in progress // Check if some temp is already in progress
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
result = cancelRealTempBasal(); result = cancelRealTempBasal();
@ -521,12 +493,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) { if (Config.logPumpActions) {
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min"); log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min");
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h"); log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
} }
// Compare with extended rate in progress // Compare with extended rate in progress
if (isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set // correct extended already set
result.success = true; result.success = true;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
@ -651,9 +623,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
@Override @Override
public PumpEnactResult cancelTempBasal() { public PumpEnactResult cancelTempBasal() {
if (isRealTempBasalInProgress()) if (MainApp.getConfigBuilder().isTempBasalInProgress())
return cancelRealTempBasal(); return cancelRealTempBasal();
if (isExtendedBoluslInProgress()) if (MainApp.getConfigBuilder().isExtendedBoluslInProgress())
return cancelExtendedBolus(); return cancelExtendedBolus();
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = true; result.success = true;
@ -741,7 +713,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
extended.put("PumpIOB", getDanaRPump().iob); extended.put("PumpIOB", getDanaRPump().iob);
// extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); // extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString());
// extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); // extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount);
TempBasal tb = getTempBasal(); TempBasal tb = getTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate());
extended.put("TempBasalStart", tb.timeStart.toLocaleString()); extended.put("TempBasalStart", tb.timeStart.toLocaleString());
@ -868,11 +840,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
// if (getDanaRPump().lastBolusTime.getTime() != 0) { // if (getDanaRPump().lastBolusTime.getTime() != 0) {
// ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; // ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n";
// } // }
if (isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
ret += "Temp: " + getRealTempBasal().toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n";
} }
if (isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
ret += "Extended: " + getExtendedBolus().toString() + "\n"; ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n";
} }
if (!veryShort){ if (!veryShort){
ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n"; ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n";

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
@ -66,13 +67,14 @@ public class MsgStatusBolusExtended extends MessageBase {
public static void updateExtendedBolusInDB() { public static void updateExtendedBolusInDB() {
DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump(); DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump();
Date now = new Date(); Date now = new Date();
try { try {
if (DanaRKoreanPlugin.isExtendedBoluslInProgress()) { if (treatmentsInterface.isExtendedBoluslInProgress()) {
TempBasal extendedBolus = DanaRKoreanPlugin.getExtendedBolus(); TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
if (danaRKoreanPump.isExtendedInProgress) { if (danaRKoreanPump.isExtendedInProgress) {
if (extendedBolus.absolute != danaRKoreanPump.extendedBolusAbsoluteRate) { if (extendedBolus.absolute != danaRKoreanPump.extendedBolusAbsoluteRate) {
// Close current extended // Close current extended

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump;
@ -55,13 +56,14 @@ public class MsgStatusTempBasal extends MessageBase {
public static void updateTempBasalInDB() { public static void updateTempBasalInDB() {
DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump(); DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump();
Date now = new Date(); Date now = new Date();
try { try {
if (DanaRKoreanPlugin.isRealTempBasalInProgress()) { if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal tempBasal = DanaRKoreanPlugin.getRealTempBasal(); TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
if (danaRKoreanPump.isTempBasalInProgress) { if (danaRKoreanPump.isTempBasalInProgress) {
if (tempBasal.percent != danaRKoreanPump.tempBasalPercent) { if (tempBasal.percent != danaRKoreanPump.tempBasalPercent) {
// Close current temp basal // Close current temp basal

View file

@ -220,13 +220,13 @@ public class DanaRv2Fragment extends Fragment {
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
if (getPlugin().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(getPlugin().getTempBasal().toString()); tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString());
} else { } else {
tempBasalView.setText(""); tempBasalView.setText("");
} }
if (getPlugin().isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
extendedBolusView.setText(getPlugin().getExtendedBolus().toString()); extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString());
} else { } else {
extendedBolusView.setText(""); extendedBolusView.setText("");
} }

View file

@ -223,16 +223,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
} }
// Pump interface // Pump interface
@Override
public boolean isTempBasalInProgress() {
return getTempBasal() != null; //TODO: crosscheck here
}
@Override
public boolean isExtendedBoluslInProgress() {
return getExtendedBolus() != null; //TODO: crosscheck here
}
@Override @Override
public int setNewBasalProfile(NSProfile profile) { public int setNewBasalProfile(NSProfile profile) {
if (sExecutionService == null) { if (sExecutionService == null) {
@ -298,7 +288,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public double getTempBasalAbsoluteRate() { public double getTempBasalAbsoluteRate() {
TempBasal tb = getTempBasal(); TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
Double baseRate = getBaseBasalRate(); Double baseRate = getBaseBasalRate();
Double tempRate = baseRate * (tb.percent / 100d); Double tempRate = baseRate * (tb.percent / 100d);
@ -309,25 +299,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public double getTempBasalRemainingMinutes() { public double getTempBasalRemainingMinutes() {
if (isTempBasalInProgress()) if (MainApp.getConfigBuilder().isTempBasalInProgress())
return getTempBasal().getPlannedRemainingMinutes(); return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes();
return 0; return 0;
} }
public TempBasal getTempBasal(Date time) {
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time);
}
@Override
public TempBasal getTempBasal() {
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
}
@Override @Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
@ -383,7 +359,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
if (doTempOff) { if (doTempOff) {
// If temp in progress // If temp in progress
if (isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)");
return cancelTempBasal(); return cancelTempBasal();
@ -405,9 +381,9 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
if (percentRate > getPumpDescription().maxHighTempPercent) if (percentRate > getPumpDescription().maxHighTempPercent)
percentRate = getPumpDescription().maxHighTempPercent; percentRate = getPumpDescription().maxHighTempPercent;
// Check if some temp is already in progress // Check if some temp is already in progress
if (isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
// Correct basal already set ? // Correct basal already set ?
if (getTempBasal().percent == percentRate) { if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = getTempBasalAbsoluteRate(); result.absolute = getTempBasalAbsoluteRate();
@ -633,7 +609,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
extended.put("PumpIOB", getDanaRPump().iob); extended.put("PumpIOB", getDanaRPump().iob);
extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount);
TempBasal tb = getTempBasal(); TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate());
extended.put("TempBasalStart", tb.timeStart.toLocaleString()); extended.put("TempBasalStart", tb.timeStart.toLocaleString());
@ -761,11 +737,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
if (getDanaRPump().lastBolusTime.getTime() != 0) { if (getDanaRPump().lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n";
} }
if (isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
ret += "Temp: " + getTempBasal().toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n";
} }
if (isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
ret += "Extended: " + getExtendedBolus().toString() + "\n"; ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n";
} }
if (!veryShort) { if (!veryShort) {
ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n"; ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n";

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
@ -64,14 +65,14 @@ public class MsgStatusBolusExtended extends MessageBase {
} }
public static void updateExtendedBolusInDB() { public static void updateExtendedBolusInDB() {
DanaRv2Plugin danaRPlugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
Date now = new Date(); Date now = new Date();
try { try {
if (danaRPlugin.isExtendedBoluslInProgress()) { if (treatmentsInterface.isExtendedBoluslInProgress()) {
TempBasal extendedBolus = danaRPlugin.getExtendedBolus(); TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
if (pump.isExtendedInProgress) { if (pump.isExtendedInProgress) {
if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) { if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) {
// Close current extended // Close current extended

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
@ -61,14 +62,14 @@ public class MsgStatusTempBasal extends MessageBase {
} }
public static void updateTempBasalInDB() { public static void updateTempBasalInDB() {
DanaRv2Plugin danaRPlugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
DanaRPump danaRPump = DanaRPump.getInstance(); DanaRPump danaRPump = DanaRPump.getInstance();
Date now = new Date(); Date now = new Date();
try { try {
if (danaRPlugin.isTempBasalInProgress()) { if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal tempBasal = danaRPlugin.getTempBasal(); TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
if (danaRPump.isTempBasalInProgress) { if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percent != danaRPump.tempBasalPercent) { if (tempBasal.percent != danaRPump.tempBasalPercent) {
// Close current temp basal // Close current temp basal

View file

@ -138,16 +138,6 @@ public class MDIPlugin implements PluginBase, PumpInterface {
return false; return false;
} }
@Override
public boolean isTempBasalInProgress() {
return false;
}
@Override
public boolean isExtendedBoluslInProgress() {
return false;
}
@Override @Override
public int setNewBasalProfile(NSProfile profile) { public int setNewBasalProfile(NSProfile profile) {
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile(); // Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
@ -179,26 +169,11 @@ public class MDIPlugin implements PluginBase, PumpInterface {
return 0; return 0;
} }
@Override
public TempBasal getTempBasal() {
return null;
}
@Override
public TempBasal getExtendedBolus() {
return null;
}
@Override @Override
public double getTempBasalRemainingMinutes() { public double getTempBasalRemainingMinutes() {
return 0d; return 0d;
} }
@Override
public TempBasal getTempBasal(Date time) {
return null;
}
@Override @Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();

View file

@ -16,6 +16,8 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
@ -92,13 +94,13 @@ public class VirtualPumpFragment extends Fragment {
public void run() { public void run() {
basaBasalRateView.setText(virtualPumpPlugin.getBaseBasalRate() + "U"); basaBasalRateView.setText(virtualPumpPlugin.getBaseBasalRate() + "U");
if (virtualPumpPlugin.isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(virtualPumpPlugin.getTempBasal().toString()); tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString());
} else { } else {
tempBasalView.setText(""); tempBasalView.setText("");
} }
if (virtualPumpPlugin.isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
extendedBolusView.setText(virtualPumpPlugin.getExtendedBolus().toString()); extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString());
} else { } else {
extendedBolusView.setText(""); extendedBolusView.setText("");
} }

View file

@ -156,16 +156,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
return false; return false;
} }
@Override
public boolean isTempBasalInProgress() {
return getTempBasal() != null;
}
@Override
public boolean isExtendedBoluslInProgress() {
return getExtendedBolus() != null;
}
@Override @Override
public int setNewBasalProfile(NSProfile profile) { public int setNewBasalProfile(NSProfile profile) {
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile(); // Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
@ -199,40 +189,25 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
@Override @Override
public double getTempBasalAbsoluteRate() { public double getTempBasalAbsoluteRate() {
if (!isTempBasalInProgress()) if (!MainApp.getConfigBuilder().isTempBasalInProgress())
return 0; return 0;
if (getTempBasal().isAbsolute) { if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).isAbsolute) {
return getTempBasal().absolute; return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).absolute;
} else { } else {
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
if (profile == null) if (profile == null)
return defaultBasalValue; return defaultBasalValue;
Double baseRate = profile.getBasal(profile.secondsFromMidnight()); Double baseRate = profile.getBasal(profile.secondsFromMidnight());
Double tempRate = baseRate * (getTempBasal().percent / 100d); Double tempRate = baseRate * (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent / 100d);
return baseRate + tempRate; return baseRate + tempRate;
} }
} }
@Override
public TempBasal getTempBasal() {
return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return ConfigBuilderPlugin.getActiveTreatments().getExtendedBolus(new Date());
}
@Override @Override
public double getTempBasalRemainingMinutes() { public double getTempBasalRemainingMinutes() {
if (!isTempBasalInProgress()) if (!MainApp.getConfigBuilder().isTempBasalInProgress())
return 0; return 0;
return getTempBasal().getPlannedRemainingMinutes(); return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes();
}
@Override
public TempBasal getTempBasal(Date time) {
return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(time);
} }
@Override @Override
@ -314,7 +289,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
result = cancelTempBasal(); result = cancelTempBasal();
if (!result.success) if (!result.success)
return result; return result;
@ -383,9 +358,9 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
result.success = true; result.success = true;
result.isTempCancel = true; result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
result.enacted = true; result.enacted = true;
TempBasal tb = getTempBasal(); TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
tb.timeEnd = new Date(); tb.timeEnd = new Date();
try { try {
MainApp.instance().getDbHelper().getDaoTempBasals().update(tb); MainApp.instance().getDbHelper().getDaoTempBasals().update(tb);
@ -407,8 +382,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
@Override @Override
public PumpEnactResult cancelExtendedBolus() { public PumpEnactResult cancelExtendedBolus() {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
TempBasal extendedBolus = getExtendedBolus(); TempBasal extendedBolus = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime());
extendedBolus.timeEnd = new Date(); extendedBolus.timeEnd = new Date();
try { try {
MainApp.instance().getDbHelper().getDaoTempBasals().update(extendedBolus); MainApp.instance().getDbHelper().getDaoTempBasals().update(extendedBolus);
@ -447,7 +422,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getActiveProfile().getProfile().getActiveProfile()); extended.put("ActiveProfile", MainApp.getConfigBuilder().getActiveProfile().getProfile().getActiveProfile());
} catch (Exception e) {} } catch (Exception e) {}
TempBasal tb; TempBasal tb;
if ((tb = getTempBasal()) != null) { if ((tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime())) != null) {
status.put("tempbasalpct", tb.percent); status.put("tempbasalpct", tb.percent);
status.put("tempbasalstart", DateUtil.toISOString(tb.timeStart)); status.put("tempbasalstart", DateUtil.toISOString(tb.timeStart));
status.put("tempbasalremainmin", tb.getPlannedRemainingMinutes()); status.put("tempbasalremainmin", tb.getPlannedRemainingMinutes());

View file

@ -254,10 +254,10 @@ public class SmsCommunicatorPlugin implements PluginBase {
if (glucoseStatus != null) if (glucoseStatus != null)
reply += MainApp.sResources.getString(R.string.sms_delta) + " " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "; reply += MainApp.sResources.getString(R.string.sms_delta) + " " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", ";
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments(); MainApp.getConfigBuilder().updateTotalIOBTreatments();
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round(); IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals(); MainApp.getConfigBuilder().updateTotalIOBTempBasals();
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round(); IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " + MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "

View file

@ -315,9 +315,14 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
lastTempBasalsCalculation = total; lastTempBasalsCalculation = total;
} }
@Override
public boolean isTempBasalInProgress() {
return getTempBasal(new Date().getTime()) != null;
}
@Nullable @Nullable
@Override @Override
public TempBasal getTempBasal(Date time) { public TempBasal getTempBasal(long time) {
checkForExpired(tempBasals); checkForExpired(tempBasals);
for (TempBasal t : tempBasals) { for (TempBasal t : tempBasals) {
if (t.isInProgress(time)) return t; if (t.isInProgress(time)) return t;
@ -326,7 +331,13 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
} }
@Override @Override
public TempBasal getExtendedBolus(Date time) { public boolean isExtendedBoluslInProgress() {
return getExtendedBolus(new Date().getTime()) != null; //TODO: crosscheck here
}
@Nullable
@Override
public TempBasal getExtendedBolus(long time) {
checkForExpired(extendedBoluses); checkForExpired(extendedBoluses);
for (TempBasal t : extendedBoluses) { for (TempBasal t : extendedBoluses) {
if (t.isInProgress(time)) return t; if (t.isInProgress(time)) return t;
@ -374,4 +385,5 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
initializeData(); initializeData();
} }
} }
} }

View file

@ -280,6 +280,16 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
return in5minback; return in5minback;
} }
@Override
public boolean isTempBasalInProgress() {
return getTempBasal(new Date().getTime()) != null;
}
@Override
public boolean isExtendedBoluslInProgress() {
return getExtendedBolus(new Date().getTime()) != null; //TODO: crosscheck here
}
@Subscribe @Subscribe
public void onStatusEvent(final EventTreatmentChange ev) { public void onStatusEvent(final EventTreatmentChange ev) {
initializeData(); initializeData();
@ -314,7 +324,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
@Nullable @Nullable
@Override @Override
public TempBasal getTempBasal(Date time) { public TempBasal getTempBasal(long time) {
checkForExpired(tempBasals); checkForExpired(tempBasals);
for (TempBasal t : tempBasals) { for (TempBasal t : tempBasals) {
if (t.isInProgress(time)) return t; if (t.isInProgress(time)) return t;
@ -323,7 +333,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
} }
@Override @Override
public TempBasal getExtendedBolus(Date time) { public TempBasal getExtendedBolus(long time) {
checkForExpired(extendedBoluses); checkForExpired(extendedBoluses);
for (TempBasal t : extendedBoluses) { for (TempBasal t : extendedBoluses) {
if (t.isInProgress(time)) return t; if (t.isInProgress(time)) return t;

View file

@ -32,6 +32,7 @@ import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
@ -345,8 +346,8 @@ public class WatchUpdaterService extends WearableListenerService implements
double beginBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(beginBasalSegmentTime))); double beginBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(beginBasalSegmentTime)));
double endBasalValue = beginBasalValue; double endBasalValue = beginBasalValue;
TempBasal tb1 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); TempBasal tb1 = MainApp.getConfigBuilder().getTempBasal(runningTime);
TempBasal tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); TempBasal tb2 = MainApp.getConfigBuilder().getTempBasal(runningTime);
double tb_before = beginBasalValue; double tb_before = beginBasalValue;
double tb_amount = beginBasalValue; double tb_amount = beginBasalValue;
long tb_start = runningTime; long tb_start = runningTime;
@ -372,7 +373,7 @@ public class WatchUpdaterService extends WearableListenerService implements
} }
//temps //temps
tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); tb2 = MainApp.getConfigBuilder().getTempBasal(runningTime);
if (tb1 == null && tb2 == null) { if (tb1 == null && tb2 == null) {
//no temp stays no temp //no temp stays no temp
@ -405,7 +406,7 @@ public class WatchUpdaterService extends WearableListenerService implements
basals.add(basalMap(beginBasalSegmentTime, runningTime, beginBasalValue)); basals.add(basalMap(beginBasalSegmentTime, runningTime, beginBasalValue));
} }
if(tb1 != null){ if(tb1 != null){
tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(now)); //use "now" to express current situation tb2 = MainApp.getConfigBuilder().getTempBasal(now); //use "now" to express current situation
if(tb2 == null) { if(tb2 == null) {
//express the cancelled temp by painting it down one minute early //express the cancelled temp by painting it down one minute early
temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount)); temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount));
@ -420,7 +421,7 @@ public class WatchUpdaterService extends WearableListenerService implements
} }
} }
} else { } else {
tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(now)); //use "now" to express current situation tb2 = MainApp.getConfigBuilder().getTempBasal(now); //use "now" to express current situation
if(tb2 != null) { if(tb2 != null) {
//onset at the end //onset at the end
double currentAmount = tb2.tempBasalConvertedToAbsolute(new Date(runningTime)); double currentAmount = tb2.tempBasalConvertedToAbsolute(new Date(runningTime));
@ -532,10 +533,10 @@ public class WatchUpdaterService extends WearableListenerService implements
} }
//Temp basal //Temp basal
PumpInterface pump = MainApp.getConfigBuilder(); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
if (pump.isTempBasalInProgress()) { if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal activeTemp = pump.getTempBasal(); TempBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime());
if (shortString) { if (shortString) {
status += activeTemp.toStringShort(); status += activeTemp.toStringShort();
} else { } else {
@ -544,10 +545,10 @@ public class WatchUpdaterService extends WearableListenerService implements
} }
//IOB //IOB
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments(); treatmentsInterface.updateTotalIOBTreatments();
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round(); IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals(); treatmentsInterface.updateTotalIOBTempBasals();
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round(); IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
if (mPrefs.getBoolean("wear_detailediob", true)) { if (mPrefs.getBoolean("wear_detailediob", true)) {

View file

@ -9,6 +9,8 @@ import android.support.annotation.NonNull;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
@ -20,6 +22,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@ -158,10 +161,10 @@ public class StatuslinePlugin implements PluginBase {
} }
//Temp basal //Temp basal
PumpInterface pump = MainApp.getConfigBuilder(); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
if (pump.isTempBasalInProgress()) { if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal activeTemp = pump.getTempBasal(); TempBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime());
if (shortString) { if (shortString) {
status += activeTemp.toStringShort(); status += activeTemp.toStringShort();
} else { } else {
@ -170,10 +173,10 @@ public class StatuslinePlugin implements PluginBase {
} }
//IOB //IOB
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments(); treatmentsInterface.updateTotalIOBTreatments();
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round(); IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals(); treatmentsInterface.updateTotalIOBTempBasals();
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round(); IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);

View file

@ -4,6 +4,7 @@ import org.json.JSONObject;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
@ -85,7 +86,7 @@ public class BolusWizard {
// Insulin from IOB // Insulin from IOB
// IOB calculation // IOB calculation
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments(); TreatmentsInterface treatments = MainApp.getConfigBuilder();
treatments.updateTotalIOBTreatments(); treatments.updateTotalIOBTreatments();
IobTotal bolusIob = treatments.getLastCalculationTreatments().round(); IobTotal bolusIob = treatments.getLastCalculationTreatments().round();
treatments.updateTotalIOBTempBasals(); treatments.updateTotalIOBTempBasals();