Merge branch 'insight' into dev

This commit is contained in:
Milos Kozak 2019-02-02 12:56:33 +01:00
commit 5988910d2c
2 changed files with 28 additions and 54 deletions

View file

@ -34,6 +34,8 @@ import info.nightscout.utils.DecimalFormatter;
public class LocalInsightFragment extends SubscriberFragment implements View.OnClickListener { public class LocalInsightFragment extends SubscriberFragment implements View.OnClickListener {
private static final boolean ENABLE_OPERATING_MODE_BUTTON = false;
private boolean viewsCreated; private boolean viewsCreated;
private Button operatingMode; private Button operatingMode;
private Button tbrOverNotification; private Button tbrOverNotification;
@ -218,7 +220,7 @@ public class LocalInsightFragment extends SubscriberFragment implements View.OnC
return; return;
} }
int string = 0; int string = 0;
operatingMode.setVisibility(View.VISIBLE); if (ENABLE_OPERATING_MODE_BUTTON) operatingMode.setVisibility(View.VISIBLE);
operatingMode.setEnabled(operatingModeCallback == null); operatingMode.setEnabled(operatingModeCallback == null);
switch (LocalInsightPlugin.getInstance().getOperatingMode()) { switch (LocalInsightPlugin.getInstance().getOperatingMode()) {
case STARTED: case STARTED:

View file

@ -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 int bolusID = -1;
private List<BasalProfileBlock> profileBlocks; private List<BasalProfileBlock> profileBlocks;
private boolean limitsFetched; private boolean limitsFetched;
@ -341,25 +343,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
} }
private void fetchBasalProfile() throws Exception { private void fetchBasalProfile() throws Exception {
Class<? extends BRProfileBlock> parameterBlock = null; profileBlocks = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, BRProfile1Block.class).getProfileBlocks();
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();
} }
private void fetchStatus() throws Exception { private void fetchStatus() throws Exception {
@ -452,24 +436,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
profileBlocks.add(profileBlock); profileBlocks.add(profileBlock);
} }
try { try {
BRProfileBlock profileBlock = null; BRProfileBlock profileBlock = new BRProfile1Block();
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;
}
profileBlock.setProfileBlocks(profileBlocks); profileBlock.setProfileBlocks(profileBlocks);
ParameterBlockUtil.writeConfigurationBlock(connectionService, profileBlock); ParameterBlockUtil.writeConfigurationBlock(connectionService, profileBlock);
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
@ -533,12 +500,14 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (detailedBolusInfo.insulin > 0) { if (detailedBolusInfo.insulin > 0) {
try { try {
DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); synchronized ($bolusLock) {
bolusMessage.setBolusType(BolusType.STANDARD); DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
bolusMessage.setDuration(0); bolusMessage.setBolusType(BolusType.STANDARD);
bolusMessage.setExtendedAmount(0); bolusMessage.setDuration(0);
bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); bolusMessage.setExtendedAmount(0);
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
}
result.success = true; result.success = true;
result.enacted = true; result.enacted = true;
Treatment t = new Treatment(); Treatment t = new Treatment();
@ -597,16 +566,18 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override @Override
public void stopBolusDelivering() { public void stopBolusDelivering() {
new Thread(() -> { new Thread(() -> {
try { synchronized ($bolusLock) {
alertService.ignore(AlertType.WARNING_38); try {
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); alertService.ignore(AlertType.WARNING_38);
cancelBolusMessage.setBolusID(bolusID); CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
connectionService.requestMessage(cancelBolusMessage).await(); cancelBolusMessage.setBolusID(bolusID);
confirmAlert(AlertType.WARNING_38); connectionService.requestMessage(cancelBolusMessage).await();
} catch (InsightException e) { confirmAlert(AlertType.WARNING_38);
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName()); } catch (InsightException e) {
} catch (Exception e) { log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
log.error("Exception while canceling bolus", e); } catch (Exception e) {
log.error("Exception while canceling bolus", e);
}
} }
}).start(); }).start();
} }
@ -615,6 +586,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (activeBasalRate == null) return result; if (activeBasalRate == null) return result;
if (activeBasalRate.getActiveBasalRate() == 0) return result;
double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate; double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate;
if (isFakingTempsByExtendedBoluses()) { if (isFakingTempsByExtendedBoluses()) {
PumpEnactResult cancelEBResult = cancelExtendedBolusOnly(); PumpEnactResult cancelEBResult = cancelExtendedBolusOnly();