From af56304669b605f6d25f150641ceeb443b4e1e04 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Mon, 7 May 2018 12:05:53 +0100 Subject: [PATCH] Initial commit after dev was merged into here --- .../androidaps/PreferencesActivity.java | 3 +- .../interfaces/PumpDescription.java.orig | 85 +++++++ .../PumpCommon/PumpPluginAbstract.java | 235 ++++++++++-------- .../plugins/PumpCommon/utils/PumpUtil.java | 2 + .../PumpMedtronic/MedtronicFragment.java | 23 +- .../PumpMedtronic/MedtronicPumpPlugin.java | 75 +++--- .../PumpVirtual/VirtualPumpDriver.java | 113 +++++---- .../PumpVirtual/VirtualPumpFragment.java | 1 + app/src/main/res/values/arrays.xml | 2 +- app/src/main/res/values/strings.xml | 8 + 10 files changed, 339 insertions(+), 208 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java.orig diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index 1610a747fb..1069f1a157 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -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); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java.orig b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java.orig new file mode 100644 index 0000000000..7995070a4d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java.orig @@ -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 +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java index ce490cb8fb..7ea8bb11f2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java @@ -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 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/PumpUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/PumpUtil.java index a18ff6f7bf..b5094b775c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/PumpUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/PumpUtil.java @@ -53,6 +53,8 @@ public class PumpUtil { pumpDescription.isRefillingCapable = pumpCapability.hasCapability(PumpCapability.Refill); pumpDescription.storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo); + + setPumpDescription(pumpDescription, PumpType.AccuChekCombo); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java index d6e536d683..01832e0a8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java @@ -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) + "}"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java index 58a06be611..6a2e485845 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java @@ -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; +// } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpDriver.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpDriver.java index e3ff6fc52f..34f8466993 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpDriver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpDriver.java @@ -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; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java index 5a42af3811..f01fb0f379 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java @@ -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; diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 0988f2c9e1..7cd2a0a8ed 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -131,7 +131,7 @@ Tandem t:slim X2 - + Other (unsupported) 512 712 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38e547a2db..b8c3f000ac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1036,12 +1036,19 @@ n/a Autobackfill BG + Virtual Pump Type + Pump Definition + Bolus: Step=%s\nExtended Bolus: [Step=%s, Duration=%smin-%sh]\nBasal: Step=%s\nTBR: %s (by %s), Duration=%smin-%sh\nEXTENDED_NOTE + * Ranged basal/bolus values are not supported by Virtual Pump. + + Operation not supported by pump. Operation not YET supported by pump. Medtronic + MT Pump Serial Number Pump Type Pump Frequency @@ -1054,4 +1061,5 @@ Pump Frequency not set. Pump Frequency unsupported. RileyLink Address invalid. +