From b0f72fc73600c0a3e4f3f44441e57ee6e7a448ea Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 2 Feb 2019 01:11:26 +0100 Subject: [PATCH 1/4] Only update first basal profile --- .../PumpInsightLocal/LocalInsightPlugin.java | 39 +------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index fc8ac92a93..7084db8883 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -341,25 +341,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } private void fetchBasalProfile() throws Exception { - Class parameterBlock = null; - switch (ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, ActiveBRProfileBlock.class).getActiveBasalProfile()) { - case PROFILE_1: - parameterBlock = BRProfile1Block.class; - break; - case PROFILE_2: - parameterBlock = BRProfile2Block.class; - break; - case PROFILE_3: - parameterBlock = BRProfile3Block.class; - break; - case PROFILE_4: - parameterBlock = BRProfile4Block.class; - break; - case PROFILE_5: - parameterBlock = BRProfile5Block.class; - break; - } - profileBlocks = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, parameterBlock).getProfileBlocks(); + profileBlocks = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, BRProfile1Block.class).getProfileBlocks(); } private void fetchStatus() throws Exception { @@ -452,24 +434,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con profileBlocks.add(profileBlock); } try { - BRProfileBlock profileBlock = null; - switch (activeBasalRate.getActiveBasalProfile()) { - case PROFILE_1: - profileBlock = new BRProfile1Block(); - break; - case PROFILE_2: - profileBlock = new BRProfile2Block(); - break; - case PROFILE_3: - profileBlock = new BRProfile3Block(); - break; - case PROFILE_4: - profileBlock = new BRProfile4Block(); - break; - case PROFILE_5: - profileBlock = new BRProfile5Block(); - break; - } + BRProfileBlock profileBlock = new BRProfile1Block(); profileBlock.setProfileBlocks(profileBlocks); ParameterBlockUtil.writeConfigurationBlock(connectionService, profileBlock); MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); From 1ffd63c83a9a7d3569b5138718362a29cc4352cc Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 2 Feb 2019 01:14:27 +0100 Subject: [PATCH 2/4] Hide operating mode button by default --- .../plugins/PumpInsightLocal/LocalInsightFragment.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightFragment.java index 564a86b4a3..a79fdad542 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightFragment.java @@ -34,6 +34,8 @@ import info.nightscout.utils.DecimalFormatter; public class LocalInsightFragment extends SubscriberFragment implements View.OnClickListener { + private static final boolean ENABLE_OPERATING_MODE_BUTTON = false; + private boolean viewsCreated; private Button operatingMode; private Button tbrOverNotification; @@ -218,7 +220,7 @@ public class LocalInsightFragment extends SubscriberFragment implements View.OnC return; } int string = 0; - operatingMode.setVisibility(View.VISIBLE); + if (ENABLE_OPERATING_MODE_BUTTON) operatingMode.setVisibility(View.VISIBLE); operatingMode.setEnabled(operatingModeCallback == null); switch (LocalInsightPlugin.getInstance().getOperatingMode()) { case STARTED: From a282124497ae09cdfd6e9864b13b3cce1164f047 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 2 Feb 2019 01:38:01 +0100 Subject: [PATCH 3/4] Return pump enact failure when base basal ist 0 duration execution of setTempBasalAbsolute --- .../androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 7084db8883..32270999ea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -580,6 +580,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { PumpEnactResult result = new PumpEnactResult(); if (activeBasalRate == null) return result; + if (activeBasalRate.getActiveBasalRate() == 0) return result; double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate; if (isFakingTempsByExtendedBoluses()) { PumpEnactResult cancelEBResult = cancelExtendedBolusOnly(); From 71c4c411b2b235b8eae210facba8ba7a371fd076 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 2 Feb 2019 11:41:16 +0100 Subject: [PATCH 4/4] Fix race condition for bolus cancel --- .../PumpInsightLocal/LocalInsightPlugin.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java index 32270999ea..a928d56504 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsightLocal/LocalInsightPlugin.java @@ -152,6 +152,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } }; + private final Object $bolusLock = new Object[0]; + private boolean bolusInProgress; private int bolusID = -1; private List profileBlocks; private boolean limitsFetched; @@ -498,12 +500,14 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con PumpEnactResult result = new PumpEnactResult(); if (detailedBolusInfo.insulin > 0) { try { - DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); - bolusMessage.setBolusType(BolusType.STANDARD); - bolusMessage.setDuration(0); - bolusMessage.setExtendedAmount(0); - bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); - bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); + synchronized ($bolusLock) { + DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); + bolusMessage.setBolusType(BolusType.STANDARD); + bolusMessage.setDuration(0); + bolusMessage.setExtendedAmount(0); + bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); + bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); + } result.success = true; result.enacted = true; Treatment t = new Treatment(); @@ -562,16 +566,18 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public void stopBolusDelivering() { new Thread(() -> { - try { - alertService.ignore(AlertType.WARNING_38); - CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); - cancelBolusMessage.setBolusID(bolusID); - connectionService.requestMessage(cancelBolusMessage).await(); - confirmAlert(AlertType.WARNING_38); - } catch (InsightException e) { - log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); - } catch (Exception e) { - log.error("Exception while canceling bolus", e); + synchronized ($bolusLock) { + try { + alertService.ignore(AlertType.WARNING_38); + CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); + cancelBolusMessage.setBolusID(bolusID); + connectionService.requestMessage(cancelBolusMessage).await(); + confirmAlert(AlertType.WARNING_38); + } catch (InsightException e) { + log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); + } catch (Exception e) { + log.error("Exception while canceling bolus", e); + } } }).start(); }