displaying basal fix

This commit is contained in:
Milos Kozak 2016-07-12 17:56:01 +02:00
parent 3bceeb368a
commit 76d42ef3fb
12 changed files with 68 additions and 20 deletions

View file

@ -38,7 +38,7 @@ public class PumpEnactResult extends Object implements Parcelable {
if (isTempCancel) { if (isTempCancel) {
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment + "\n" + ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment + "\n" +
MainApp.sResources.getString(R.string.tempcancel); MainApp.sResources.getString(R.string.canceltemp);
} else if (isPercent) { } else if (isPercent) {
ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted; ret += "\n" + MainApp.sResources.getString(R.string.enacted) + ": " + enacted;
ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment; ret += "\n" + MainApp.sResources.getString(R.string.comment) + ": " + comment;
@ -62,7 +62,7 @@ public class PumpEnactResult extends Object implements Parcelable {
if (isTempCancel) { if (isTempCancel) {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted; ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment + ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment +
"<br>" + MainApp.sResources.getString(R.string.tempcancel); "<br>" + MainApp.sResources.getString(R.string.canceltemp);
} else if (isPercent) { } else if (isPercent) {
ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted; ret += "<br><b>" + MainApp.sResources.getString(R.string.enacted) + "</b>: " + enacted;
ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment; ret += "<br><b>" + MainApp.sResources.getString(R.string.comment) + "</b>: " + comment;

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.interfaces;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Date;
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.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
@ -21,6 +23,7 @@ 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 getTempBasal();
TempBasal getExtendedBolus(); TempBasal getExtendedBolus();

View file

@ -263,6 +263,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
return activePump.getTempBasalRemainingMinutes(); return activePump.getTempBasalRemainingMinutes();
} }
@Override
public TempBasal getTempBasal(Date time) {
return activePump.getTempBasal(time);
}
@Override @Override
public TempBasal getTempBasal() { public TempBasal getTempBasal() {
return activePump.getTempBasal(); return activePump.getTempBasal();

View file

@ -77,7 +77,7 @@ public class DanaConnection {
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
// TODO: keepalive kills active connection
public DanaConnection(Bus bus) { public DanaConnection(Bus bus) {
danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class); danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class);
danaRFragment.setDanaConnection(this); danaRFragment.setDanaConnection(this);

View file

@ -338,6 +338,14 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
return null; return null;
} }
public TempBasal getTempBasal(Date time) {
TempBasal temp = MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(time);
if (temp != null) return temp;
if (useExtendedBoluses)
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(time);
return null;
}
public TempBasal getRealTempBasal() { public TempBasal getRealTempBasal() {
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date()); return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
} }
@ -406,6 +414,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
result.enacted = false; result.enacted = false;
result.percent = 100; result.percent = 100;
result.isPercent = true; result.isPercent = true;
result.isTempCancel = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: doTempOff OK"); log.debug("setTempBasalAbsolute: doTempOff OK");
return result; return result;
@ -438,6 +447,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
result.enacted = false; result.enacted = false;
result.duration = ((Double) getTempBasalRemainingMinutes()).intValue(); result.duration = ((Double) getTempBasalRemainingMinutes()).intValue();
result.isPercent = true; result.isPercent = true;
result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)");
return result; return result;
@ -492,6 +502,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
result.enacted = false; result.enacted = false;
result.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = getDanaRPump().extendedBolusRemainingMinutes;
result.isPercent = false; result.isPercent = false;
result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Correct extended already set"); log.debug("setTempBasalAbsolute: Correct extended already set");
return result; return result;
@ -524,6 +535,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder(); ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder();
percent = configBuilderFragment.applyBasalConstraints(percent); percent = configBuilderFragment.applyBasalConstraints(percent);
if (percent < 0) { if (percent < 0) {
result.isTempCancel = false;
result.enacted = false; result.enacted = false;
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_invalidinput); result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
@ -534,6 +546,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
if (getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) { if (getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = getDanaRPump().tempBasalRemainingMin; result.duration = getDanaRPump().tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent; result.percent = getDanaRPump().tempBasalPercent;
@ -549,6 +562,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
result.enacted = true; result.enacted = true;
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = getDanaRPump().tempBasalRemainingMin; result.duration = getDanaRPump().tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent; result.percent = getDanaRPump().tempBasalPercent;
result.isPercent = true; result.isPercent = true;
@ -578,6 +592,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
result.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = getDanaRPump().extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
result.isPercent = false; result.isPercent = false;
result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setExtendedBolus: Correct extended bolus already set"); log.debug("setExtendedBolus: Correct extended bolus already set");
return result; return result;
@ -589,6 +604,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
result.enacted = true; result.enacted = true;
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = getDanaRPump().extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
result.bolusDelivered = getDanaRPump().extendedBolusAmount; result.bolusDelivered = getDanaRPump().extendedBolusAmount;
@ -614,6 +630,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
result.success = true; result.success = true;
result.enacted = false; result.enacted = false;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = true;
return result; return result;
} }
@ -623,9 +640,11 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
if (getDanaRPump().isTempBasalInProgress) { if (getDanaRPump().isTempBasalInProgress) {
getDanaConnection().tempBasalStop(); getDanaConnection().tempBasalStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true;
} }
if (!getDanaRPump().isTempBasalInProgress) { if (!getDanaRPump().isTempBasalInProgress) {
result.success = true; result.success = true;
result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("cancelRealTempBasal: OK"); log.debug("cancelRealTempBasal: OK");
@ -633,6 +652,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
} else { } else {
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly);
result.isTempCancel = true;
log.error("cancelRealTempBasal: Failed to cancel temp basal"); log.error("cancelRealTempBasal: Failed to cancel temp basal");
return result; return result;
} }
@ -645,15 +665,18 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
if (getDanaRPump().isExtendedInProgress) { if (getDanaRPump().isExtendedInProgress) {
getDanaConnection().extendedBolusStop(); getDanaConnection().extendedBolusStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true;
} }
if (!getDanaRPump().isExtendedInProgress) { if (!getDanaRPump().isExtendedInProgress) {
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("cancelExtendedBolus: OK"); log.debug("cancelExtendedBolus: OK");
return result; return result;
} else { } else {
result.success = false; result.success = false;
result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly);
log.error("cancelExtendedBolus: Failed to cancel extended bolus"); log.error("cancelExtendedBolus: Failed to cancel extended bolus");
return result; return result;

View file

@ -24,19 +24,23 @@ public class APSResult implements Parcelable {
@Override @Override
public String toString() { public String toString() {
if (changeRequested) if (changeRequested)
return MainApp.sResources.getString(R.string.rate) + " " + DecimalFormatter.to2Decimal(rate) + " U/h\n" + return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h\n" +
MainApp.sResources.getString(R.string.duration) + " " + DecimalFormatter.to0Decimal(duration) + " min\n" + MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(duration) + " min\n" +
MainApp.sResources.getString(R.string.reason) + " " + reason; MainApp.sResources.getString(R.string.reason) + ": " + reason;
else else
return MainApp.sResources.getString(R.string.nochangerequested); return MainApp.sResources.getString(R.string.nochangerequested);
} }
public Spanned toSpanned() { public Spanned toSpanned() {
if (changeRequested) if (changeRequested) {
return Html.fromHtml("<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h<br>" + String ret = "";
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" + if (rate == 0 && duration == 0) ret = MainApp.sResources.getString(R.string.canceltemp);
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason); else
else ret = "<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h<br>" +
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" +
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason;
return Html.fromHtml(ret);
} else
return Html.fromHtml(MainApp.sResources.getString(R.string.nochangerequested)); return Html.fromHtml(MainApp.sResources.getString(R.string.nochangerequested));
} }
@ -70,7 +74,8 @@ public class APSResult implements Parcelable {
changeRequested = in.readInt() == 1; changeRequested = in.readInt() == 1;
} }
public APSResult() {} public APSResult() {
}
public APSResult clone() { public APSResult clone() {
APSResult newResult = new APSResult(); APSResult newResult = new APSResult();

View file

@ -27,12 +27,14 @@ import java.util.Date;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
public class ObjectivesFragment extends Fragment implements View.OnClickListener, PluginBase, ConstraintsInterface { public class ObjectivesFragment extends Fragment implements View.OnClickListener, PluginBase, ConstraintsInterface {
private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class); private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class);
@ -60,7 +62,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
@Override @Override
public boolean isVisibleInTabs(int type) { public boolean isVisibleInTabs(int type) {
return fragmentVisible; LoopFragment loopFragment = (LoopFragment) MainActivity.getSpecificPlugin(LoopFragment.class);
return fragmentVisible && loopFragment != null && loopFragment.isVisibleInTabs(type);
} }
@Override @Override

View file

@ -267,7 +267,14 @@ public class OverviewFragment extends Fragment implements PluginBase {
objectivesFragment.saveProgress(); objectivesFragment.saveProgress();
} }
} }
updateGUI(); Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateGUI();
}
});
} }
}); });
} }
@ -532,7 +539,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
long now = new Date().getTime(); long now = new Date().getTime();
List<BarDataPoint> basalArray = new ArrayList<BarDataPoint>(); List<BarDataPoint> basalArray = new ArrayList<BarDataPoint>();
for (long time = fromTime; time < now; time += 5 * 60 * 1000L) { for (long time = fromTime; time < now; time += 5 * 60 * 1000L) {
TempBasal tb = MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date(time)); TempBasal tb = MainApp.getConfigBuilder().getActivePump().getTempBasal(new Date(time));
if (tb != null) if (tb != null)
basalArray.add(new BarDataPoint(time, tb.tempBasalConvertedToAbsolute(new Date(time)), true)); basalArray.add(new BarDataPoint(time, tb.tempBasalConvertedToAbsolute(new Date(time)), true));
else else

View file

@ -230,9 +230,6 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
for (TempBasal t : tempBasals) { for (TempBasal t : tempBasals) {
if (t.isInProgress(time)) return t; if (t.isInProgress(time)) return t;
} }
if (useExtendedBoluses) {
return getExtendedBolus(time);
}
return null; return null;
} }

View file

@ -177,6 +177,11 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
return getTempBasal().getPlannedRemainingMinutes(); return getTempBasal().getPlannedRemainingMinutes();
} }
@Override
public TempBasal getTempBasal(Date time) {
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
}
@Override @Override
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) { public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();

View file

@ -232,6 +232,6 @@
<string name="reloadprofile">Obnovit profil</string> <string name="reloadprofile">Obnovit profil</string>
<string name="save">Uložit</string> <string name="save">Uložit</string>
<string name="success">Úspěch</string> <string name="success">Úspěch</string>
<string name="tempcancel">Zrušit dočasný bazál</string>
<string name="virtualpump_lastconnection_label">Poslední spojení:</string> <string name="virtualpump_lastconnection_label">Poslední spojení:</string>
<string name="canceltemp">Zrušit dočasný bazál</string>
</resources> </resources>

View file

@ -236,11 +236,11 @@
<string name="danar_valuenotsetproperly">Value not set properly</string> <string name="danar_valuenotsetproperly">Value not set properly</string>
<string name="reloadprofile">Reload profile</string> <string name="reloadprofile">Reload profile</string>
<string name="danar_viewprofile">View profile</string> <string name="danar_viewprofile">View profile</string>
<string name="tempcancel">Temp cancel</string>
<string name="enacted">Enacted</string> <string name="enacted">Enacted</string>
<string name="comment">Comment</string> <string name="comment">Comment</string>
<string name="success">Success</string> <string name="success">Success</string>
<string name="percent">Percent</string> <string name="percent">Percent</string>
<string name="absolute">Absolute</string> <string name="absolute">Absolute</string>
<string name="canceltemp">Cancel temp basal</string>
</resources> </resources>