Merge branch 'virtual_pump_Bug863' of https://github.com/andyrozman/AndroidAPS into andyrozman-virtual_pump_Bug863

This commit is contained in:
Milos Kozak 2018-08-23 17:53:28 +02:00
commit 2c5837a235
15 changed files with 957 additions and 0 deletions

View file

@ -45,4 +45,39 @@ public class PumpDescription {
public boolean supportsTDDs = false;
public boolean needsManualTDDLoad = true;
public void resetSettings()
{
isBolusCapable = true;
bolusStep = 0.1d;
isExtendedBolusCapable = true;
extendedBolusStep = 0.1d;
extendedBolusDurationStep = 30;
extendedBolusMaxDuration = 12 * 60;
isTempBasalCapable = true;
tempBasalStyle = PERCENT;
maxTempPercent = 200;
tempPercentStep = 10;
maxTempAbsolute = 10;
tempAbsoluteStep = 0.05d;
tempDurationStep = 60;
tempMaxDuration = 12 * 60;
tempDurationStep15mAllowed = false;
tempDurationStep30mAllowed = false;
isSetBasalProfileCapable = true;
basalStep = 0.01d;
basalMinimumRate = 0.04d;
is30minBasalRatesCapable = false;
isRefillingCapable = false;
storesCarbInfo = true;
supportsTDDs = false;
needsManualTDDLoad = true;
}
}

View file

@ -0,0 +1,49 @@
package info.nightscout.androidaps.plugins.PumpCommon.data;
/**
* Created by andy on 02/05/2018.
*/
public class DoseSettings {
private float step;
private int durationStep;
private int maxDuration;
private float minDose;
private Float maxDose;
public DoseSettings(float step, int durationStep, int maxDuration, float minDose, Float maxDose)
{
this.step = step;
this.durationStep = durationStep;
this.maxDuration = maxDuration;
this.minDose = minDose;
this.maxDose = maxDose;
}
public DoseSettings(float step, int durationStep, int maxDuration, float minDose)
{
this(step, durationStep, maxDuration, minDose, null);
}
public float getStep() {
return step;
}
public int getDurationStep() {
return durationStep;
}
public int getMaxDuration() {
return maxDuration;
}
public float getMinDose() {
return minDose;
}
public Float getMaxDose() {
return maxDose;
}
}

View file

@ -0,0 +1,90 @@
package info.nightscout.androidaps.plugins.PumpCommon.defs;
/**
* Created by andy on 02/05/2018.
*/
public enum DoseStepSize
{
ComboBasal( //
new DoseStepSizeEntry(0f, 1f, 0.01f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
InsightBolus(
new DoseStepSizeEntry(0f, 2f, 0.05f), //
new DoseStepSizeEntry(2f, 5f, 0.1f), //
new DoseStepSizeEntry(5f, 10f, 0.2f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.5f)),
MedtronicVeoBasal( //
new DoseStepSizeEntry(0f, 1f, 0.025f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
;
DoseStepSizeEntry[] entries;
DoseStepSize(DoseStepSizeEntry...entries)
{
this.entries = entries;
}
public float getStepSizeForAmount(float amount)
{
for (DoseStepSizeEntry entry : entries) {
if (entry.from <= amount && entry.to > amount)
return entry.value;
}
// should never come to this
return entries[entries.length-1].value;
}
public String getDescription() {
StringBuilder sb = new StringBuilder();
for (DoseStepSizeEntry entry : entries) {
sb.append(entry.value);
sb.append(" {");
sb.append(entry.from);
sb.append("-");
if (entry.to == Float.MAX_VALUE)
{
sb.append("~}");
}
else
{
sb.append(entry.to);
sb.append("}, ");
}
}
return sb.toString();
}
static class DoseStepSizeEntry
{
float from;
float to;
float value;
// to = this value is not included, but would actually mean <, so for rates between 0.025-0.975 u/h, we would have [from=0, to=10]
DoseStepSizeEntry(float from, float to, float value)
{
this.from = from;
this.to = to;
this.value = value;
}
}
}

View file

@ -0,0 +1,74 @@
package info.nightscout.androidaps.plugins.PumpCommon.defs;
/**
* Created by andy on 03/05/2018.
*/
public enum PumpCapability {
Bolus, // isBolusCapable
ExtendedBolus, // isExtendedBolusCapable
TempBasal, // isTempBasalCapable
BasalProfileSet, // isSetBasalProfileCapable
Refill, // isRefillingCapable
StoreCarbInfo, // storesCarbInfo
TDD, // supportsTDDs
ManualTDDLoad, // needsManualTDDLoad
BasalRate30min, // is30minBasalRatesCapable
// 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), //
InsightCapabilities(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill,TDD,BasalRate30min), //
// BasalRates (separately grouped)
BasalRate_Duration15minAllowed, //
BasalRate_Duration30minAllowed, //
BasalRate_Duration15and30minAllowed(BasalRate_Duration15minAllowed, BasalRate_Duration30minAllowed), //
BasalRate_Duration15and30minNotAllowed, //
;
PumpCapability[] children;
PumpCapability()
{
}
PumpCapability(PumpCapability...children)
{
this.children = children;
}
public boolean hasCapability(PumpCapability capability)
{
// we can only check presense of simple capabilities
if (capability.children != null)
return false;
if (this == capability)
return true;
if (this.children!=null)
{
for (PumpCapability child : children) {
if (child == capability)
return true;
}
return false;
}
else
return false;
}
}

View file

@ -0,0 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.defs;
/**
* Created by andy on 02/05/2018.
*/
public enum PumpTempBasalType {
Percent, //
Absolute,
}

View file

@ -0,0 +1,329 @@
package info.nightscout.androidaps.plugins.PumpCommon.defs;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings;
/**
* Created by andy on 02/05/2018.
*
* Most of this defintions is intended for VirtualPump only, but they can be used by other plugins.
*/
public enum PumpType {
GenericAAPS("Generic AAPS", 0.1f, null, //
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10,30, 24*60, 0f, 500f), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01f, 0.01f, null, PumpCapability.VirtualPumpCapabilities), //
// Cellnovo
Cellnovo1("Cellnovo", 0.05f, null, //
new DoseSettings(0.05f, 30, 24*60, 1f, null),
PumpTempBasalType.Percent,
new DoseSettings(5,30, 24*60, 0f, 200f), PumpCapability.BasalRate_Duration30minAllowed, //
0.05f, 0.05f, null, PumpCapability.VirtualPumpCapabilities), //
// Accu-Chek
AccuChekCombo("Accu-Chek Combo", 0.1f, null, //
new DoseSettings(0.1f, 15, 12*60, 0.1f), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12*60,0f, 500f), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01f, 0.1f, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), //
AccuChekSpirit("Accu-Chek Spirit", 0.1f, null, //
new DoseSettings(0.1f, 15, 12*60, 0.1f), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12*60,0f, 500f), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01f, 0.1f, null, PumpCapability.VirtualPumpCapabilities), //
AccuChekInsight("Accu-Chek Insight", 0.05f, DoseStepSize.InsightBolus, //
new DoseSettings(0.05f, 15, 24*60, 0.05f), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12*60,0f, 250f), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02f, 0.1f, null, PumpCapability.InsightCapabilities), //
// Animas
AnimasVibe("Animas Vibe", 0.05f, null, // AnimasBolus?
new DoseSettings(0.05f, 30, 12*60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24*60, 0f, 200f), PumpCapability.BasalRate_Duration30minAllowed, //
0.025f, 5f, 0f, null, PumpCapability.VirtualPumpCapabilities), //
AnimasPing("Animas Ping", AnimasVibe),
// Dana
DanaR("DanaR", 0.05f, null, //
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10f, 60, 24*60, 0f, 200f), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.04f, 0.01f, null, PumpCapability.DanaCapabilities),
DanaRKorean("DanaR Korean", 0.05f, null, //
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10f, 60, 24*60, 0f, 200f), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.1f, 0.01f, null, PumpCapability.DanaCapabilities),
DanaRS("DanaRS", 0.05f, null, //
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),
DanaRv2("DanaRv2", DanaRS),
// Insulet
Insulet_Omnipod("Insulet Omnipod", 0.05f, null, //
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 12*60, 0f, 5.0f), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr
0.05f, 0.05f, null, PumpCapability.VirtualPumpCapabilities),
// Medtronic
Medtronic_512_712("Medtronic 512/712", 0.05f, null, //
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24*60, 0f, 35f), PumpCapability.BasalRate_Duration30minAllowed, //
0.05f, 0.05f, null, PumpCapability.VirtualPumpCapabilities), // TODO
Medtronic_515_715("Medtronic 515/715", Medtronic_512_712),
Medtronic_522_722("Medtronic 522/722", Medtronic_512_712),
Medtronic_523_723_Revel("Medtronic 523/723 (Revel)", 0.05f, null, //
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24*60, 0f, 35f), PumpCapability.BasalRate_Duration30minAllowed, //
0.025f, 0.025f, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO
Medtronic_640G("Medtronic 640G", 0.025f, null, //
new DoseSettings(0.05f, 30, 8*60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24*60, 0f, 35f), PumpCapability.BasalRate_Duration30minAllowed, //
0.025f, 0.025f, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
// Tandem
TandemTSlim("Tandem t:slim", 0.01f, null, //
new DoseSettings(0.01f,15, 8*60, 0.4f),
PumpTempBasalType.Percent,
new DoseSettings(1,15, 8*60, 0f, 250f), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.1f, 0.001f, null, PumpCapability.VirtualPumpCapabilities),
TandemTFlex("Tandem t:flex", TandemTSlim), //
TandemTSlimG4("Tandem t:slim G4", TandemTSlim), //
TandemTSlimX2("Tandem t:slim X2", TandemTSlim), //
;
private String description;
private float bolusSize;
private DoseStepSize specialBolusSize;
private DoseSettings extendedBolusSettings;
private PumpTempBasalType pumpTempBasalType;
private DoseSettings tbrSettings;
private PumpCapability specialBasalDurations;
private float baseBasalMinValue; //
private Float baseBasalMaxValue;
private float baseBasalStep; //
private DoseStepSize baseBasalSpecialSteps; //
private PumpCapability pumpCapability;
private PumpType parent;
private static Map<String,PumpType> mapByDescription;
static
{
mapByDescription = new HashMap<>();
for (PumpType pumpType : values()) {
mapByDescription.put(pumpType.getDescription(), pumpType);
}
}
PumpType(String description, PumpType parent)
{
this.description = description;
this.parent = parent;
}
PumpType(String description, PumpType parent, PumpCapability pumpCapability)
{
this.description = description;
this.parent = parent;
this.pumpCapability = pumpCapability;
}
PumpType(String description, float bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
float baseBasalMinValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability)
{
this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
}
PumpType(String description, float bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
float baseBasalMinValue, Float baseBasalMaxValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability)
{
this.description = description;
this.bolusSize = bolusSize;
this.specialBolusSize = specialBolusSize;
this.extendedBolusSettings = extendedBolusSettings;
this.pumpTempBasalType = pumpTempBasalType;
this.tbrSettings = tbrSettings;
this.specialBasalDurations = specialBasalDurations;
this.baseBasalMinValue = baseBasalMinValue;
this.baseBasalMaxValue = baseBasalMaxValue;
this.baseBasalStep = baseBasalStep;
this.baseBasalSpecialSteps = baseBasalSpecialSteps;
this.pumpCapability = pumpCapability;
}
public String getDescription() {
return description;
}
public PumpCapability getPumpCapability() {
if (isParentSet())
return this.pumpCapability == null ? parent.pumpCapability : pumpCapability;
else
return this.pumpCapability;
}
public float getBolusSize() {
return isParentSet() ? parent.bolusSize : bolusSize;
}
public DoseStepSize getSpecialBolusSize() {
return isParentSet() ? parent.specialBolusSize : specialBolusSize;
}
public DoseSettings getExtendedBolusSettings() {
return isParentSet() ? parent.extendedBolusSettings : extendedBolusSettings;
}
public PumpTempBasalType getPumpTempBasalType() {
return isParentSet() ? parent.pumpTempBasalType : pumpTempBasalType;
}
public DoseSettings getTbrSettings() {
return isParentSet() ? parent.tbrSettings : tbrSettings;
}
public float getBaseBasalMinValue() {
return isParentSet() ? parent.baseBasalMinValue : baseBasalMinValue;
}
public Float getBaseBasalMaxValue() {
return isParentSet() ? parent.baseBasalMaxValue : baseBasalMaxValue;
}
public float getBaseBasalStep() {
return isParentSet() ? parent.baseBasalStep : baseBasalStep;
}
public DoseStepSize getBaseBasalSpecialSteps() {
return isParentSet() ? parent.baseBasalSpecialSteps : baseBasalSpecialSteps;
}
public PumpType getParent() {
return parent;
}
private boolean isParentSet()
{
return this.parent!=null;
}
public static PumpType getByDescription(String desc)
{
if (mapByDescription.containsKey(desc))
{
return mapByDescription.get(desc);
}
else
{
return PumpType.GenericAAPS;
}
}
public String getFullDescription(String i18nTemplate, boolean hasExtendedBasals) {
String unit = getPumpTempBasalType()==PumpTempBasalType.Percent ? "%" : "";
DoseSettings eb = getExtendedBolusSettings();
DoseSettings tbr = getTbrSettings();
String extendedNote = hasExtendedBasals ? MainApp.gs(R.string.virtualpump_pump_def_extended_note) : "";
return String.format(i18nTemplate, //
getStep("" + getBolusSize(), getSpecialBolusSize()), //
eb.getStep(), eb.getDurationStep(), eb.getMaxDuration()/60, //
getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), //
tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit,
tbr.getDurationStep(), tbr.getMaxDuration()/60, extendedNote);
}
private String getBaseBasalRange()
{
Float maxValue = getBaseBasalMaxValue();
return maxValue==null ? "" + getBaseBasalMinValue() : getBaseBasalMinValue() + "-" + maxValue;
}
private String getStep(String step, DoseStepSize stepSize)
{
if (stepSize!=null)
return step + " [" + stepSize.getDescription() + "] *";
else
return "" + step;
}
public boolean hasExtendedBasals() {
return ((getBaseBasalSpecialSteps() !=null) || (getSpecialBolusSize() != null));
}
public PumpCapability getSpecialBasalDurations() {
if (isParentSet())
{
return parent.getSpecialBasalDurations();
}
else
{
return specialBasalDurations == null ? //
PumpCapability.BasalRate_Duration15and30minNotAllowed : specialBasalDurations;
}
}
}

View file

@ -0,0 +1,63 @@
package info.nightscout.androidaps.plugins.PumpCommon.utils;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
/**
* Created by andy on 02/05/2018.
*/
public class PumpUtil {
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
{
PumpCapability pumpCapability = pumpType.getPumpCapability();
pumpDescription.isBolusCapable = pumpCapability.hasCapability(PumpCapability.Bolus);
pumpDescription.bolusStep = pumpType.getBolusSize();
pumpDescription.isExtendedBolusCapable = pumpCapability.hasCapability(PumpCapability.ExtendedBolus);
pumpDescription.extendedBolusStep = pumpType.getExtendedBolusSettings().getStep();
pumpDescription.extendedBolusDurationStep = pumpType.getExtendedBolusSettings().getDurationStep();
pumpDescription.extendedBolusMaxDuration = pumpType.getExtendedBolusSettings().getMaxDuration();
pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TempBasal);
if (pumpType.getPumpTempBasalType()==PumpTempBasalType.Percent)
{
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep();
}
else
{
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep();
}
pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep();
pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
pumpDescription.tempDurationStep15mAllowed = pumpType.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration15minAllowed);
pumpDescription.tempDurationStep30mAllowed = pumpType.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration30minAllowed);
pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
pumpDescription.basalStep = pumpType.getBaseBasalStep();
pumpDescription.basalMinimumRate = pumpType.getBaseBasalMinValue();
pumpDescription.isRefillingCapable = pumpCapability.hasCapability(PumpCapability.Refill);
pumpDescription.storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo);
pumpDescription.supportsTDDs = pumpCapability.hasCapability(PumpCapability.TDD);
pumpDescription.needsManualTDDLoad = pumpCapability.hasCapability(PumpCapability.ManualTDDLoad);
pumpDescription.is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min);
}
}

View file

@ -15,10 +15,12 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.FabricPrivacy;
@ -31,6 +33,9 @@ public class VirtualPumpFragment extends SubscriberFragment {
TextView extendedBolusView;
TextView batteryView;
TextView reservoirView;
TextView pumpTypeView;
TextView pumpSettingsView;
private static Handler sLoopHandler = new Handler();
private static Runnable sRefreshLoop = null;
@ -60,6 +65,8 @@ public class VirtualPumpFragment extends SubscriberFragment {
extendedBolusView = (TextView) view.findViewById(R.id.virtualpump_extendedbolus);
batteryView = (TextView) view.findViewById(R.id.virtualpump_battery);
reservoirView = (TextView) view.findViewById(R.id.virtualpump_reservoir);
pumpTypeView = (TextView) view.findViewById(R.id.virtualpump_type);
pumpSettingsView = (TextView) view.findViewById(R.id.virtualpump_type_def);
return view;
} catch (Exception e) {
@ -97,6 +104,18 @@ public class VirtualPumpFragment extends SubscriberFragment {
}
batteryView.setText(virtualPump.batteryPercent + "%");
reservoirView.setText(virtualPump.reservoirInUnits + "U");
virtualPump.refreshConfiguration();
PumpType pumpType = virtualPump.getPumpType();
pumpTypeView.setText(pumpType.getDescription());
String template = MainApp.gs(R.string.virtualpump_pump_def);
pumpSettingsView.setText(pumpType.getFullDescription(template, pumpType.hasExtendedBasals()));
}
});
}

View file

@ -28,6 +28,8 @@ import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
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.PumpVirtual.events.EventVirtualPumpUpdateGui;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
@ -57,6 +59,9 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
private PumpDescription pumpDescription = new PumpDescription();
PumpType pumpType = null;
private static void loadFakingStatus() {
fromNSAreCommingFakedExtendedBoluses = SP.getBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, false);
}
@ -414,4 +419,32 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
return "Virtual Pump";
}
public PumpType getPumpType()
{
return pumpType;
}
public void refreshConfiguration()
{
String pumptype = SP.getString("virtualpump_type", "Generic AAPS");
PumpType pumpTypeNew = PumpType.getByDescription(pumptype);
log.debug("Pump in configuration: {}, PumpType object: {}", pumptype, pumpTypeNew);
if (pumpType == pumpTypeNew)
return;
log.debug("New pump configuration found ({}), changing from previous ({})", pumpTypeNew, pumpType);
// reset
pumpDescription.resetSettings();
PumpUtil.setPumpDescription(pumpDescription, pumpTypeNew);
this.pumpType = pumpTypeNew;
}
}

View file

@ -189,6 +189,7 @@
</LinearLayout>
<!-- Reservoir -->
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
@ -232,6 +233,99 @@
android:textSize="14sp" />
</LinearLayout>
<!-- Pump Type -->
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/virtualpump_type"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/virtualpump_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingLeft="5dp"
android:textSize="14sp" />
</LinearLayout>
<!-- Pump Type -->
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/virtualpump_definition"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/virtualpump_type_def"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingLeft="5dp"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -111,4 +111,30 @@
<item>@string/no</item>
<item>@string/yes</item>
</string-array>
<string-array name="virtualPumpTypes">
<item>Generic AAPS</item>
<item>Accu-Chek Spirit</item>
<item>Accu-Chek Combo</item>
<item>Accu-Chek Insight</item>
<item>Animas Ping</item>
<item>Animas Vibe</item>
<item>Cellnovo</item>
<item>DanaR</item>
<item>DanaR Korean</item>
<item>DanaRS</item>
<item>DanaRv2</item>
<item>Insulet Omnipod</item>
<item>Medtronic 512/712</item>
<item>Medtronic 515/715</item>
<item>Medtronic 522/722</item>
<item>Medtronic 523/723 (Revel)</item>
<item>Medtronic 554/754 (Veo)</item>
<item>Medtronic 640G</item>
<item>Tandem t:slim</item>
<item>Tandem t:flex</item>
<item>Tandem t:slim G4</item>
<item>Tandem t:slim X2</item>
</string-array>
</resources>

View file

@ -1083,6 +1083,10 @@
<string name="openapsama_max_daily_safety_multiplier">Max daily safety multiplier</string>
<string name="openapsama_current_basal_safety_multiplier">Current basal safety multiplier</string>
<string name="value_unavailable_short">n/a</string>
<string name="virtualpump_type">Virtual Pump Type</string>
<string name="virtualpump_definition">Pump Definition</string>
<string name="virtualpump_pump_def">Bolus: Step=%s\nExtended Bolus: [Step=%s, Duration=%smin-%sh]\nBasal: Step=%s\nTBR: %s (by %s), Duration=%smin-%sh\nEXTENDED_NOTE</string>
<string name="virtualpump_pump_def_extended_note">* Ranged basal/bolus values are not supported by Virtual Pump.</string>
<string name="ns_autobackfill_title">Autobackfill BG</string>
<string name="ga_lang" translatable="false">Irish</string>
<string name="wear_wizard_settings">Wizard Settings</string>

View file

@ -8,6 +8,14 @@
android:defaultValue="false"
android:key="virtualpump_uploadstatus"
android:title="@string/virtualpump_uploadstatus_title" />
<ListPreference
android:defaultValue="1"
android:entries="@array/virtualPumpTypes"
android:entryValues="@array/virtualPumpTypes"
android:key="virtualpump_type"
android:title="@string/virtualpump_type" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,45 @@
package info.nightscout.androidaps.plugins.PumpCommon.utils;
import org.junit.Assert;
import org.junit.Test;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import static org.junit.Assert.*;
/**
* Created by andy on 5/13/18.
*/
public class PumpUtilUTest {
@Test
public void setPumpDescription() throws Exception {
PumpDescription pumpDescription = new PumpDescription();
PumpUtil.setPumpDescription(pumpDescription, PumpType.AccuChekCombo);
Assert.assertEquals(pumpDescription.bolusStep, PumpType.AccuChekCombo.getBolusSize(), 0.1d);
Assert.assertEquals(pumpDescription.basalMinimumRate, PumpType.AccuChekCombo.getBaseBasalStep(), 0.1d);
Assert.assertEquals(pumpDescription.basalStep, PumpType.AccuChekCombo.getBaseBasalStep(), 0.1d);
Assert.assertEquals(pumpDescription.extendedBolusDurationStep, PumpType.AccuChekCombo.getExtendedBolusSettings().getDurationStep(), 0.1d);
Assert.assertEquals(pumpDescription.extendedBolusMaxDuration, PumpType.AccuChekCombo.getExtendedBolusSettings().getMaxDuration(), 0.1d);
Assert.assertEquals(pumpDescription.extendedBolusStep, PumpType.AccuChekCombo.getExtendedBolusSettings().getStep(), 0.1d);
Assert.assertEquals(pumpDescription.isExtendedBolusCapable, PumpType.AccuChekCombo.getPumpCapability().hasCapability(PumpCapability.ExtendedBolus));
Assert.assertEquals(pumpDescription.isBolusCapable, PumpType.AccuChekCombo.getPumpCapability().hasCapability(PumpCapability.Bolus));
Assert.assertEquals(pumpDescription.isRefillingCapable, PumpType.AccuChekCombo.getPumpCapability().hasCapability(PumpCapability.Refill));
Assert.assertEquals(pumpDescription.isSetBasalProfileCapable, PumpType.AccuChekCombo.getPumpCapability().hasCapability(PumpCapability.BasalProfileSet));
Assert.assertEquals(pumpDescription.isTempBasalCapable, PumpType.AccuChekCombo.getPumpCapability().hasCapability(PumpCapability.TempBasal));
Assert.assertEquals(pumpDescription.maxTempPercent, PumpType.AccuChekCombo.getTbrSettings().getMaxDose(), 0.1d);
Assert.assertEquals(pumpDescription.tempPercentStep, PumpType.AccuChekCombo.getTbrSettings().getStep(), 0.1d);
Assert.assertEquals(pumpDescription.tempBasalStyle, PumpType.AccuChekCombo.getPumpTempBasalType()== PumpTempBasalType.Percent ? PumpDescription.PERCENT : PumpDescription.ABSOLUTE);
Assert.assertEquals(pumpDescription.tempDurationStep, PumpType.AccuChekCombo.getTbrSettings().getDurationStep());
Assert.assertEquals(pumpDescription.tempDurationStep15mAllowed, PumpType.AccuChekCombo.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration15minAllowed));
Assert.assertEquals(pumpDescription.tempDurationStep30mAllowed, PumpType.AccuChekCombo.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration30minAllowed));
}
}

View file

@ -0,0 +1,78 @@
package info.nightscout.androidaps.plugins.PumpVirtual;
import android.content.Context;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.when;
/**
* Created by andy on 5/13/18.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, SP.class})
public class VirtualPumpPluginUTest {
VirtualPumpPlugin virtualPumpPlugin;
@Before
public void prepareMocks() throws Exception {
AAPSMocker.mockMainApp();
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockBus();
AAPSMocker.mockStrings();
AAPSMocker.mockCommandQueue();
AAPSMocker.mockSP();
virtualPumpPlugin = VirtualPumpPlugin.getPlugin();
}
@Test
public void getPumpType() throws Exception {
}
@Test
public void refreshConfiguration() throws Exception {
when(SP.getString("virtualpump_type", "Generic AAPS")).thenReturn("Accu-Chek Combo");
virtualPumpPlugin.refreshConfiguration();
Assert.assertEquals(PumpType.AccuChekCombo, virtualPumpPlugin.getPumpType());
}
@Test
public void refreshConfigurationTwice() throws Exception {
when(SP.getString("virtualpump_type", "Generic AAPS")).thenReturn("Accu-Chek Combo");
virtualPumpPlugin.refreshConfiguration();
when(SP.getString("virtualpump_type", "Generic AAPS")).thenReturn("Accu-Chek Combo");
virtualPumpPlugin.refreshConfiguration();
Assert.assertEquals(PumpType.AccuChekCombo, virtualPumpPlugin.getPumpType());
}
}