SetTbr: wait if an existing TBR is about to run out.

See code comment.
This commit is contained in:
Johannes Mockenhaupt 2017-12-13 11:07:57 +01:00
parent 536bd10e9b
commit 3156efaaf6
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import de.jotomo.ruffy.spi.PumpState;
import de.jotomo.ruffy.spi.PumpWarningCodes;
import de.jotomo.ruffy.spi.WarningOrErrorCode;
@ -63,6 +64,25 @@ public class SetTbrCommand extends BaseCommand {
boolean cancellingTbr = percentage == 100;
try {
// When programming a new TBR while an existing TBR runs out, a TBR CANCELLED
// alert is raised (failing the command, requiring a reconnect and confirming alert
// and all). To avoid this, wait until the active TBR runs out if the active TBR
// is about to end
long timeout = System.currentTimeMillis() + 65 * 1000;
PumpState state = scripter.readPumpStateInternal();
if (state.tbrRemainingDuration == 1) {
while (state.tbrActive && System.currentTimeMillis() < timeout) {
log.debug("Waiting for existing TBR to run out to avoid alert while setting TBR");
scripter.waitForScreenUpdate();
state = scripter.readPumpStateInternal();
}
// if we waited above and a cancellation was requested, we already completed the request
if (!state.tbrActive && cancellingTbr) {
result.success = true;
return;
}
}
enterTbrMenu();
boolean increasingPercentage = inputTbrPercentage();
verifyDisplayedTbrPercentage(increasingPercentage);