From 68af342eeba30f296416d25492d64923070d9e25 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 5 Dec 2017 00:47:20 +0100 Subject: [PATCH] Update combo stuff to work with new queue. --- .../plugins/PumpCombo/ComboFragment.java | 2 +- .../plugins/PumpCombo/ComboPlugin.java | 40 ++++++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index b2d2185388..26cf83fe00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -61,7 +61,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis public void onClick(View view) { switch (view.getId()) { case R.id.combo_refresh: - new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request")).start(); + new Thread(() -> ComboPlugin.getPlugin().getPumpStatus()).start(); break; case R.id.combo_error_history: ComboAlertHistoryDialog ehd = new ComboAlertHistoryDialog(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 4ae5c377da..b7f2ebc5b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -215,12 +215,37 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } @Override - public synchronized int setNewBasalProfile(Profile profile) { + public boolean isConnected() { + return true; + } + + @Override + public boolean isConnecting() { + return false; + } + + @Override + public void connect(String reason) { + // we're not doing that + } + + @Override + public void disconnect(String reason) { + // we're not doing that + } + + @Override + public void stopConnecting() { + // we're not doing that + } + + @Override + public synchronized PumpEnactResult setNewBasalProfile(Profile profile) { if (!isInitialized()) { log.error("setNewBasalProfile not initialized"); Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); MainApp.bus().post(new EventNewNotification(notification)); - return PumpInterface.FAILED; + return new PumpEnactResult().success(false).enacted(false).comment(MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet)); } BasalProfile requestedBasalProfile = convertProfileToComboProfile(profile); @@ -228,7 +253,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf //dismiss previously "FAILED" overview notifications MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); - return PumpInterface.NOT_NEEDED; + return new PumpEnactResult().success(true).enacted(false); } CommandResult setResult = runCommand(MainApp.sResources.getString(R.string.combo_activity_setting_basal_profile), 2, @@ -236,7 +261,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!setResult.success) { Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT); MainApp.bus().post(new EventNewNotification(notification)); - return PumpInterface.FAILED; + return new PumpEnactResult().success(false).enacted(false); } /* don't re-read basal profile to not trigger pump bug; setBasalProfile command checks the total at the end, which must suffice @@ -252,7 +277,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf //issue success notification Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60); MainApp.bus().post(new EventNewNotification(notification)); - return PumpInterface.SUCCESS; + return new PumpEnactResult().success(true).enacted(true); } @Override @@ -301,7 +326,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf * reservoir level and checks the running TBR on the pump. */ @Override - public synchronized void refreshDataFromPump(String reason) { + public synchronized void getPumpStatus() { log.debug("RefreshDataFromPump called"); if (!pump.initialized) { long maxWait = System.currentTimeMillis() + 15 * 1000; @@ -521,6 +546,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf // See if the queue might solve this, otherwise we could add a check in runCommand // (but can't currently determine if the request is a basal request) // or have the scripter skip the next bolus that comes in + // TODO related: if pump can't be reached, a bolus will wait until pump is available again + // and will then bolus all requested boluses ... because 'synchronized' makes for a dumb + // queue if (bolusInProgress) { ruffyScripter.cancelBolus(); }