synchronize danar and danarv2 plugins

This commit is contained in:
Milos Kozak 2017-05-26 14:41:05 +02:00
parent b8b9827b61
commit 0973ef97ac
6 changed files with 68 additions and 72 deletions

View file

@ -376,8 +376,8 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue(); if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
else percentRate = Round.floorTo((double) percentRate, 10d).intValue(); else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
if (percentRate > 200) { if (percentRate > getPumpDescription().maxHighTempPercent) {
percentRate = 200; percentRate = getPumpDescription().maxHighTempPercent;
} }
// If extended in progress // If extended in progress
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) {
@ -801,7 +801,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
} }
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n";
} }
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {

View file

@ -804,7 +804,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
} }
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n";
} }
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {

View file

@ -208,7 +208,7 @@ public class DanaRv2Fragment extends Fragment {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@Override @Override
public void run() { public void run() {
DanaRPump pump = DanaRv2Plugin.getDanaRPump(); DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection.getTime() != 0) { if (pump.lastConnection.getTime() != 0) {
Long agoMsec = new Date().getTime() - pump.lastConnection.getTime(); Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
@ -219,7 +219,7 @@ public class DanaRv2Fragment extends Fragment {
Long agoMsec = new Date().getTime() - pump.lastBolusTime.getTime(); Long agoMsec = new Date().getTime() - pump.lastBolusTime.getTime();
double agoHours = agoMsec / 60d / 60d / 1000d; double agoHours = agoMsec / 60d / 60d / 1000d;
if (agoHours < 6) // max 6h back if (agoHours < 6) // max 6h back
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
else lastBolusView.setText(""); else lastBolusView.setText("");
} }

View file

@ -66,14 +66,10 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
public static DanaRv2ExecutionService sExecutionService; public static DanaRv2ExecutionService sExecutionService;
private static DanaRPump sDanaRPump = DanaRPump.getInstance(); private static DanaRPump pump = DanaRPump.getInstance();
public static PumpDescription pumpDescription = new PumpDescription(); public static PumpDescription pumpDescription = new PumpDescription();
public static DanaRPump getDanaRPump() {
return sDanaRPump;
}
public DanaRv2Plugin() { public DanaRv2Plugin() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
@ -209,12 +205,12 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
return getDanaRPump().lastConnection.getTime() > 0 && getDanaRPump().isExtendedBolusEnabled; return pump.lastConnection.getTime() > 0 && pump.isExtendedBolusEnabled;
} }
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return getDanaRPump().pumpSuspended; return pump.pumpSuspended;
} }
@Override @Override
@ -253,7 +249,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
public boolean isThisProfileSet(NSProfile profile) { public boolean isThisProfileSet(NSProfile profile) {
if (!isInitialized()) if (!isInitialized())
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
DanaRPump pump = getDanaRPump();
if (pump.pumpProfiles == null) if (pump.pumpProfiles == null)
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
int basalValues = pump.basal48Enable ? 48 : 24; int basalValues = pump.basal48Enable ? 48 : 24;
@ -272,7 +267,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public Date lastDataTime() { public Date lastDataTime() {
return getDanaRPump().lastConnection; return pump.lastConnection;
} }
@Override @Override
@ -284,7 +279,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public double getBaseBasalRate() { public double getBaseBasalRate() {
return getDanaRPump().currentBasal; return pump.currentBasal;
} }
@Override @Override
@ -327,7 +322,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) { public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
// Recheck pump status if older than 30 min // Recheck pump status if older than 30 min
if (getDanaRPump().lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime()) { if (pump.lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime()) {
doConnect("setTempBasalAbsolute old data"); doConnect("setTempBasalAbsolute old data");
} }
@ -415,28 +410,27 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
} }
if (percent > getPumpDescription().maxHighTempPercent) if (percent > getPumpDescription().maxHighTempPercent)
percent = getPumpDescription().maxHighTempPercent; percent = getPumpDescription().maxHighTempPercent;
if (getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) { if (pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; 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 = pump.tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent; result.percent = pump.tempBasalPercent;
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set"); log.debug("setTempBasalPercent: Correct value already set");
return result; return result;
} }
int durationInHours = Math.max(durationInMinutes / 60, 1); int durationInHours = Math.max(durationInMinutes / 60, 1);
boolean connectionOK = false; boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours);
connectionOK = sExecutionService.tempBasal(percent, durationInHours); if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
if (connectionOK && getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) {
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.isTempCancel = false;
result.duration = getDanaRPump().tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent; result.percent = pump.tempBasalPercent;
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK"); log.debug("setTempBasalPercent: OK");
@ -452,13 +446,13 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
public PumpEnactResult setHighTempBasalPercent(Integer percent) { public PumpEnactResult setHighTempBasalPercent(Integer percent) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
boolean connectionOK = sExecutionService.highTempBasal(percent); boolean connectionOK = sExecutionService.highTempBasal(percent);
if (connectionOK && getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
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.isTempCancel = false;
result.duration = getDanaRPump().tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent; result.percent = pump.tempBasalPercent;
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setHighTempBasalPercent: OK"); log.debug("setHighTempBasalPercent: OK");
@ -479,28 +473,28 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isExtendedInProgress && Math.abs(getDanaRPump().extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) { if (pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = false; result.enacted = false;
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.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;
result.isPercent = false; result.isPercent = false;
result.isTempCancel = false; result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + getDanaRPump().extendedBolusAmount + " Asked: " + insulin); log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
return result; return result;
} }
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
boolean connectionOK = sExecutionService.extendedBolus(insulin, durationInHalfHours); boolean connectionOK = sExecutionService.extendedBolus(insulin, durationInHalfHours);
if (connectionOK && getDanaRPump().isExtendedInProgress && Math.abs(getDanaRPump().extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) { if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
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.isTempCancel = false;
result.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;
result.bolusDelivered = getDanaRPump().extendedBolusAmount; result.bolusDelivered = pump.extendedBolusAmount;
result.isPercent = false; result.isPercent = false;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setExtendedBolus: OK"); log.debug("setExtendedBolus: OK");
@ -516,12 +510,12 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public PumpEnactResult cancelTempBasal() { public PumpEnactResult cancelTempBasal() {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isTempBasalInProgress) { if (pump.isTempBasalInProgress) {
sExecutionService.tempBasalStop(); sExecutionService.tempBasalStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true; result.isTempCancel = true;
} }
if (!getDanaRPump().isTempBasalInProgress) { if (!pump.isTempBasalInProgress) {
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);
@ -540,12 +534,12 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public PumpEnactResult cancelExtendedBolus() { public PumpEnactResult cancelExtendedBolus() {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isExtendedInProgress) { if (pump.isExtendedInProgress) {
sExecutionService.extendedBolusStop(); sExecutionService.extendedBolusStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true; result.isTempCancel = true;
} }
if (!getDanaRPump().isExtendedInProgress) { if (!pump.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);
if (Config.logPumpActions) if (Config.logPumpActions)
@ -577,21 +571,23 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus() {
if (getDanaRPump().lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) { if (pump.lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) {
return null; return null;
} }
JSONObject pump = new JSONObject(); JSONObject pumpjson = new JSONObject();
JSONObject battery = new JSONObject(); JSONObject battery = new JSONObject();
JSONObject status = new JSONObject(); JSONObject status = new JSONObject();
JSONObject extended = new JSONObject(); JSONObject extended = new JSONObject();
try { try {
battery.put("percent", getDanaRPump().batteryRemaining); battery.put("percent", pump.batteryRemaining);
status.put("status", getDanaRPump().pumpSuspended ? "suspended" : "normal"); status.put("status", pump.pumpSuspended ? "suspended" : "normal");
status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection)); status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", getDanaRPump().iob); extended.put("PumpIOB", pump.iob);
extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); if (pump.lastBolusTime.getTime() != 0) {
extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", pump.lastBolusAmount);
}
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime())); extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime()));
@ -610,20 +606,20 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
} catch (Exception e) { } catch (Exception e) {
} }
pump.put("battery", battery); pumpjson.put("battery", battery);
pump.put("status", status); pumpjson.put("status", status);
pump.put("extended", extended); pumpjson.put("extended", extended);
pump.put("reservoir", (int) getDanaRPump().reservoirRemainingUnits); pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
pump.put("clock", DateUtil.toISOString(new Date())); pumpjson.put("clock", DateUtil.toISOString(new Date()));
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
return pump; return pumpjson;
} }
@Override @Override
public String deviceID() { public String deviceID() {
return getDanaRPump().serialNumber; return pump.serialNumber;
} }
@Override @Override
@ -659,9 +655,9 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public Double applyBasalConstraints(Double absoluteRate) { public Double applyBasalConstraints(Double absoluteRate) {
double origAbsoluteRate = absoluteRate; double origAbsoluteRate = absoluteRate;
if (getDanaRPump() != null) { if (pump != null) {
if (absoluteRate > getDanaRPump().maxBasal) { if (absoluteRate > pump.maxBasal) {
absoluteRate = getDanaRPump().maxBasal; absoluteRate = pump.maxBasal;
if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit) if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit)
log.debug("Limiting rate " + origAbsoluteRate + "U/h by pump constraint to " + absoluteRate + "U/h"); log.debug("Limiting rate " + origAbsoluteRate + "U/h by pump constraint to " + absoluteRate + "U/h");
} }
@ -685,9 +681,9 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Override @Override
public Double applyBolusConstraints(Double insulin) { public Double applyBolusConstraints(Double insulin) {
double origInsulin = insulin; double origInsulin = insulin;
if (getDanaRPump() != null) { if (pump != null) {
if (insulin > getDanaRPump().maxBolus) { if (insulin > pump.maxBolus) {
insulin = getDanaRPump().maxBolus; insulin = pump.maxBolus;
if (Config.logConstraintsChanges && origInsulin != Constants.bolusOnlyForCheckLimit) if (Config.logConstraintsChanges && origInsulin != Constants.bolusOnlyForCheckLimit)
log.debug("Limiting bolus " + origInsulin + "U by pump constraint to " + insulin + "U"); log.debug("Limiting bolus " + origInsulin + "U by pump constraint to " + insulin + "U");
} }
@ -708,7 +704,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
@Nullable @Nullable
@Override @Override
public NSProfile getProfile() { public NSProfile getProfile() {
DanaRPump pump = getDanaRPump();
if (pump.lastSettingsRead.getTime() == 0) if (pump.lastSettingsRead.getTime() == 0)
return null; // no info now return null; // no info now
return pump.createConvertedProfile(); return pump.createConvertedProfile();
@ -717,13 +712,13 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
// Reply for sms communicator // Reply for sms communicator
public String shortStatus(boolean veryShort) { public String shortStatus(boolean veryShort) {
String ret = ""; String ret = "";
if (getDanaRPump().lastConnection.getTime() != 0) { if (pump.lastConnection.getTime() != 0) {
Long agoMsec = new Date().getTime() - getDanaRPump().lastConnection.getTime(); Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n"; ret += "LastConn: " + agoMin + " minago\n";
} }
if (getDanaRPump().lastBolusTime.getTime() != 0) { if (pump.lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
} }
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n";
@ -732,11 +727,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).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(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
} }
ret += "IOB: " + getDanaRPump().iob + "U\n"; ret += "IOB: " + pump.iob + "U\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(getDanaRPump().reservoirRemainingUnits) + "U\n"; ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
ret += "Batt: " + getDanaRPump().batteryRemaining + "\n"; ret += "Batt: " + pump.batteryRemaining + "\n";
return ret; return ret;
} }
// TODO: daily total constraint // TODO: daily total constraint

View file

@ -14,6 +14,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
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.comm.MessageHashTable_v2; import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable_v2;
import info.nightscout.utils.CRC; import info.nightscout.utils.CRC;
@ -177,7 +178,7 @@ public class SerialIOThread extends Thread {
if (!message.received) { if (!message.received) {
log.warn("Reply not received " + message.getMessageName()); log.warn("Reply not received " + message.getMessageName());
if (message.getCommand() == 0xF0F1) { if (message.getCommand() == 0xF0F1) {
DanaRv2Plugin.getDanaRPump().isNewPump = false; DanaRPump.getInstance().isNewPump = false;
log.debug("Old firmware detected"); log.debug("Old firmware detected");
} }
} }

View file

@ -90,7 +90,7 @@ public class DanaRv2ExecutionService extends Service {
public DanaRv2ExecutionService() { public DanaRv2ExecutionService() {
registerBus(); registerBus();
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED)); MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
danaRPump = DanaRv2Plugin.getDanaRPump(); danaRPump = DanaRPump.getInstance();
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRv2ExecutionService"); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRv2ExecutionService");