Initial commit after dev was merged into here

This commit is contained in:
Andy Rozman 2018-05-07 12:05:53 +01:00
parent 421946269a
commit af56304669
10 changed files with 339 additions and 208 deletions

View file

@ -162,6 +162,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginType.PUMP);
addPreferencesFromResourceIfEnabled(InsightPlugin.getPlugin(), PluginType.PUMP);
addPreferencesFromResourceIfEnabled(ComboPlugin.getPlugin(), PluginType.PUMP);
addPreferencesFromResourceIfEnabled(MedtronicPumpPlugin.getPlugin(), PluginType.PUMP);
if (DanaRPlugin.getPlugin().isEnabled(PluginType.PROFILE)
|| DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PROFILE)
@ -175,7 +176,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginType.PUMP);
}
addPreferencesFromResourceIfEnabled(MedtronicPumpPlugin.getPlugin(), PluginBase.PUMP);
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginType.INSULIN);

View file

@ -0,0 +1,85 @@
package info.nightscout.androidaps.interfaces;
/**
* Created by mike on 08.12.2016.
*/
public class PumpDescription {
public static final int NONE = 0;
public static final int PERCENT = 0x01;
public static final int ABSOLUTE = 0x02;
public boolean isBolusCapable = true;
public double bolusStep = 0.1d;
public boolean isExtendedBolusCapable = true;
public double extendedBolusStep = 0.1d;
public double extendedBolusDurationStep = 30;
public double extendedBolusMaxDuration = 12 * 60;
public boolean isTempBasalCapable = true;
public int tempBasalStyle = PERCENT;
public int maxTempPercent = 200;
public int tempPercentStep = 10;
public double maxTempAbsolute = 10;
public double tempAbsoluteStep = 0.05d;
public int tempDurationStep = 60;
public boolean tempDurationStep15mAllowed = false;
public boolean tempDurationStep30mAllowed = false;
public int tempMaxDuration = 12 * 60;
public boolean isSetBasalProfileCapable = true;
public double basalStep = 0.01d;
public double basalMinimumRate = 0.04d;
public boolean isRefillingCapable = false;
public boolean storesCarbInfo = true;
<<<<<<< HEAD
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;
isSetBasalProfileCapable = true;
basalStep = 0.01d;
basalMinimumRate = 0.04d;
isRefillingCapable = false;
storesCarbInfo = true;
}
=======
public boolean is30minBasalRatesCapable = false;
public boolean supportsTDDs = false;
public boolean needsManualTDDLoad = true;
>>>>>>> dev
}

View file

@ -8,15 +8,19 @@ import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.PumpCombo.ComboFragment;
import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverInterface;
@ -24,7 +28,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverInterface;
* Created by andy on 23.04.18.
*/
public abstract class PumpPluginAbstract implements PluginBase, PumpInterface, ConstraintsInterface, ProfileInterface {
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface, ProfileInterface {
protected boolean fragmentVisible = false;
protected boolean fragmentEnabled = false;
@ -40,69 +44,76 @@ public abstract class PumpPluginAbstract implements PluginBase, PumpInterface, C
protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, //
String internalName)
String internalName, //
String fragmentClassName, //
int pluginName, //
int pluginShortName)
{
super(new PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(fragmentClassName)
.pluginName(pluginName)
.shortName(pluginShortName)
);
this.pumpDriver = pumpDriverInterface;
this.pumpStatus = this.pumpDriver.getPumpStatusData();
}
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PUMP && fragmentVisible;
}
// @Override
// public boolean isVisibleInTabs(int type) {
// return type == PUMP && fragmentVisible;
// }
//
//
// @Override
// public boolean canBeHidden(int type) {
// return true;
// }
//
//
// @Override
// public boolean hasFragment() {
// return true;
// }
//
//
// @Override
// public boolean showInList(int type) {
// return type == PUMP;
// }
@Override
public boolean canBeHidden(int type) {
return true;
}
// @Override
// public void setFragmentEnabled(int type, boolean fragmentEnabled) {
// if (type == PUMP) {
// this.fragmentEnabled = fragmentEnabled;
//
// if (fragmentEnabled) {
// if (!pumpServiceRunning)
// startPumpService();
// else
// Log.d(TAG, "Can't start, Pump service (" + getInternalName() + "is already running.");
// }
// else {
// if (pumpServiceRunning)
// stopPumpService();
// else
// Log.d(TAG, "Can't stop, Pump service (" + getInternalName() + "is already stopped.");
// }
// }
// }
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return type == PUMP;
}
@Override
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
if (type == PUMP) {
this.fragmentEnabled = fragmentEnabled;
if (fragmentEnabled) {
if (!pumpServiceRunning)
startPumpService();
else
Log.d(TAG, "Can't start, Pump service (" + getInternalName() + "is already running.");
}
else {
if (pumpServiceRunning)
stopPumpService();
else
Log.d(TAG, "Can't stop, Pump service (" + getInternalName() + "is already stopped.");
}
}
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PUMP)
this.fragmentVisible = fragmentVisible;
}
// @Override
// public void setFragmentVisible(int type, boolean fragmentVisible) {
// if (type == PUMP)
// this.fragmentVisible = fragmentVisible;
// }
protected abstract String getInternalName();
@ -194,12 +205,16 @@ public abstract class PumpPluginAbstract implements PluginBase, PumpInterface, C
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew){
return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, enforceNew);
//return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, enforceNew);
// FIXME
return null;
}
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew){
return pumpDriver.setTempBasalPercent(percent, durationInMinutes, enforceNew);
//return pumpDriver.setTempBasalPercent(percent, durationInMinutes, enforceNew);
// FIXME
return null;
}
@ -222,8 +237,8 @@ public abstract class PumpPluginAbstract implements PluginBase, PumpInterface, C
// Status to be passed to NS
public JSONObject getJSONStatus(){
return pumpDriver.getJSONStatus();
public JSONObject getJSONStatus(Profile profile, String profileName){
return pumpDriver.getJSONStatus( profile, profileName);
}
@ -254,60 +269,60 @@ public abstract class PumpPluginAbstract implements PluginBase, PumpInterface, C
// Constraints interface
@Override
public boolean isLoopEnabled() {
return true;
}
@Override
public boolean isClosedModeEnabled() {
return true;
}
@Override
public boolean isAutosensModeEnabled() {
return true;
}
@Override
public boolean isAMAModeEnabled() {
return true;
}
@Override
public boolean isSMBModeEnabled() {
return true;
}
@Override
public Double applyBasalConstraints(Double absoluteRate) {
this.pumpStatus.constraintBasalRateAbsolute = absoluteRate;
return absoluteRate;
}
@Override
public Integer applyBasalConstraints(Integer percentRate) {
this.pumpStatus.constraintBasalRatePercent = percentRate;
return percentRate;
}
@Override
public Double applyBolusConstraints(Double insulin) {
this.pumpStatus.constraintBolus = insulin;
return insulin;
}
@Override
public Integer applyCarbsConstraints(Integer carbs) {
this.pumpStatus.constraintCarbs = carbs;
return carbs;
}
@Override
public Double applyMaxIOBConstraints(Double maxIob) {
this.pumpStatus.constraintMaxIob = maxIob;
return maxIob;
}
// @Override
// public boolean isLoopEnabled() {
// return true;
// }
//
// @Override
// public boolean isClosedModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isAutosensModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isAMAModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isSMBModeEnabled() {
// return true;
// }
//
// @Override
// public Double applyBasalConstraints(Double absoluteRate) {
// this.pumpStatus.constraintBasalRateAbsolute = absoluteRate;
// return absoluteRate;
// }
//
// @Override
// public Integer applyBasalConstraints(Integer percentRate) {
// this.pumpStatus.constraintBasalRatePercent = percentRate;
// return percentRate;
// }
//
// @Override
// public Double applyBolusConstraints(Double insulin) {
// this.pumpStatus.constraintBolus = insulin;
// return insulin;
// }
//
// @Override
// public Integer applyCarbsConstraints(Integer carbs) {
// this.pumpStatus.constraintCarbs = carbs;
// return carbs;
// }
//
// @Override
// public Double applyMaxIOBConstraints(Double maxIob) {
// this.pumpStatus.constraintMaxIob = maxIob;
// return maxIob;
// }
// Profile interface

View file

@ -53,6 +53,8 @@ public class PumpUtil {
pumpDescription.isRefillingCapable = pumpCapability.hasCapability(PumpCapability.Refill);
pumpDescription.storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo);
setPumpDescription(pumpDescription, PumpType.AccuChekCombo);
}

View file

@ -33,8 +33,9 @@ import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.events.EventQueueChanged;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -133,10 +134,10 @@ public class MedtronicFragment extends SubscriberFragment {
profileViewDialog.show(manager, "ProfileViewDialog");
}
@OnClick(R.id.medtronic_stats)
void onStatsClick() {
startActivity(new Intent(getContext(), DanaRStatsActivity.class));
}
//@OnClick(R.id.medtronic_stats)
//void onStatsClick() {
// startActivity(new Intent(getContext(), DanaRStatsActivity.class));
//}
@OnClick(R.id.medtronic_btconnection)
void onBtConnectionClick() {
@ -226,20 +227,24 @@ public class MedtronicFragment extends SubscriberFragment {
basaBasalRateView.setText("(" + (pump.activeProfileName) + ") " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h");
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
} else {
// v2 plugin
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
}
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / " + pump.reservoirFullUnits + " U");
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");

View file

@ -12,6 +12,7 @@ import java.util.Date;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
@ -20,6 +21,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.PumpMedtronic.medtronic.MedtronicPumpDriver;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpDriver;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
@ -48,7 +50,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public MedtronicPumpPlugin()
{
super(new MedtronicPumpDriver(), //
"MedtronicPump"//
"MedtronicPump", //
MedtronicFragment.class.getName(), //
R.string.medtronic_name, //
R.string.medtronic_name_short //
);
}
@ -73,14 +78,18 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
return null;
}
@Override
public JSONObject getJSONStatus() {
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
return null;
}
@Override
public JSONObject getJSONStatus(Profile profile, String profileName) {
//if (!SP.getBoolean("virtualpump_uploadstatus", false)) {
// return null;
//}
@ -96,18 +105,21 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
} catch (Exception e) {
}
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
}
status.put("timestamp", DateUtil.toISOString(new Date()));
pump.put("battery", battery);
@ -138,32 +150,21 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return false;
}
@Override
public String getFragmentClass()
{
return MedtronicFragment.class.getName();
public PumpEnactResult loadTDDs() {
return null;
}
@Override
public String getName() {
return "Medtronic";
}
@Override
public String getNameShort() {
return "MEDT";
}
@Override
public boolean isEnabled(int type) {
// TODO might need tweaking
if (type == PluginBase.PUMP)
return fragmentEnabled;
else if (type == PluginBase.CONSTRAINTS)
return fragmentEnabled;
return false;
}
// @Override
// public boolean isEnabled(int type) {
// // TODO might need tweaking
// if (type == PluginBase.PUMP)
// return fragmentEnabled;
// else if (type == PluginBase.CONSTRAINTS)
// return fragmentEnabled;
// return false;
// }
@Override
@ -172,10 +173,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
@Override
public boolean isLoopEnabled() {
// FIXME check if we need to override
return getPumpStatusData().validBasalRateProfileSelectedOnPump;
}
// @Override
// public boolean isLoopEnabled() {
// // FIXME check if we need to override
// return getPumpStatusData().validBasalRateProfileSelectedOnPump;
// }
}

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverAbstract;
import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverInterface;
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
@ -110,6 +111,8 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
return (Config.NSCLIENT || Config.G5UPLOADER) && fromNSAreCommingFakedExtendedBoluses;
}
@Override
public boolean isInitialized() {
return true;
@ -180,11 +183,12 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
public double getBaseBasalRate() {
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile != null)
return profile.getBasal() != null ? profile.getBasal() : 0d;
return profile.getBasal();
else
return 0d;
}
@Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
PumpEnactResult result = new PumpEnactResult();
@ -192,21 +196,21 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
result.bolusDelivered = detailedBolusInfo.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
result.enacted = result.bolusDelivered > 0 || result.carbsDelivered > 0;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.comment = MainApp.gs(R.string.virtualpump_resultok);
Double delivering = 0d;
while (delivering < detailedBolusInfo.insulin) {
SystemClock.sleep(200);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivering);
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivering), delivering);
bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100);
MainApp.bus().post(bolusingEvent);
delivering += 0.1d;
}
SystemClock.sleep(200);
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivered), detailedBolusInfo.insulin);
bolusingEvent.status = String.format(MainApp.gs(R.string.bolusdelivered), detailedBolusInfo.insulin);
bolusingEvent.percent = 100;
MainApp.bus().post(bolusingEvent);
SystemClock.sleep(1000);
@ -214,32 +218,34 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
LOG.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
pumpStatusData.setLastDataTimeToNow();
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo);
return result;
}
@Override
public void stopBolusDelivering() {
}
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
TemporaryBasal tempBasal = new TemporaryBasal();
tempBasal.date = System.currentTimeMillis();
tempBasal.isAbsolute = true;
tempBasal.absoluteRate = absoluteRate;
tempBasal.durationInMinutes = durationInMinutes;
tempBasal.source = Source.USER;
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
TemporaryBasal tempBasal = new TemporaryBasal()
.date(System.currentTimeMillis())
.absolute(absoluteRate)
.duration(durationInMinutes)
.source(Source.USER);
PumpEnactResult result = new PumpEnactResult();
result.success = true;
result.enacted = true;
result.isTempCancel = false;
result.absolute = absoluteRate;
result.duration = durationInMinutes;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
treatmentsInterface.addToHistoryTempBasal(tempBasal);
result.comment = MainApp.gs(R.string.virtualpump_resultok);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
if (Config.logPumpComm)
LOG.debug("Setting temp basal absolute: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
@ -247,40 +253,39 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
return result;
}
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult();
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
result = cancelTempBasal(false);
if (!result.success)
return result;
}
TemporaryBasal tempBasal = new TemporaryBasal();
tempBasal.date = System.currentTimeMillis();
tempBasal.isAbsolute = false;
tempBasal.percentRate = percent;
tempBasal.durationInMinutes = durationInMinutes;
tempBasal.source = Source.USER;
TemporaryBasal tempBasal = new TemporaryBasal()
.date(System.currentTimeMillis())
.percent(percent)
.duration(durationInMinutes)
.source(Source.USER);
result.success = true;
result.enacted = true;
result.percent = percent;
result.isPercent = true;
result.isTempCancel = false;
result.duration = durationInMinutes;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
treatmentsInterface.addToHistoryTempBasal(tempBasal);
result.comment = MainApp.gs(R.string.virtualpump_resultok);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
if (Config.logPumpComm)
LOG.debug("Settings temp basal percent: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
pumpStatusData.setLastDataTimeToNow();
return result;
}
@Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
PumpEnactResult result = cancelExtendedBolus();
if (!result.success)
return result;
@ -294,61 +299,63 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
result.bolusDelivered = insulin;
result.isTempCancel = false;
result.duration = durationInMinutes;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
treatmentsInterface.addToHistoryExtendedBolus(extendedBolus);
result.comment = MainApp.gs(R.string.virtualpump_resultok);
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
if (Config.logPumpComm)
LOG.debug("Setting extended bolus: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
pumpStatusData.setLastDataTimeToNow();
return result;
}
@Override
public PumpEnactResult cancelTempBasal(boolean force) {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
PumpEnactResult result = new PumpEnactResult();
result.success = true;
result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (treatmentsInterface.isTempBasalInProgress()) {
result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
result.enacted = true;
TemporaryBasal tempStop = new TemporaryBasal(System.currentTimeMillis());
tempStop.source = Source.USER;
treatmentsInterface.addToHistoryTempBasal(tempStop);
TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
//tempBasal = null;
if (Config.logPumpComm)
LOG.debug("Canceling temp basal: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
}
pumpStatusData.setLastDataTimeToNow();
return result;
}
@Override
public PumpEnactResult cancelExtendedBolus() {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
PumpEnactResult result = new PumpEnactResult();
if (treatmentsInterface.isInHistoryExtendedBoluslInProgress()) {
if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
ExtendedBolus exStop = new ExtendedBolus(System.currentTimeMillis());
exStop.source = Source.USER;
treatmentsInterface.addToHistoryExtendedBolus(exStop);
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(exStop);
}
result.success = true;
result.enacted = true;
result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (Config.logPumpComm)
LOG.debug("Canceling extended basal: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
pumpStatusData.setLastDataTimeToNow();
return result;
}
@Override
public JSONObject getJSONStatus() {
public JSONObject getJSONStatus(Profile profile, String profileName) {
long now = System.currentTimeMillis();
if (!SP.getBoolean("virtualpump_uploadstatus", false)) {
return null;
}
@ -361,28 +368,28 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
status.put("status", "normal");
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
try {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
extended.put("ActiveProfile", profileName);
} catch (Exception e) {
}
TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now);
if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis()));
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now);
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
}
status.put("timestamp", DateUtil.toISOString(new Date()));
status.put("timestamp", DateUtil.toISOString(now));
pump.put("battery", battery);
pump.put("status", status);
pump.put("extended", extended);
pump.put("reservoir", pumpStatusData.reservoirRemainingUnits);
pump.put("clock", DateUtil.toISOString(new Date()));
pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) {
LOG.error("Unhandled exception", e);
}
@ -390,5 +397,11 @@ public class VirtualPumpDriver extends PumpDriverAbstract {
}
@Override
public PumpEnactResult loadTDDs() {
//no result, could read DB in the future?
PumpEnactResult result = new PumpEnactResult();
return result;
}
}

View file

@ -15,6 +15,7 @@ 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;

View file

@ -131,7 +131,7 @@
<item>Tandem t:slim X2</item>
</string-array>
<string-array name="medtronicPumpTypeArray">
<string-array name="medtronicPumpTypeArray">
<item>Other (unsupported)</item>
<item>512</item>
<item>712</item>

View file

@ -1036,12 +1036,19 @@
<string name="value_unavailable_short">n/a</string>
<string name="ns_autobackfill_title">Autobackfill BG</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>
<!-- Pump Abstract -->
<string name="pump_operation_not_supported_by_pump">Operation not supported by pump.</string>
<string name="pump_operation_not_yet_supported_by_pump">Operation not YET supported by pump.</string>
<!-- Medtronic -->
<string name="medtronic_name" translatable="false">Medtronic</string>
<string name="medtronic_name_short" translatable="false">MT</string>
<string name="medtronic_serial_number">Pump Serial Number</string>
<string name="medtronic_pump_type">Pump Type</string>
<string name="medtronic_pump_frequency">Pump Frequency</string>
@ -1054,4 +1061,5 @@
<string name="medtronic_error_pump_frequency_not_set">Pump Frequency not set.</string>
<string name="medtronic_error_pump_frequency_invalid">Pump Frequency unsupported.</string>
<string name="medtronic_error_rileylink_address_invalid">RileyLink Address invalid.</string>
</resources>