reuse predefined descriptions in real drivers

This commit is contained in:
Milos Kozak 2018-08-23 19:36:56 +02:00
parent b7950322c8
commit 9419b8c4d1
10 changed files with 32 additions and 206 deletions

View file

@ -61,6 +61,8 @@ import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
@ -85,42 +87,6 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
private final static PumpDescription pumpDescription = new PumpDescription();
static {
// these properties can't be changed on the pump, some via desktop configuration software
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.1d;
pumpDescription.isExtendedBolusCapable = false;
pumpDescription.extendedBolusStep = 0.1d;
pumpDescription.extendedBolusDurationStep = 15;
pumpDescription.extendedBolusMaxDuration = 12 * 60;
pumpDescription.isTempBasalCapable = true;
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = 500;
pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 15;
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = true;
pumpDescription.basalStep = 0.01d;
pumpDescription.basalMinimumRate = 0.05d;
pumpDescription.isRefillingCapable = true;
pumpDescription.storesCarbInfo = false;
pumpDescription.is30minBasalRatesCapable = false;
pumpDescription.supportsTDDs = true;
pumpDescription.needsManualTDDLoad = true;
}
@NonNull
private final RuffyCommands ruffyScripter;
@ -173,6 +139,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
.description(R.string.description_pump_combo)
);
ruffyScripter = new RuffyScripter(MainApp.instance().getApplicationContext());
PumpUtil.setPumpDescription(pumpDescription, PumpType.getByDescription("Accu-Chek Combo"));
}
public ComboPump getPump() {

View file

@ -18,8 +18,9 @@ public enum PumpCapability {
// grouped by pump
VirtualPumpCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill), //
ComboCapabilities(Bolus, TempBasal, BasalProfileSet, Refill, StoreCarbInfo, TDD, ManualTDDLoad), //
DanaCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, StoreCarbInfo, TDD, ManualTDDLoad), //
ComboCapabilities(Bolus, TempBasal, BasalProfileSet, Refill, TDD, ManualTDDLoad), //
DanaCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, TDD, ManualTDDLoad), //
DanaWithHistoryCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, StoreCarbInfo, TDD, ManualTDDLoad), //
InsightCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill,TDD,BasalRate30min), //
@ -28,9 +29,6 @@ public enum PumpCapability {
BasalRate_Duration30minAllowed, //
BasalRate_Duration15and30minAllowed(BasalRate_Duration15minAllowed, BasalRate_Duration30minAllowed), //
BasalRate_Duration15and30minNotAllowed, //
;
PumpCapability[] children;

View file

@ -78,7 +78,7 @@ public enum PumpType {
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10f, 60, 24*60, 0f, 200f), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.04f, 0.01f, null, PumpCapability.DanaCapabilities),
0.04f, 0.01f, null, PumpCapability.DanaWithHistoryCapabilities),
DanaRv2("DanaRv2", DanaRS),

View file

@ -14,6 +14,9 @@ public class PumpUtil {
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
{
// reset
pumpDescription.resetSettings();
PumpCapability pumpCapability = pumpType.getPumpCapability();
pumpDescription.isBolusCapable = pumpCapability.hasCapability(PumpCapability.Bolus);

View file

@ -21,9 +21,10 @@ 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.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
@ -47,35 +48,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
public DanaRPlugin() {
super();
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.05d;
pumpDescription.isExtendedBolusCapable = true;
pumpDescription.extendedBolusStep = 0.05d;
pumpDescription.extendedBolusDurationStep = 30;
pumpDescription.extendedBolusMaxDuration = 8 * 60;
pumpDescription.isTempBasalCapable = true;
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = 200;
pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 60;
pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = true;
pumpDescription.basalStep = 0.01d;
pumpDescription.basalMinimumRate = 0.04d;
pumpDescription.isRefillingCapable = true;
pumpDescription.storesCarbInfo = false;
pumpDescription.supportsTDDs = true;
pumpDescription.needsManualTDDLoad = true;
PumpUtil.setPumpDescription(pumpDescription, PumpType.getByDescription("DanaR"));
}
@Override

View file

@ -21,9 +21,10 @@ 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.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart;
@ -50,35 +51,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
pluginDescription.description(R.string.description_pump_dana_r_korean);
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.1d;
pumpDescription.isExtendedBolusCapable = true;
pumpDescription.extendedBolusStep = 0.05d;
pumpDescription.extendedBolusDurationStep = 30;
pumpDescription.extendedBolusMaxDuration = 8 * 60;
pumpDescription.isTempBasalCapable = true;
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = 200;
pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 60;
pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = true;
pumpDescription.basalStep = 0.01d;
pumpDescription.basalMinimumRate = 0.1d;
pumpDescription.isRefillingCapable = true;
pumpDescription.storesCarbInfo = false;
pumpDescription.supportsTDDs = true;
pumpDescription.needsManualTDDLoad = true;
PumpUtil.setPumpDescription(pumpDescription, PumpType.getByDescription("DanaR Korean"));
}
@Override

View file

@ -43,6 +43,8 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
@ -88,36 +90,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
.description(R.string.description_pump_dana_rs)
);
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.05d;
pumpDescription.isExtendedBolusCapable = true;
pumpDescription.extendedBolusStep = 0.05d;
pumpDescription.extendedBolusDurationStep = 30;
pumpDescription.extendedBolusMaxDuration = 8 * 60;
pumpDescription.isTempBasalCapable = true;
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = 200;
pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 60;
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = true;
pumpDescription.basalStep = 0.01d;
pumpDescription.basalMinimumRate = 0.04d;
pumpDescription.isRefillingCapable = true;
pumpDescription.storesCarbInfo = true;
pumpDescription.supportsTDDs = true;
pumpDescription.needsManualTDDLoad = true;
PumpUtil.setPumpDescription(pumpDescription, PumpType.getByDescription("DanaRS"));
}
@Override

View file

@ -18,10 +18,11 @@ import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpDescription;
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.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed;
@ -50,37 +51,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
pluginDescription.description(R.string.description_pump_dana_r_v2);
useExtendedBoluses = false;
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.05d;
pumpDescription.isExtendedBolusCapable = true;
pumpDescription.extendedBolusStep = 0.05d;
pumpDescription.extendedBolusDurationStep = 30;
pumpDescription.extendedBolusMaxDuration = 8 * 60;
pumpDescription.isTempBasalCapable = true;
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = 200;
pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 60;
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = true;
pumpDescription.basalStep = 0.01d;
pumpDescription.basalMinimumRate = 0.04d;
pumpDescription.isRefillingCapable = true;
pumpDescription.storesCarbInfo = true;
pumpDescription.supportsTDDs = true;
pumpDescription.needsManualTDDLoad = true;
PumpUtil.setPumpDescription(pumpDescription, PumpType.getByDescription("DanaRv2"));
}
@Override

View file

@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.BuildConfig;
@ -34,10 +33,13 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelBolusSilentlyTaskRunner;
import info.nightscout.androidaps.plugins.PumpInsight.connector.CancelTBRSilentlyTaskRunner;
import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector;
@ -53,7 +55,6 @@ import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.utils.SP;
import sugar.free.sightparser.applayer.descriptors.ActiveBolus;
import sugar.free.sightparser.applayer.descriptors.ActiveBolusType;
@ -121,38 +122,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
.description(R.string.description_pump_insight)
);
log("InsightPlugin instantiated");
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.01d; // specification says 0.05U up to 2U then 0.1U @ 2-5U 0.2U @ 10-20U 0.5U 10-20U (are these just UI restrictions? Yes, they are!)
pumpDescription.isExtendedBolusCapable = true;
pumpDescription.extendedBolusStep = 0.01d; // specification probably same as above
pumpDescription.extendedBolusDurationStep = 15; // 15 minutes up to 24 hours
pumpDescription.extendedBolusMaxDuration = 24 * 60;
pumpDescription.isTempBasalCapable = true;
//pumpDescription.tempBasalStyle = PumpDescription.PERCENT | PumpDescription.ABSOLUTE;
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = 250; // 0-250%
pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 15; // 15 minutes up to 24 hours
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = true;
pumpDescription.is30minBasalRatesCapable = true;
pumpDescription.basalStep = 0.01d;
pumpDescription.basalMinimumRate = 0.02d;
pumpDescription.basalMaximumRate = 25d;
pumpDescription.isRefillingCapable = true;
pumpDescription.storesCarbInfo = false;
pumpDescription.supportsTDDs = true;
pumpDescription.needsManualTDDLoad = false;
PumpUtil.setPumpDescription(pumpDescription, PumpType.getByDescription("Accu-Chek Insight"));
}
@ -212,7 +182,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
@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);
@ -529,16 +499,16 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
log("Calculated requested rate: " + absoluteRate + " base rate: " + getBaseBasalRate() + " percentage: " + percent + "%");
try {
if (percent > 250) {
log ("Calculated rate is above 250%, switching to emulation using extended boluses");
log("Calculated rate is above 250%, switching to emulation using extended boluses");
cancelTempBasal(true);
if (!setExtendedBolus((absoluteRate - getBaseBasalRate()) / 60D * ((double) durationInMinutes), durationInMinutes).success) {
//Fallback to TBR if setting an extended bolus didn't work
log ("Setting an extended bolus didn't work, falling back to normal TBR");
log("Setting an extended bolus didn't work, falling back to normal TBR");
return setTempBasalPercent((int) percent, durationInMinutes, profile, true);
}
return new PumpEnactResult().success(true).enacted(true).absolute(absoluteRate).duration(durationInMinutes);
} else {
log ("Calculated rate is below or equal to 250%, using normal TBRs");
log("Calculated rate is below or equal to 250%, using normal TBRs");
cancelExtendedBolus();
return setTempBasalPercent((int) percent, durationInMinutes, profile, true);
}
@ -567,7 +537,8 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
.source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
updateGui();
if (L.isEnabled(L.PUMPCOMM)) log.debug("Set temp basal " + percent + "% for " + durationInMinutes + "m");
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set temp basal " + percent + "% for " + durationInMinutes + "m");
connector.requestHistorySync(5000);
connector.tryToGetPumpStatusAgain();
return new PumpEnactResult().success(true).enacted(true).percent(percent);

View file

@ -458,9 +458,6 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
if (L.isEnabled(L.PUMP))
log.debug("New pump configuration found ({}), changing from previous ({})", pumpTypeNew, pumpType);
// reset
pumpDescription.resetSettings();
PumpUtil.setPumpDescription(pumpDescription, pumpTypeNew);
this.pumpType = pumpTypeNew;