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 {
synchronized ($bolusLock) {
DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
bolusMessage.setBolusType(BolusType.STANDARD); bolusMessage.setBolusType(BolusType.STANDARD);
bolusMessage.setDuration(0); bolusMessage.setDuration(0);
bolusMessage.setExtendedAmount(0); bolusMessage.setExtendedAmount(0);
bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); 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,6 +566,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override @Override
public void stopBolusDelivering() { public void stopBolusDelivering() {
new Thread(() -> { new Thread(() -> {
synchronized ($bolusLock) {
try { try {
alertService.ignore(AlertType.WARNING_38); alertService.ignore(AlertType.WARNING_38);
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
@ -608,6 +578,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
} catch (Exception e) { } catch (Exception e) {
log.error("Exception while canceling bolus", 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();