fix #1145 non-consistent singleton-pattern in DanaRPump

This commit is contained in:
Milos Kozak 2018-08-03 23:35:24 +02:00
parent 294253797c
commit 9a2df7b04c
6 changed files with 112 additions and 119 deletions

View file

@ -48,7 +48,6 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
protected AbstractDanaRExecutionService sExecutionService;
protected DanaRPump pump = DanaRPump.getInstance();
protected boolean useExtendedBoluses = false;
public PumpDescription pumpDescription = new PumpDescription();
@ -76,7 +75,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
@Override
public boolean isSuspended() {
return pump.pumpSuspended;
return DanaRPump.getInstance().pumpSuspended;
}
@Override
@ -125,6 +124,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
public boolean isThisProfileSet(Profile profile) {
if (!isInitialized())
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
DanaRPump pump = DanaRPump.getInstance();
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;
@ -144,12 +144,12 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
@Override
public Date lastDataTime() {
return new Date(pump.lastConnection);
return new Date(DanaRPump.getInstance().lastConnection);
}
@Override
public double getBaseBasalRate() {
return pump.currentBasal;
return DanaRPump.getInstance().currentBasal;
}
@Override
@ -163,6 +163,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
if (percent < 0) {
@ -212,6 +213,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
@Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
DanaRPump pump = DanaRPump.getInstance();
insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
@ -262,7 +264,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
result.enacted = true;
result.isTempCancel = true;
}
if (!pump.isExtendedInProgress) {
if (!DanaRPump.getInstance().isExtendedInProgress) {
result.success = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (L.isEnabled(L.PUMP))
@ -280,8 +282,8 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
public void connect(String from) {
if (sExecutionService != null) {
sExecutionService.connect();
pumpDescription.basalStep = pump.basalStep;
pumpDescription.bolusStep = pump.bolusStep;
pumpDescription.basalStep = DanaRPump.getInstance().basalStep;
pumpDescription.bolusStep = DanaRPump.getInstance().bolusStep;
}
}
@ -309,13 +311,14 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
public void getPumpStatus() {
if (sExecutionService != null) {
sExecutionService.getPumpStatus();
pumpDescription.basalStep = pump.basalStep;
pumpDescription.bolusStep = pump.bolusStep;
pumpDescription.basalStep = DanaRPump.getInstance().basalStep;
pumpDescription.bolusStep = DanaRPump.getInstance().bolusStep;
}
}
@Override
public JSONObject getJSONStatus(Profile profile, String profilename) {
DanaRPump pump = DanaRPump.getInstance();
long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
return null;
@ -365,7 +368,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
@Override
public String deviceID() {
return pump.serialNumber;
return DanaRPump.getInstance().serialNumber;
}
@Override
@ -388,8 +391,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
@Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
if (pump != null)
absoluteRate.setIfSmaller(pump.maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), pump.maxBasal, MainApp.gs(R.string.pumplimit)), this);
absoluteRate.setIfSmaller(DanaRPump.getInstance().maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), DanaRPump.getInstance().maxBasal, MainApp.gs(R.string.pumplimit)), this);
return absoluteRate;
}
@ -403,27 +405,26 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
@Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
if (pump != null)
insulin.setIfSmaller(pump.maxBolus, String.format(MainApp.gs(R.string.limitingbolus), pump.maxBolus, MainApp.gs(R.string.pumplimit)), this);
insulin.setIfSmaller(DanaRPump.getInstance().maxBolus, String.format(MainApp.gs(R.string.limitingbolus), DanaRPump.getInstance().maxBolus, MainApp.gs(R.string.pumplimit)), this);
return insulin;
}
@Nullable
@Override
public ProfileStore getProfile() {
if (pump.lastSettingsRead == 0)
if (DanaRPump.getInstance().lastSettingsRead == 0)
return null; // no info now
return pump.createConvertedProfile();
return DanaRPump.getInstance().createConvertedProfile();
}
@Override
public String getUnits() {
return pump.getUnits();
return DanaRPump.getInstance().getUnits();
}
@Override
public String getProfileName() {
return pump.createConvertedProfileName();
return DanaRPump.getInstance().createConvertedProfileName();
}
@Override
@ -433,6 +434,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
// Reply for sms communicator
public String shortStatus(boolean veryShort) {
DanaRPump pump = DanaRPump.getInstance();
String ret = "";
if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.PumpDanaR;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
@ -18,16 +17,16 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.Round;
import info.nightscout.utils.SP;
@ -47,7 +46,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
public DanaRPlugin() {
super();
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.05d;
@ -87,20 +86,16 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(R.string.allow_hardware_pump_text)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setPositiveButton(R.string.yes, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
}
});
builder.create().show();
}
@ -149,7 +144,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
public void onStatusEvent(final EventPreferenceChange s) {
if (isEnabled(PluginType.PUMP)) {
boolean previousValue = useExtendedBoluses;
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
sExecutionService.extendedBolusStop();
@ -176,6 +171,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
@Override
public boolean isInitialized() {
DanaRPump pump = DanaRPump.getInstance();
return pump.lastConnection > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0;
}
@ -221,6 +217,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
// connect("setTempBasalAbsolute old data");
//}
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
@ -381,7 +378,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
return result;
}
public PumpEnactResult cancelRealTempBasal() {
private PumpEnactResult cancelRealTempBasal() {
PumpEnactResult result = new PumpEnactResult();
TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null) {
@ -389,7 +386,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
result.enacted = true;
result.isTempCancel = true;
}
if (!pump.isTempBasalInProgress) {
if (!DanaRPump.getInstance().isTempBasalInProgress) {
result.success = true;
result.isTempCancel = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.PumpDanaRKorean;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
@ -26,6 +25,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
@ -49,7 +49,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
public DanaRKoreanPlugin() {
pluginDescription.description(R.string.description_pump_dana_r_korean);
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.1d;
@ -89,20 +89,16 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(R.string.allow_hardware_pump_text)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setPositiveButton(R.string.yes, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
}
});
builder.create().show();
}
@ -152,7 +148,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
public void onStatusEvent(final EventPreferenceChange s) {
if (isEnabled(PluginType.PUMP)) {
boolean previousValue = useExtendedBoluses;
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
sExecutionService.extendedBolusStop();
@ -179,6 +175,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
@Override
public boolean isInitialized() {
DanaRPump pump = DanaRPump.getInstance();
return pump.lastConnection > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled;
}
@ -224,6 +221,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
// connect("setTempBasalAbsolute old data");
//}
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
@ -384,7 +382,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
return result;
}
public PumpEnactResult cancelRealTempBasal() {
private PumpEnactResult cancelRealTempBasal() {
PumpEnactResult result = new PumpEnactResult();
TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null) {
@ -392,7 +390,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
result.enacted = true;
result.isTempCancel = true;
}
if (!pump.isTempBasalInProgress) {
if (!DanaRPump.getInstance().isTempBasalInProgress) {
result.success = true;
result.isTempCancel = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.PumpDanaRS;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
@ -74,15 +73,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
return plugin;
}
public static DanaRSService danaRSService;
private static DanaRSService danaRSService;
public static String mDeviceAddress = "";
private static String mDeviceAddress = "";
public static String mDeviceName = "";
private static DanaRPump pump = DanaRPump.getInstance();
public static PumpDescription pumpDescription = new PumpDescription();
DanaRSPlugin() {
private DanaRSPlugin() {
super(new PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(DanaRFragment.class.getName())
@ -161,20 +159,16 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(R.string.allow_hardware_pump_text)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setPositiveButton(R.string.yes, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
}
});
builder.create().show();
}
@ -245,8 +239,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
public void getPumpStatus() {
if (danaRSService != null) {
danaRSService.getPumpStatus();
pumpDescription.basalStep = pump.basalStep;
pumpDescription.bolusStep = pump.bolusStep;
pumpDescription.basalStep = DanaRPump.getInstance().basalStep;
pumpDescription.bolusStep = DanaRPump.getInstance().bolusStep;
}
}
@ -271,8 +265,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
if (pump != null)
absoluteRate.setIfSmaller(pump.maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), pump.maxBasal, MainApp.gs(R.string.pumplimit)), this);
absoluteRate.setIfSmaller(DanaRPump.getInstance().maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), DanaRPump.getInstance().maxBasal, MainApp.gs(R.string.pumplimit)), this);
return absoluteRate;
}
@ -287,8 +280,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
if (pump != null)
insulin.setIfSmaller(pump.maxBolus, String.format(MainApp.gs(R.string.limitingbolus), pump.maxBolus, MainApp.gs(R.string.pumplimit)), this);
insulin.setIfSmaller(DanaRPump.getInstance().maxBolus, String.format(MainApp.gs(R.string.limitingbolus), DanaRPump.getInstance().maxBolus, MainApp.gs(R.string.pumplimit)), this);
return insulin;
}
@ -297,31 +289,31 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Nullable
@Override
public ProfileStore getProfile() {
if (pump.lastSettingsRead == 0)
if (DanaRPump.getInstance().lastSettingsRead == 0)
return null; // no info now
return pump.createConvertedProfile();
return DanaRPump.getInstance().createConvertedProfile();
}
@Override
public String getUnits() {
return pump.getUnits();
return DanaRPump.getInstance().getUnits();
}
@Override
public String getProfileName() {
return pump.createConvertedProfileName();
return DanaRPump.getInstance().createConvertedProfileName();
}
// Pump interface
@Override
public boolean isInitialized() {
return pump.lastConnection > 0 && pump.maxBasal > 0;
return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0;
}
@Override
public boolean isSuspended() {
return pump.pumpSuspended;
return DanaRPump.getInstance().pumpSuspended;
}
@Override
@ -369,6 +361,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
public boolean isThisProfileSet(Profile profile) {
if (!isInitialized())
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
DanaRPump pump = DanaRPump.getInstance();
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;
@ -388,12 +381,12 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public Date lastDataTime() {
return new Date(pump.lastConnection);
return new Date(DanaRPump.getInstance().lastConnection);
}
@Override
public double getBaseBasalRate() {
return pump.currentBasal;
return DanaRPump.getInstance().currentBasal;
}
@Override
@ -549,6 +542,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
if (percent < 0) {
@ -601,7 +595,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
return result;
}
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
private synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
boolean connectionOK = danaRSService.highTempBasal(percent);
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
@ -625,6 +620,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public synchronized PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
DanaRPump pump = DanaRPump.getInstance();
insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
@ -673,7 +669,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
result.enacted = true;
result.isTempCancel = true;
}
if (!pump.isTempBasalInProgress) {
if (!DanaRPump.getInstance().isTempBasalInProgress) {
result.success = true;
result.isTempCancel = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
@ -698,7 +694,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
result.enacted = true;
result.isTempCancel = true;
}
if (!pump.isExtendedInProgress) {
if (!DanaRPump.getInstance().isExtendedInProgress) {
result.success = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (L.isEnabled(L.PUMP))
@ -714,6 +710,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public JSONObject getJSONStatus(Profile profile, String profileName) {
DanaRPump pump = DanaRPump.getInstance();
long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
return null;
@ -763,7 +760,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public String deviceID() {
return pump.serialNumber;
return DanaRPump.getInstance().serialNumber;
}
@Override
@ -773,6 +770,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
@Override
public String shortStatus(boolean veryShort) {
DanaRPump pump = DanaRPump.getInstance();
String ret = "";
if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;

View file

@ -90,7 +90,6 @@ public class DanaRSService extends Service {
private IBinder mBinder = new LocalBinder();
private DanaRPump danaRPump = DanaRPump.getInstance();
private Treatment bolusingTreatment = null;
private long lastHistoryFetched = 0;
@ -130,6 +129,7 @@ public class DanaRSService extends Service {
}
public void getPumpStatus() {
DanaRPump danaRPump = DanaRPump.getInstance();
try {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus)));
@ -253,7 +253,7 @@ public class DanaRSService extends Service {
lastHistoryFetched = 0;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Events loaded");
danaRPump.lastConnection = System.currentTimeMillis();
DanaRPump.getInstance().lastConnection = System.currentTimeMillis();
return new PumpEnactResult().success(true);
}
@ -362,7 +362,7 @@ public class DanaRSService extends Service {
public boolean tempBasal(Integer percent, int durationInHours) {
if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
if (DanaRPump.getInstance().isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal());
SystemClock.sleep(500);
@ -377,7 +377,7 @@ public class DanaRSService extends Service {
}
public boolean highTempBasal(Integer percent) {
if (danaRPump.isTempBasalInProgress) {
if (DanaRPump.getInstance().isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal());
SystemClock.sleep(500);
@ -396,7 +396,7 @@ public class DanaRSService extends Service {
return false;
}
if (danaRPump.isTempBasalInProgress) {
if (DanaRPump.getInstance().isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal());
SystemClock.sleep(500);
@ -448,7 +448,7 @@ public class DanaRSService extends Service {
bleComm.sendMessage(msgSet);
DanaRS_Packet_Basal_Set_Profile_Number msgActivate = new DanaRS_Packet_Basal_Set_Profile_Number(0);
bleComm.sendMessage(msgActivate);
danaRPump.lastSettingsRead = 0; // force read full settings
DanaRPump.getInstance().lastSettingsRead = 0; // force read full settings
getPumpStatus();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.PumpDanaRv2;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
@ -24,6 +23,7 @@ import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
@ -141,31 +141,27 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
@Override
public boolean isInitialized() {
return pump.lastConnection > 0 && pump.maxBasal > 0;
return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0;
}
@Override
public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) {
boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false);
if (allowHardwarePump || context == null){
if (allowHardwarePump || context == null) {
pluginSwitcher.invoke();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(R.string.allow_hardware_pump_text)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setPositiveButton(R.string.yes, (dialog, id) -> {
pluginSwitcher.invoke();
SP.putBoolean("allow_hardware_pump", true);
if (L.isEnabled(L.PUMP))
log.debug("First time HW pump allowed!");
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setNegativeButton(R.string.cancel, (dialog, id) -> {
pluginSwitcher.cancel();
if (L.isEnabled(L.PUMP))
log.debug("User does not allow switching to HW pump!");
}
});
builder.create().show();
}
@ -191,7 +187,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
speed = 60;
break;
}
detailedBolusInfo.date = DateUtil.now() + (long)(speed * detailedBolusInfo.insulin * 1000);
detailedBolusInfo.date = DateUtil.now() + (long) (speed * detailedBolusInfo.insulin * 1000);
// clean carbs to prevent counting them as twice because they will picked up as another record
// I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
double carbs = detailedBolusInfo.carbs;
@ -323,6 +319,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
if (percent < 0) {
@ -375,7 +372,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
return result;
}
public PumpEnactResult setHighTempBasalPercent(Integer percent) {
private PumpEnactResult setHighTempBasalPercent(Integer percent) {
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
boolean connectionOK = sExecutionService.highTempBasal(percent);
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
@ -406,7 +404,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.enacted = true;
result.isTempCancel = true;
}
if (!pump.isTempBasalInProgress) {
if (!DanaRPump.getInstance().isTempBasalInProgress) {
result.success = true;
result.isTempCancel = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);