From 29327aef01d5d29a4fb04f02f379e4159c4ed09e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 27 Dec 2016 23:35:50 +0100 Subject: [PATCH] MDI pump driver --- .../info/nightscout/androidaps/MainApp.java | 2 + .../interfaces/PumpDescription.java | 1 + .../androidaps/plugins/Loop/LoopPlugin.java | 4 +- .../androidaps/plugins/MDI/MDIFragment.java | 33 +++ .../androidaps/plugins/MDI/MDIPlugin.java | 259 ++++++++++++++++++ .../plugins/Objectives/ObjectivesPlugin.java | 2 +- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 4 +- .../plugins/Overview/OverviewFragment.java | 2 +- .../plugins/TempBasals/TempBasalsPlugin.java | 4 +- app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 11 files changed, 305 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIFragment.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 90ff82e017..e2e7eabd89 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.DanaR.DanaRFragment; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanFragment; import info.nightscout.androidaps.plugins.Loop.LoopFragment; +import info.nightscout.androidaps.plugins.MDI.MDIFragment; import info.nightscout.androidaps.plugins.NSProfile.NSProfileFragment; import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment; @@ -75,6 +76,7 @@ public class MainApp extends Application { if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin()); if (Config.DANARKOREAN) pluginsList.add(DanaRKoreanFragment.getPlugin()); if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.getPlugin()); + pluginsList.add(MDIFragment.getPlugin()); pluginsList.add(VirtualPumpFragment.getPlugin()); if (Config.LOOPENABLED) pluginsList.add(LoopFragment.getPlugin()); if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java index b350db88ea..78a111d468 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpDescription.java @@ -5,6 +5,7 @@ package info.nightscout.androidaps.interfaces; */ public class PumpDescription { + public static final int NONE = 0; public static final int PERCENT = 1; public static final int ABSOLUTE = 2; public static final int EXTENDED = 4; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index c90ee5c4e1..d84bbb1017 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -83,12 +83,12 @@ public class LoopPlugin implements PluginBase { @Override public boolean isEnabled(int type) { - return type == LOOP && fragmentEnabled; + return type == LOOP && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; } @Override public boolean isVisibleInTabs(int type) { - return type == LOOP && fragmentVisible; + return type == LOOP && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIFragment.java new file mode 100644 index 0000000000..a67f68dfb3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIFragment.java @@ -0,0 +1,33 @@ +package info.nightscout.androidaps.plugins.MDI; + + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +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.interfaces.FragmentBase; +import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.VirtualPump.events.EventVirtualPumpUpdateGui; + +public class MDIFragment extends Fragment implements FragmentBase { + private static Logger log = LoggerFactory.getLogger(MDIFragment.class); + + private static MDIPlugin mdiPlugin = new MDIPlugin(); + + public static MDIPlugin getPlugin() { + return mdiPlugin; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java new file mode 100644 index 0000000000..7676086de2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java @@ -0,0 +1,259 @@ +package info.nightscout.androidaps.plugins.MDI; + +import android.content.Context; + +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.SQLException; +import java.util.Date; + +import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.db.TempBasal; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PumpDescription; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; +import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpFragment; +import info.nightscout.androidaps.plugins.VirtualPump.events.EventVirtualPumpUpdateGui; +import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.DateUtil; + +/** + * Created by mike on 05.08.2016. + */ +public class MDIPlugin implements PluginBase, PumpInterface { + private static Logger log = LoggerFactory.getLogger(MDIPlugin.class); + + boolean fragmentEnabled = false; + boolean fragmentVisible = false; + + PumpDescription pumpDescription = new PumpDescription(); + + public MDIPlugin() { + pumpDescription.isBolusCapable = true; + pumpDescription.bolusStep = 0.5d; + + pumpDescription.isExtendedBolusCapable = false; + pumpDescription.extendedBolusStep = 0d; + + pumpDescription.isTempBasalCapable = false; + pumpDescription.lowTempBasalStyle = PumpDescription.NONE; + pumpDescription.highTempBasalStyle = PumpDescription.NONE; + pumpDescription.maxHighTempPercent = 0; + pumpDescription.maxHighTempAbsolute = 0; + pumpDescription.lowTempPercentStep = 0; + pumpDescription.lowTempAbsoluteStep = 0; + pumpDescription.lowTempPercentDuration = 0; + pumpDescription.lowTempAbsoluteDuration = 0; + pumpDescription.highTempPercentStep = 0; + pumpDescription.highTempAbsoluteStep = 0d; + pumpDescription.highTempPercentDuration = 0; + pumpDescription.highTempAbsoluteDuration = 0; + + pumpDescription.isSetBasalProfileCapable = true; + pumpDescription.basalStep = 0d; + pumpDescription.basalMinimumRate = 0d; + + pumpDescription.isRefillingCapable = false; + } + + @Override + public String getFragmentClass() { + return MDIFragment.class.getName(); + } + + @Override + public String getName() { + return MainApp.instance().getString(R.string.mdi); + } + + @Override + public boolean isEnabled(int type) { + return type == PUMP && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return false; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == PUMP) this.fragmentEnabled = fragmentEnabled; + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + if (type == PUMP) this.fragmentVisible = fragmentVisible; + } + + @Override + public int getType() { + return PluginBase.PUMP; + } + + @Override + public boolean isInitialized() { + return true; + } + + @Override + public boolean isTempBasalInProgress() { + return false; + } + + @Override + public boolean isExtendedBoluslInProgress() { + return false; + } + + @Override + public int setNewBasalProfile(NSProfile profile) { + // Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile(); + return SUCCESS; + } + + @Override + public boolean isThisProfileSet(NSProfile profile) { + return false; + } + + @Override + public double getBaseBasalRate() { + return 0d; + } + + @Override + public double getTempBasalAbsoluteRate() { + return 0; + } + + @Override + public TempBasal getTempBasal() { + return null; + } + + @Override + public TempBasal getExtendedBolus() { + return null; + } + + @Override + public double getTempBasalRemainingMinutes() { + return 0d; + } + + @Override + public TempBasal getTempBasal(Date time) { + return null; + } + + @Override + public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) { + PumpEnactResult result = new PumpEnactResult(); + result.success = true; + result.bolusDelivered = insulin; + result.carbsDelivered = carbs; + result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + return result; + } + + @Override + public void stopBolusDelivering() { + } + + @Override + public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) { + PumpEnactResult result = new PumpEnactResult(); + result.success = false; + result.comment = MainApp.instance().getString(R.string.pumperror); + if (Config.logPumpComm) + log.debug("Setting temp basal absolute: " + result); + return result; + } + + @Override + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + PumpEnactResult result = new PumpEnactResult(); + result.success = false; + result.comment = MainApp.instance().getString(R.string.pumperror); + if (Config.logPumpComm) + log.debug("Settings temp basal percent: " + result); + return result; + } + + @Override + public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { + PumpEnactResult result = new PumpEnactResult(); + result.success = false; + result.comment = MainApp.instance().getString(R.string.pumperror); + if (Config.logPumpComm) + log.debug("Setting extended bolus: " + result); + return result; + } + + @Override + public PumpEnactResult cancelTempBasal() { + PumpEnactResult result = new PumpEnactResult(); + result.success = false; + result.comment = MainApp.instance().getString(R.string.pumperror); + if (Config.logPumpComm) + log.debug("Cancel temp basal: " + result); + return result; + } + + @Override + public PumpEnactResult cancelExtendedBolus() { + PumpEnactResult result = new PumpEnactResult(); + result.success = false; + result.comment = MainApp.instance().getString(R.string.pumperror); + if (Config.logPumpComm) + log.debug("Canceling extended basal: " + result); + return result; + } + + @Override + public JSONObject getJSONStatus() { + JSONObject pump = new JSONObject(); + JSONObject status = new JSONObject(); + JSONObject extended = new JSONObject(); + try { + status.put("status", "normal"); + extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); + try { + extended.put("ActiveProfile", MainApp.getConfigBuilder().getActiveProfile().getProfile().getActiveProfile()); + } catch (Exception e) { + } + status.put("timestamp", DateUtil.toISOString(new Date())); + + pump.put("status", status); + pump.put("extended", extended); + pump.put("clock", DateUtil.toISOString(new Date())); + } catch (JSONException e) { + } + return pump; + } + + @Override + public String deviceID() { + return "MDI"; + } + + @Override + public PumpDescription getPumpDescription() { + return pumpDescription; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java index 2326189406..f865165437 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java @@ -51,7 +51,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { @Override public boolean isEnabled(int type) { - return type == CONSTRAINTS; + return type == CONSTRAINTS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 138fae369f..47ef05e08f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -58,12 +58,12 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { @Override public boolean isEnabled(int type) { - return type == APS && fragmentEnabled; + return type == APS && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; } @Override public boolean isVisibleInTabs(int type) { - return type == APS && fragmentVisible; + return type == APS && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index e46ded9855..62d68ebb23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -450,7 +450,7 @@ public class OverviewFragment extends Fragment { // open loop mode final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; - if (Config.APS) { + if (Config.APS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable) { apsModeView.setVisibility(View.VISIBLE); apsModeView.setBackgroundResource(R.drawable.loopmodeborder); apsModeView.setTextColor(Color.BLACK); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java index a1b5ec8d4e..87a73cb1df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java @@ -66,12 +66,12 @@ public class TempBasalsPlugin implements PluginBase, TempBasalsInterface { @Override public boolean isEnabled(int type) { - return type == TEMPBASAL && fragmentEnabled; + return type == TEMPBASAL && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; } @Override public boolean isVisibleInTabs(int type) { - return type == TEMPBASAL && fragmentVisible; + return type == TEMPBASAL && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; } @Override diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index b559f8bd12..fa211d33b0 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -373,4 +373,5 @@ Pumpa není inicializována, profil nenastaven! Vybrán špatný ovladač pumpy Hodnota bazálu pod minimem. Nenastaveno! + Pera diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 02bd48a9f1..87b200db28 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -386,4 +386,5 @@ Basal value below minimum. Profile not set! BG: Last BG: + MDI