Fix bolus progress dialog with bolus cancel
This commit is contained in:
parent
4146c8a770
commit
7a4d721c29
1 changed files with 27 additions and 23 deletions
|
@ -69,12 +69,7 @@ import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.his
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.StartOfTBREvent;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.StartOfTBREvent;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TotalDailyDoseEvent;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TotalDailyDoseEvent;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TubeFilledEvent;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TubeFilledEvent;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.ActiveBRProfileBlock;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile1Block;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile1Block;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile2Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile3Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile4Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile5Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfileBlock;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfileBlock;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.FactoryMinBolusAmountBlock;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.FactoryMinBolusAmountBlock;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.MaxBasalAmountBlock;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.MaxBasalAmountBlock;
|
||||||
|
@ -155,7 +150,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Object $bolusLock = new Object[0];
|
private final Object $bolusLock = new Object[0];
|
||||||
private int bolusID = -1;
|
private int bolusID;
|
||||||
|
private boolean bolusCancelled;
|
||||||
private List<BasalProfileBlock> profileBlocks;
|
private List<BasalProfileBlock> profileBlocks;
|
||||||
private boolean limitsFetched;
|
private boolean limitsFetched;
|
||||||
private double maximumBolusAmount;
|
private double maximumBolusAmount;
|
||||||
|
@ -269,7 +265,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnecting() {
|
public boolean isConnecting() {
|
||||||
if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) return false;
|
if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this))
|
||||||
|
return false;
|
||||||
InsightState state = connectionService.getState();
|
InsightState state = connectionService.getState();
|
||||||
return state == InsightState.CONNECTING
|
return state == InsightState.CONNECTING
|
||||||
|| state == InsightState.APP_CONNECT_MESSAGE
|
|| state == InsightState.APP_CONNECT_MESSAGE
|
||||||
|
@ -517,6 +514,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
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();
|
||||||
|
bolusCancelled = false;
|
||||||
}
|
}
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -539,7 +537,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
while (true) {
|
while (true) {
|
||||||
synchronized ($bolusLock) {
|
synchronized ($bolusLock) {
|
||||||
if (bolusID == -1) break;
|
if (bolusCancelled) break;
|
||||||
}
|
}
|
||||||
OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode();
|
OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode();
|
||||||
if (operatingMode != OperatingMode.STARTED) break;
|
if (operatingMode != OperatingMode.STARTED) break;
|
||||||
|
@ -558,12 +556,18 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount());
|
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount());
|
||||||
if (percentBefore != bolusingEvent.percent)
|
if (percentBefore != bolusingEvent.percent)
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
} else if (trials == -1 || trials++ >= 5) {
|
} else {
|
||||||
|
synchronized ($bolusLock) {
|
||||||
|
if (bolusCancelled || trials == -1 || trials++ >= 5) {
|
||||||
|
if (!bolusCancelled) {
|
||||||
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin);
|
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin);
|
||||||
bolusingEvent.percent = 100;
|
bolusingEvent.percent = 100;
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
}
|
}
|
||||||
readHistory();
|
readHistory();
|
||||||
|
@ -589,13 +593,14 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
synchronized ($bolusLock) {
|
|
||||||
try {
|
try {
|
||||||
|
synchronized ($bolusLock) {
|
||||||
alertService.ignore(AlertType.WARNING_38);
|
alertService.ignore(AlertType.WARNING_38);
|
||||||
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
|
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
|
||||||
cancelBolusMessage.setBolusID(bolusID);
|
cancelBolusMessage.setBolusID(bolusID);
|
||||||
connectionService.requestMessage(cancelBolusMessage).await();
|
connectionService.requestMessage(cancelBolusMessage).await();
|
||||||
bolusID = -1;
|
bolusCancelled = true;
|
||||||
|
}
|
||||||
confirmAlert(AlertType.WARNING_38);
|
confirmAlert(AlertType.WARNING_38);
|
||||||
} catch (AppLayerErrorException e) {
|
} catch (AppLayerErrorException e) {
|
||||||
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||||
|
@ -604,7 +609,6 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue