Move confirmAlert method to scripter.
(cherry picked from commit f018d42)
This commit is contained in:
parent
b1d000eae3
commit
c96122cbed
|
@ -582,6 +582,39 @@ public class RuffyScripter {
|
|||
// only ensureConnected() uses the method with the timeout parameter; inline that code,
|
||||
// so we can use a custom timeout and give a better error message in case of failure
|
||||
|
||||
|
||||
// TODO confirmAlarms? and report back which were cancelled?
|
||||
|
||||
/** Confirms and dismisses the given alert if it's raised before the timeout */
|
||||
public boolean confirmAlert(String alertMessage, int maxWaitMs) {
|
||||
long inFiveSeconds = System.currentTimeMillis() + maxWaitMs;
|
||||
boolean alertProcessed = false;
|
||||
while (System.currentTimeMillis() < inFiveSeconds && !alertProcessed) {
|
||||
if (getCurrentMenu().getType() == MenuType.WARNING_OR_ERROR) {
|
||||
// Note that the message is permanently displayed, while the error code is blinking.
|
||||
// A wait till the error code can be read results in the code hanging, despite
|
||||
// menu updates coming in, so just check the message.
|
||||
// TODO quick try if the can't make reading the error code work ..
|
||||
String errorMsg = (String) getCurrentMenu().getAttribute(MenuAttribute.MESSAGE);
|
||||
if (!errorMsg.equals(alertMessage)) {
|
||||
throw new CommandException().success(false).enacted(false)
|
||||
.message("An alert other than the expected " + alertMessage + " was raised by the pump: "
|
||||
+ errorMsg + ". Please check the pump.");
|
||||
}
|
||||
// confirm alert
|
||||
verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR);
|
||||
pressCheckKey();
|
||||
// dismiss alert
|
||||
verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR);
|
||||
pressCheckKey();
|
||||
waitForMenuToBeLeft(MenuType.WARNING_OR_ERROR);
|
||||
alertProcessed = true;
|
||||
}
|
||||
SystemClock.sleep(10);
|
||||
}
|
||||
return alertProcessed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the menu update is in
|
||||
*/
|
||||
|
|
|
@ -1,17 +1,30 @@
|
|||
package de.jotomo.ruffyscripter.commands;
|
||||
|
||||
import android.os.SystemClock;
|
||||
|
||||
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
|
||||
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
|
||||
|
||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||
|
||||
public abstract class BaseCommand implements Command {
|
||||
// RS will inject itself here
|
||||
protected RuffyScripter scripter;
|
||||
@Override public void setScripter(RuffyScripter scripter) { this.scripter = scripter; }
|
||||
|
||||
@Override
|
||||
public void setScripter(RuffyScripter scripter) {
|
||||
this.scripter = scripter;
|
||||
}
|
||||
|
||||
// TODO upcoming
|
||||
protected final boolean canBeCancelled = true;
|
||||
protected volatile boolean cancelRequested = false;
|
||||
|
||||
public void requestCancellation() {
|
||||
cancelRequested = true;
|
||||
cancelRequested = true;
|
||||
}
|
||||
|
||||
public boolean isCancellable() {
|
||||
return canBeCancelled;
|
||||
}
|
||||
public boolean isCancellable() { return canBeCancelled; }
|
||||
}
|
||||
|
|
|
@ -191,13 +191,6 @@ public class CancellableBolusCommand extends BolusCommand {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO confirmAlarms? and report back which were cancelled?
|
||||
|
||||
private boolean confirmAlert(String alertText, int maxWaitTillExpectedAlert) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
public void requestCancellation() {
|
||||
cancelRequested = true;
|
||||
progressReportCallback.report(STOPPING, 0, 0);
|
||||
|
|
|
@ -226,36 +226,7 @@ public class SetTbrCommand extends BaseCommand {
|
|||
// We could read the remaining duration from MAIN_MENU, but by the time we're here,
|
||||
// the pump could have moved from 0:02 to 0:01, so instead, check if a "TBR CANCELLED" alert
|
||||
// is raised and if so dismiss it
|
||||
confirmAlert("TBR CANCELLED", 5000);
|
||||
}
|
||||
|
||||
/** Confirms and dismisses the given alert if it's raised before the timeout */
|
||||
private void confirmAlert(String alertMessage, int maxWaitMs) {
|
||||
long inFiveSeconds = System.currentTimeMillis() + maxWaitMs;
|
||||
boolean alertProcessed = false;
|
||||
while (System.currentTimeMillis() < inFiveSeconds && !alertProcessed) {
|
||||
if (scripter.getCurrentMenu().getType() == MenuType.WARNING_OR_ERROR) {
|
||||
// Note that the message is permanently displayed, while the error code is blinking.
|
||||
// A wait till the error code can be read results in the code hanging, despite
|
||||
// menu updates coming in, so just check the message.
|
||||
// TODO quick try if the can't make reading the error code work ..
|
||||
String errorMsg = (String) scripter.getCurrentMenu().getAttribute(MenuAttribute.MESSAGE);
|
||||
if (!errorMsg.equals(alertMessage)) {
|
||||
throw new CommandException().success(false).enacted(false)
|
||||
.message("An alert other than the expected " + alertMessage + " was raised by the pump: "
|
||||
+ errorMsg + ". Please check the pump.");
|
||||
}
|
||||
// confirm alert
|
||||
scripter.verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR);
|
||||
scripter.pressCheckKey();
|
||||
// dismiss alert
|
||||
scripter.verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR);
|
||||
scripter.pressCheckKey();
|
||||
scripter.waitForMenuToBeLeft(MenuType.WARNING_OR_ERROR);
|
||||
alertProcessed = true;
|
||||
}
|
||||
SystemClock.sleep(10);
|
||||
}
|
||||
scripter.confirmAlert("TBR CANCELLED", 5000);
|
||||
}
|
||||
|
||||
private void verifyMainMenuShowsNoActiveTbr() {
|
||||
|
|
Loading…
Reference in a new issue