From e5a326c3771624745f575a93b7a81cf12a76022c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 7 Jun 2017 18:10:07 +0200 Subject: [PATCH] nsclient always use virtual pump, more sync fixes --- .../java/info/nightscout/androidaps/MainApp.java | 3 ++- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 5 ++++- .../plugins/Overview/Dialogs/NewTreatmentDialog.java | 2 ++ .../plugins/Overview/Dialogs/WizardDialog.java | 2 ++ .../plugins/Overview/OverviewFragment.java | 2 ++ .../plugins/PumpVirtual/VirtualPumpFragment.java | 12 +++--------- .../plugins/PumpVirtual/VirtualPumpPlugin.java | 7 +++++++ .../SmsCommunicator/SmsCommunicatorPlugin.java | 2 ++ .../androidaps/plugins/Wear/ActionStringHandler.java | 2 ++ 9 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 015bad2651..1e49b03d73 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Fragment; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.plugins.PumpMDI.MDIFragment; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpFragment; +import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment; import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpFragment; import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; @@ -102,7 +103,7 @@ public class MainApp extends Application { if (Config.DANARv2) pluginsList.add(DanaRv2Fragment.getPlugin()); pluginsList.add(CareportalFragment.getPlugin()); if (Config.MDI) pluginsList.add(MDIFragment.getPlugin()); - if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpFragment.getPlugin()); + if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance()); if (Config.LOOPENABLED) pluginsList.add(LoopFragment.getPlugin()); if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin()); if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAFragment.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index dce0a48a61..34ac7626e4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.utils.NSUpload; /** @@ -275,7 +276,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain // PluginBase.PUMP pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.PUMP); activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP); - if (Config.logConfigBuilder && activePump != null) + if (activePump == null) + activePump = VirtualPumpPlugin.getInstance(); // for NSClient build + if (Config.logConfigBuilder) log.debug("Selected pump interface: " + ((PluginBase) activePump).getName()); for (PluginBase p : pluginsInCategory) { if (!p.getName().equals(((PluginBase) activePump).getName())) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index b908507d09..9b6b7a0f45 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -27,6 +27,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.CareportalEvent; +import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; @@ -112,6 +113,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene detailedBolusInfo.insulin = finalInsulinAfterConstraints; detailedBolusInfo.carbs = finalCarbsAfterConstraints; detailedBolusInfo.context = context; + detailedBolusInfo.source = Source.USER; PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { AlertDialog.Builder builder = new AlertDialog.Builder(context); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index f3faaafa2f..5ba5f3a6f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -48,6 +48,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; +import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; @@ -333,6 +334,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com detailedBolusInfo.glucoseType = "Manual"; detailedBolusInfo.carbTime = carbTime; detailedBolusInfo.boluscalc = boluscalcJSON; + detailedBolusInfo.source = Source.USER; result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.treatmentdeliveryerror), result.comment, null); 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 c2d9dd7766..6c10a1e8d7 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 @@ -73,6 +73,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; +import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; @@ -698,6 +699,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, detailedBolusInfo.carbs = finalCarbsAfterConstraints; detailedBolusInfo.context = context; detailedBolusInfo.boluscalc = boluscalcJSON; + detailedBolusInfo.source = Source.USER; PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo); if (!result.success) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 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 ef9efe4464..bd3cb6f978 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 @@ -25,12 +25,6 @@ import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpd public class VirtualPumpFragment extends Fragment { private static Logger log = LoggerFactory.getLogger(VirtualPumpFragment.class); - private static VirtualPumpPlugin virtualPumpPlugin = new VirtualPumpPlugin(); - - public static VirtualPumpPlugin getPlugin() { - return virtualPumpPlugin; - } - TextView basaBasalRateView; TextView tempBasalView; TextView extendedBolusView; @@ -93,7 +87,7 @@ public class VirtualPumpFragment extends Fragment { @Override public void run() { - basaBasalRateView.setText(virtualPumpPlugin.getBaseBasalRate() + "U"); + basaBasalRateView.setText(VirtualPumpPlugin.getInstance().getBaseBasalRate() + "U"); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(new Date().getTime()).toString()); } else { @@ -104,8 +98,8 @@ public class VirtualPumpFragment extends Fragment { } else { extendedBolusView.setText(""); } - batteryView.setText(VirtualPumpPlugin.batteryPercent + "%"); - reservoirView.setText(VirtualPumpPlugin.reservoirInUnits + "U"); + batteryView.setText(VirtualPumpPlugin.getInstance().batteryPercent + "%"); + reservoirView.setText(VirtualPumpPlugin.getInstance().reservoirInUnits + "U"); } }); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 309c031803..a53be576f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -46,6 +46,13 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { PumpDescription pumpDescription = new PumpDescription(); + static VirtualPumpPlugin instance = null; + public static VirtualPumpPlugin getInstance() { + if (instance == null) + instance = new VirtualPumpPlugin(); + return instance; + } + public VirtualPumpPlugin() { pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.1d; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index e77e16005f..4e81aa49d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -27,6 +27,7 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; +import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; @@ -465,6 +466,7 @@ public class SmsCommunicatorPlugin implements PluginBase { danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested; + detailedBolusInfo.source = Source.USER; PumpEnactResult result = pumpInterface.deliverTreatment(detailedBolusInfo); if (result.success) { reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index 9c4fc24f25..7969817dc3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; +import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.PluginBase; @@ -390,6 +391,7 @@ public class ActionStringHandler { DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo.insulin = amount; detailedBolusInfo.carbs = carbs; + detailedBolusInfo.source = Source.USER; PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(detailedBolusInfo); if (!result.success) { sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +