synchronize danar and danarkorean plugins
This commit is contained in:
parent
4b39578d9c
commit
b8b9827b61
|
@ -211,7 +211,7 @@ public class DanaRFragment extends Fragment {
|
|||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void run() {
|
||||
DanaRPump pump = DanaRPlugin.getDanaRPump();
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
if (pump.lastConnection.getTime() != 0) {
|
||||
Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
|
@ -222,7 +222,7 @@ public class DanaRFragment extends Fragment {
|
|||
Long agoMsec = new Date().getTime() - pump.lastBolusTime.getTime();
|
||||
double agoHours = agoMsec / 60d / 60d / 1000d;
|
||||
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("");
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati
|
|||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.Round;
|
||||
|
@ -65,15 +64,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
public static DanaRExecutionService sExecutionService;
|
||||
|
||||
|
||||
private static DanaRPump sDanaRPump = DanaRPump.getInstance();
|
||||
private static DanaRPump pump = DanaRPump.getInstance();
|
||||
private static boolean useExtendedBoluses = false;
|
||||
|
||||
public static PumpDescription pumpDescription = new PumpDescription();
|
||||
|
||||
public static DanaRPump getDanaRPump() {
|
||||
return sDanaRPump;
|
||||
}
|
||||
|
||||
public DanaRPlugin() {
|
||||
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
|
||||
|
||||
|
@ -223,12 +218,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return getDanaRPump().lastConnection.getTime() > 0 && getDanaRPump().isExtendedBolusEnabled;
|
||||
return pump.lastConnection.getTime() > 0 && pump.isExtendedBolusEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuspended() {
|
||||
return getDanaRPump().pumpSuspended;
|
||||
return pump.pumpSuspended;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -267,7 +262,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
public boolean isThisProfileSet(NSProfile profile) {
|
||||
if (!isInitialized())
|
||||
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
||||
DanaRPump pump = getDanaRPump();
|
||||
if (pump.pumpProfiles == null)
|
||||
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
||||
int basalValues = pump.basal48Enable ? 48 : 24;
|
||||
|
@ -286,7 +280,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
@Override
|
||||
public Date lastDataTime() {
|
||||
return getDanaRPump().lastConnection;
|
||||
return pump.lastConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -298,7 +292,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
return getDanaRPump().currentBasal;
|
||||
return pump.currentBasal;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -341,7 +335,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
// 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");
|
||||
}
|
||||
|
||||
|
@ -398,7 +392,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
// Check if some temp is already in progress
|
||||
if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) {
|
||||
// Correct basal already set ?
|
||||
if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percentRate == percentRate) {
|
||||
if (MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).percentRate == percentRate) {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRate();
|
||||
|
@ -448,17 +442,17 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
// What is current rate of extended bolusing in u/h?
|
||||
if (Config.logPumpActions) {
|
||||
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min");
|
||||
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
|
||||
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
|
||||
}
|
||||
|
||||
// Compare with extended rate in progress
|
||||
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
// correct extended already set
|
||||
result.success = true;
|
||||
result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
|
||||
result.absolute = pump.extendedBolusAbsoluteRate;
|
||||
result.enacted = false;
|
||||
result.duration = getDanaRPump().extendedBolusRemainingMinutes;
|
||||
result.duration = pump.extendedBolusRemainingMinutes;
|
||||
result.isPercent = false;
|
||||
result.isTempCancel = false;
|
||||
if (Config.logPumpActions)
|
||||
|
@ -501,14 +495,15 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
log.error("setTempBasalPercent: Invalid input");
|
||||
return result;
|
||||
}
|
||||
if (percent > getPumpDescription().maxHighTempPercent) percent = getPumpDescription().maxHighTempPercent;
|
||||
if (getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) {
|
||||
if (percent > getPumpDescription().maxHighTempPercent)
|
||||
percent = getPumpDescription().maxHighTempPercent;
|
||||
if (pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||
result.enacted = false;
|
||||
result.success = true;
|
||||
result.isTempCancel = false;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
result.duration = getDanaRPump().tempBasalRemainingMin;
|
||||
result.percent = getDanaRPump().tempBasalPercent;
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: Correct value already set");
|
||||
|
@ -516,13 +511,13 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
int durationInHours = Math.max(durationInMinutes / 60, 1);
|
||||
boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours);
|
||||
if (connectionOK && getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) {
|
||||
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||
result.enacted = true;
|
||||
result.success = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
result.isTempCancel = false;
|
||||
result.duration = getDanaRPump().tempBasalRemainingMin;
|
||||
result.percent = getDanaRPump().tempBasalPercent;
|
||||
result.duration = pump.tempBasalRemainingMin;
|
||||
result.percent = pump.tempBasalPercent;
|
||||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: OK");
|
||||
|
@ -543,28 +538,28 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||
|
||||
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.success = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
result.duration = getDanaRPump().extendedBolusRemainingMinutes;
|
||||
result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
|
||||
result.duration = pump.extendedBolusRemainingMinutes;
|
||||
result.absolute = pump.extendedBolusAbsoluteRate;
|
||||
result.isPercent = false;
|
||||
result.isTempCancel = false;
|
||||
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;
|
||||
}
|
||||
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||
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.success = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
result.isTempCancel = false;
|
||||
result.duration = getDanaRPump().extendedBolusRemainingMinutes;
|
||||
result.absolute = getDanaRPump().extendedBolusAbsoluteRate;
|
||||
result.bolusDelivered = getDanaRPump().extendedBolusAmount;
|
||||
result.duration = pump.extendedBolusRemainingMinutes;
|
||||
result.absolute = pump.extendedBolusAbsoluteRate;
|
||||
result.bolusDelivered = pump.extendedBolusAmount;
|
||||
result.isPercent = false;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setExtendedBolus: OK");
|
||||
|
@ -596,12 +591,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
public PumpEnactResult cancelRealTempBasal() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
if (getDanaRPump().isTempBasalInProgress) {
|
||||
if (pump.isTempBasalInProgress) {
|
||||
sExecutionService.tempBasalStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
}
|
||||
if (!getDanaRPump().isTempBasalInProgress) {
|
||||
if (!pump.isTempBasalInProgress) {
|
||||
result.success = true;
|
||||
result.isTempCancel = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
|
@ -620,12 +615,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
@Override
|
||||
public PumpEnactResult cancelExtendedBolus() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
if (getDanaRPump().isExtendedInProgress) {
|
||||
if (pump.isExtendedInProgress) {
|
||||
sExecutionService.extendedBolusStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
}
|
||||
if (!getDanaRPump().isExtendedInProgress) {
|
||||
if (!pump.isExtendedInProgress) {
|
||||
result.success = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
if (Config.logPumpActions)
|
||||
|
@ -657,21 +652,23 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
JSONObject pump = new JSONObject();
|
||||
JSONObject pumpjson = new JSONObject();
|
||||
JSONObject battery = new JSONObject();
|
||||
JSONObject status = new JSONObject();
|
||||
JSONObject extended = new JSONObject();
|
||||
try {
|
||||
battery.put("percent", getDanaRPump().batteryRemaining);
|
||||
status.put("status", getDanaRPump().pumpSuspended ? "suspended" : "normal");
|
||||
status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection));
|
||||
battery.put("percent", pump.batteryRemaining);
|
||||
status.put("status", pump.pumpSuspended ? "suspended" : "normal");
|
||||
status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
|
||||
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
||||
extended.put("PumpIOB", getDanaRPump().iob);
|
||||
extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString());
|
||||
extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount);
|
||||
extended.put("PumpIOB", pump.iob);
|
||||
if (pump.lastBolusTime.getTime() != 0) {
|
||||
extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
|
||||
extended.put("LastBolusAmount", pump.lastBolusAmount);
|
||||
}
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime());
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime()));
|
||||
|
@ -690,20 +687,20 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
pump.put("battery", battery);
|
||||
pump.put("status", status);
|
||||
pump.put("extended", extended);
|
||||
pump.put("reservoir", (int) getDanaRPump().reservoirRemainingUnits);
|
||||
pump.put("clock", DateUtil.toISOString(new Date()));
|
||||
pumpjson.put("battery", battery);
|
||||
pumpjson.put("status", status);
|
||||
pumpjson.put("extended", extended);
|
||||
pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
|
||||
pumpjson.put("clock", DateUtil.toISOString(new Date()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return pump;
|
||||
return pumpjson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deviceID() {
|
||||
return getDanaRPump().serialNumber;
|
||||
return pump.serialNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -739,9 +736,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
@Override
|
||||
public Double applyBasalConstraints(Double absoluteRate) {
|
||||
double origAbsoluteRate = absoluteRate;
|
||||
if (getDanaRPump() != null) {
|
||||
if (absoluteRate > getDanaRPump().maxBasal) {
|
||||
absoluteRate = getDanaRPump().maxBasal;
|
||||
if (pump != null) {
|
||||
if (absoluteRate > pump.maxBasal) {
|
||||
absoluteRate = pump.maxBasal;
|
||||
if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit)
|
||||
log.debug("Limiting rate " + origAbsoluteRate + "U/h by pump constraint to " + absoluteRate + "U/h");
|
||||
}
|
||||
|
@ -754,7 +751,8 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
public Integer applyBasalConstraints(Integer percentRate) {
|
||||
Integer origPercentRate = percentRate;
|
||||
if (percentRate < 0) percentRate = 0;
|
||||
if (percentRate > getPumpDescription().maxHighTempPercent) percentRate = getPumpDescription().maxHighTempPercent;
|
||||
if (percentRate > getPumpDescription().maxHighTempPercent)
|
||||
percentRate = getPumpDescription().maxHighTempPercent;
|
||||
if (!Objects.equals(percentRate, origPercentRate) && Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit))
|
||||
log.debug("Limiting percent rate " + origPercentRate + "% to " + percentRate + "%");
|
||||
return percentRate;
|
||||
|
@ -764,9 +762,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
@Override
|
||||
public Double applyBolusConstraints(Double insulin) {
|
||||
double origInsulin = insulin;
|
||||
if (getDanaRPump() != null) {
|
||||
if (insulin > getDanaRPump().maxBolus) {
|
||||
insulin = getDanaRPump().maxBolus;
|
||||
if (pump != null) {
|
||||
if (insulin > pump.maxBolus) {
|
||||
insulin = pump.maxBolus;
|
||||
if (Config.logConstraintsChanges && origInsulin != Constants.bolusOnlyForCheckLimit)
|
||||
log.debug("Limiting bolus " + origInsulin + "U by pump constraint to " + insulin + "U");
|
||||
}
|
||||
|
@ -787,7 +785,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
@Nullable
|
||||
@Override
|
||||
public NSProfile getProfile() {
|
||||
DanaRPump pump = getDanaRPump();
|
||||
if (pump.lastSettingsRead.getTime() == 0)
|
||||
return null; // no info now
|
||||
return pump.createConvertedProfile();
|
||||
|
@ -796,13 +793,13 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
// Reply for sms communicator
|
||||
public String shortStatus(boolean veryShort) {
|
||||
String ret = "";
|
||||
if (getDanaRPump().lastConnection.getTime() != 0) {
|
||||
Long agoMsec = new Date().getTime() - getDanaRPump().lastConnection.getTime();
|
||||
if (pump.lastConnection.getTime() != 0) {
|
||||
Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
ret += "LastConn: " + agoMin + " minago\n";
|
||||
}
|
||||
if (getDanaRPump().lastBolusTime.getTime() != 0) {
|
||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n";
|
||||
if (pump.lastBolusTime.getTime() != 0) {
|
||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
|
||||
}
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n";
|
||||
|
@ -811,14 +808,13 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n";
|
||||
}
|
||||
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 += "Reserv: " + DecimalFormatter.to0Decimal(getDanaRPump().reservoirRemainingUnits) + "U\n";
|
||||
ret += "Batt: " + getDanaRPump().batteryRemaining + "\n";
|
||||
ret += "IOB: " + pump.iob + "U\n";
|
||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
|
||||
ret += "Batt: " + pump.batteryRemaining + "\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: daily total constraint
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
||||
/**
|
||||
|
@ -72,7 +73,7 @@ public class ProfileViewDialog extends DialogFragment {
|
|||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DanaRPlugin.getDanaRPump().lastSettingsRead = new Date(0);
|
||||
DanaRPump.getInstance().lastSettingsRead = new Date(0);
|
||||
DanaRPlugin.doConnect("ProfileViewDialog");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -177,7 +177,7 @@ public class SerialIOThread extends Thread {
|
|||
if (!message.received) {
|
||||
log.warn("Reply not received " + message.getMessageName());
|
||||
if (message.getCommand() == 0xF0F1) {
|
||||
DanaRPlugin.getDanaRPump().isNewPump = false;
|
||||
DanaRPump.getInstance().isNewPump = false;
|
||||
log.debug("Old firmware detected");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public class DanaRExecutionService extends Service {
|
|||
public DanaRExecutionService() {
|
||||
registerBus();
|
||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||
danaRPump = DanaRPlugin.getDanaRPump();
|
||||
danaRPump = DanaRPump.getInstance();
|
||||
|
||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRExecutionService");
|
||||
|
|
|
@ -42,7 +42,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.Round;
|
||||
|
@ -237,13 +236,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
}
|
||||
|
||||
// Pump interface
|
||||
public boolean isTempBasalInProgress() {
|
||||
if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()) != null) return true;
|
||||
if (MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()) != null && useExtendedBoluses)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setNewBasalProfile(NSProfile profile) {
|
||||
if (sExecutionService == null) {
|
||||
|
@ -280,6 +272,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
for (int h = 0; h < basalValues; h++) {
|
||||
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
|
||||
Double profileValue = profile.getBasal(h * basalIncrement);
|
||||
if (profileValue == null) return true;
|
||||
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
|
||||
log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);
|
||||
return false;
|
||||
|
@ -305,14 +298,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
return pump.currentBasal;
|
||||
}
|
||||
|
||||
public TemporaryBasal getTempBasal(long time) {
|
||||
TemporaryBasal temp = MainApp.getConfigBuilder().getTempBasal(time);
|
||||
if (temp != null) return temp;
|
||||
if (useExtendedBoluses)
|
||||
return new TemporaryBasal(MainApp.getConfigBuilder().getExtendedBolus(time));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
|
@ -490,6 +475,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalAbsolute: Extended bolus set ok");
|
||||
result.absolute = result.absolute + getBaseBasalRate();
|
||||
result.originalExtendedAmount = extendedAmount;
|
||||
return result;
|
||||
}
|
||||
// We should never end here
|
||||
|
@ -593,8 +579,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
public PumpEnactResult cancelTempBasal() {
|
||||
if (MainApp.getConfigBuilder().isRealTempBasalInProgress())
|
||||
return cancelRealTempBasal();
|
||||
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses)
|
||||
return cancelExtendedBolus();
|
||||
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||
PumpEnactResult cancelEx = cancelExtendedBolus();
|
||||
cancelEx.isFakedTempBasal = true;
|
||||
return cancelEx;
|
||||
}
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
|
@ -675,12 +664,14 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
JSONObject extended = new JSONObject();
|
||||
try {
|
||||
battery.put("percent", pump.batteryRemaining);
|
||||
status.put("status", "normal");
|
||||
status.put("status", pump.pumpSuspended ? "suspended" : "normal");
|
||||
status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
|
||||
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
||||
extended.put("PumpIOB", pump.iob);
|
||||
// extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
|
||||
// extended.put("LastBolusAmount", pump.lastBolusAmount);
|
||||
if (pump.lastBolusTime.getTime() != 0) {
|
||||
extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
|
||||
extended.put("LastBolusAmount", pump.lastBolusAmount);
|
||||
}
|
||||
TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime());
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime()));
|
||||
|
@ -810,9 +801,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
ret += "LastConn: " + agoMin + " minago\n";
|
||||
}
|
||||
// if (pump.lastBolusTime.getTime() != 0) {
|
||||
// ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
|
||||
// }
|
||||
if (pump.lastBolusTime.getTime() != 0) {
|
||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
|
||||
}
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue