More bolus work.
This commit is contained in:
parent
ab900fda6c
commit
74bbab9cf1
|
@ -39,6 +39,8 @@ import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateG
|
|||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
||||
import static de.jotomo.ruffy.spi.BolusProgressReporter.State.FINISHED;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
|
@ -431,20 +433,17 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
}
|
||||
|
||||
// check enough insulin left for bolus
|
||||
if (Math.round(detailedBolusInfo.insulin) > pump.reservoirLevel) {
|
||||
if (Math.round(detailedBolusInfo.insulin + 0.5) > reservoirBolusResult.reservoirLevel) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.sResources.getString(R.string.combo_reservoir_level_insufficant_for_bolus));
|
||||
}
|
||||
|
||||
// verify we're update to date and know the most recent bolus
|
||||
Bolus lastPumpBolus = null;
|
||||
if (!reservoirBolusResult.history.bolusHistory.isEmpty()) {
|
||||
lastPumpBolus = reservoirBolusResult.history.bolusHistory.get(0);
|
||||
}
|
||||
if (!Objects.equals(pump.lastBolus, lastPumpBolus)) {
|
||||
checkPumpHistory();
|
||||
return new PumpEnactResult().success(false).enacted(false).
|
||||
comment(MainApp.sResources.getString(R.string.combo_pump_bolus_history_state_mismtach));
|
||||
if (!Objects.equals(pump.lastBolus, reservoirBolusResult.lastBolus)) {
|
||||
// TODO needs syncing with DB first
|
||||
// new Thread(this::checkPumpHistory).start();
|
||||
// return new PumpEnactResult().success(false).enacted(false).
|
||||
// comment(MainApp.sResources.getString(R.string.combo_pump_bolus_history_state_mismatch));
|
||||
}
|
||||
|
||||
if (cancelBolus) {
|
||||
|
@ -462,22 +461,21 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
bolusInProgress = false;
|
||||
|
||||
if (!bolusCmdResult.success) {
|
||||
new Thread(this::checkPumpHistory).start();
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
|
||||
}
|
||||
|
||||
// verify delivered bolus
|
||||
reservoirBolusResult = runCommand(null, 3,
|
||||
ruffyScripter::readReservoirLevelAndLastBolus);
|
||||
reservoirBolusResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus);
|
||||
if (!reservoirBolusResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
|
||||
}
|
||||
lastPumpBolus = null;
|
||||
if (!reservoirBolusResult.history.bolusHistory.isEmpty()) {
|
||||
lastPumpBolus = reservoirBolusResult.history.bolusHistory.get(0);
|
||||
}
|
||||
if (lastPumpBolus == null || lastPumpBolus.amount != detailedBolusInfo.insulin) {
|
||||
Bolus lastPumpBolus = reservoirBolusResult.lastBolus;
|
||||
if (cancelBolus) {
|
||||
// if cancellation was requested, the delivered bolus is allowed to differ from requested
|
||||
} else if (lastPumpBolus == null || lastPumpBolus.amount != detailedBolusInfo.insulin) {
|
||||
return new PumpEnactResult().success(false).enacted(false).
|
||||
comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
|
||||
}
|
||||
|
@ -485,20 +483,29 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
// update local data
|
||||
pump.reservoirLevel = reservoirBolusResult.reservoirLevel;
|
||||
pump.lastBolus = lastPumpBolus;
|
||||
pump.state = reservoirBolusResult.state;
|
||||
|
||||
// add treatment record to DB
|
||||
detailedBolusInfo.insulin = lastPumpBolus.amount;
|
||||
detailedBolusInfo.date = lastPumpBolus.timestamp;
|
||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
|
||||
return new PumpEnactResult()
|
||||
.success(true)
|
||||
.enacted(true)
|
||||
.bolusDelivered(lastPumpBolus.amount)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
// add treatment record to DB (if it wasn't cancelled)
|
||||
if (lastPumpBolus != null && (lastPumpBolus.amount > 0)) {
|
||||
detailedBolusInfo.insulin = lastPumpBolus.amount;
|
||||
detailedBolusInfo.date = lastPumpBolus.timestamp;
|
||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
return new PumpEnactResult()
|
||||
.success(true)
|
||||
.enacted(true)
|
||||
.bolusDelivered(lastPumpBolus.amount)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
} else {
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
}
|
||||
} finally {
|
||||
// BolusCommand.execute() intentionally doesn't close the progress dialog if an error
|
||||
// occurred/ so it stays open while the connection was re-established if needed and/or
|
||||
// this method did recovery
|
||||
bolusProgressReporter.report(FINISHED, 100, 0);
|
||||
pump.activity = null;
|
||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||
MainApp.bus().post(new EventRefreshOverview("Combo Bolus"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -787,9 +787,9 @@
|
|||
<string name="enable_pump_unreachable_alert">Alert if pump unreachable for 30 min</string>
|
||||
<string name="combo_pump_never_connected">Never</string>
|
||||
<string name="combo_reservoir_level_insufficant_for_bolus">Not enough insulin left in reservoir for bolus</string>
|
||||
<string name="combo_pump_bolus_history_state_mismtach">A bolus has been given recently on the pump directly of which AndroidAPS has only just become aware of. Please verify IOB and bolus again if needed. No bolus has been given.</string>
|
||||
<string name="combo_pump_bolus_history_state_mismatch">A bolus has been given recently on the pump directly of which AndroidAPS has only just become aware of. The pump\'s history is currently being read. Please check che Combo page, verify last bolus and IOB and bolus again if needed. No bolus has been given.</string>
|
||||
<string name="combo_pump_bolus_verification_failed">Bolus delivery verification failed. The pump history will be read again on the next loop run or when refreshing from the Combo page. Please check and bolus again if needed.</string>
|
||||
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
|
||||
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please check the Combo page and bolus again as needed.</string>
|
||||
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please check the Combo page and bolus again as needed.</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package de.jotomo.ruffy.spi;
|
||||
|
||||
import java.util.Date;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import de.jotomo.ruffy.spi.history.Bolus;
|
||||
import de.jotomo.ruffy.spi.history.PumpHistory;
|
||||
|
@ -18,6 +18,7 @@ public class CommandResult {
|
|||
/** State of the pump *after* command execution. */
|
||||
public PumpState state;
|
||||
/** History if requested by the command. */
|
||||
@Nullable
|
||||
public PumpHistory history;
|
||||
/** Basal rate profile if requested. */
|
||||
public BasalProfile basalProfile;
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import de.jotomo.ruffy.spi.BolusProgressReporter;
|
||||
import de.jotomo.ruffy.spi.CommandResult;
|
||||
|
@ -135,7 +136,7 @@ public class BolusCommand extends BaseCommand {
|
|||
throw new CommandException("Pump is showing exotic warning: " + warningCode);
|
||||
}
|
||||
}
|
||||
if (bolusRemaining != null && !bolusRemaining.equals(lastBolusReported)) {
|
||||
if (bolusRemaining != null && !Objects.equals(bolusRemaining, lastBolusReported)) {
|
||||
log.debug("Delivering bolus, remaining: " + bolusRemaining);
|
||||
int percentDelivered = (int) (100 - (bolusRemaining / bolus * 100));
|
||||
bolusProgressReporter.report(DELIVERING, percentDelivered, bolus - bolusRemaining);
|
||||
|
@ -147,7 +148,12 @@ public class BolusCommand extends BaseCommand {
|
|||
bolusProgressReporter.report(DELIVERED, 100, bolus);
|
||||
result.success = true;
|
||||
} finally {
|
||||
bolusProgressReporter.report(FINISHED, 100, 0);
|
||||
// this is a bit messy: when there's an issue (e.g. disconnected) the dialog should
|
||||
// stay open, since we're recovering. So leave it open and make sure in ComboPlugin.deliverBolus
|
||||
// the dialog is closed at the end.
|
||||
if (result.success) {
|
||||
bolusProgressReporter.report(FINISHED, 100, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue