From 99830b05b65d8576ade8f8a32dd67260236b57cf Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 15 Jul 2017 16:46:12 +0200 Subject: [PATCH] Fix detecting error state on connection and fix cancelling TBR. When there's an error, timing is crucial. Waiting for the blinking error code to be readable hangs the thread running the command. --- .../java/de/jotomo/ruffyscripter/RuffyScripter.java | 13 +------------ .../ruffyscripter/commands/SetTbrCommand.java | 13 ++++++++----- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 7fb389d8b9..c58f43d95c 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -129,8 +129,7 @@ public class RuffyScripter { // check if pump is an an error state if (currentMenu != null && currentMenu.getType() == MenuType.WARNING_OR_ERROR) { try { - PumpAlert alert = readDisplayPumpAlert(); - return new CommandResult().message("Pump is in an error state: " + alert + " (" + alert.code + ")"); + return new CommandResult().message("Pump is in an error state: " + currentMenu.getAttribute(MenuAttribute.MESSAGE)); } catch (Exception e) { return new CommandResult().message("Pump is in an error state, reading the error state resulted in the attached exception").exception(e); } @@ -344,14 +343,4 @@ public class RuffyScripter { } return state; } - - public PumpAlert readDisplayPumpAlert() { - Object errorObj = currentMenu.getAttribute(MenuAttribute.ERROR); - while (errorObj == null) { - SystemClock.sleep(10); - errorObj = currentMenu.getAttribute(MenuAttribute.ERROR); - } - String errorMsg = (String) currentMenu.getAttribute(MenuAttribute.MESSAGE); - return new PumpAlert((int) errorObj, errorMsg); - } } diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index 5bb90b2861..c12d588a51 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -190,19 +190,22 @@ public class SetTbrCommand implements Command { scripter.pressCheckKey(); // we could read remaining duration from MAIN_MENU, but but the time we're here, - // we could have moved from 0:02 to 0:01, so instead,/ check if a TBR CANCELLED alert + // we could have moved from 0:02 to 0:01, so instead, check if a "TBR CANCELLED alert" // is raised and if so dismiss it scripter.waitForMenuToBeLeft(MenuType.TBR_SET); long inTwoSeconds = System.currentTimeMillis() + 2 * 1000; boolean alertProcessed = false; while (System.currentTimeMillis() < inTwoSeconds && !alertProcessed) { if (scripter.currentMenu.getType() == MenuType.WARNING_OR_ERROR) { - // check the raised alarm is TBR CANCELLED - PumpAlert alert = scripter.readDisplayPumpAlert(); - if (alert.code != 6 || Objects.equals(alert.msg, "TBR CANCELLED")) { + // check the raised alarm is TBR CANCELLED. + // note that the message is permanently displayed, while the error code is blinking. + // wait till the error code can be read results in the code hanging, despite + // menu updates coming in, so just check the message + String errorMsg = (String) scripter.currentMenu.getAttribute(MenuAttribute.MESSAGE); + if (!errorMsg.equals("TBR CANCELLED")) { throw new CommandException().success(false).enacted(false) .message("An alert other than the expected TBR CANCELLED was raised by the pump: " - + alert.code + "(" + alert.msg + "). Please check the pump."); + + errorMsg + ". Please check the pump."); } // confirm "TBR CANCELLED alert" scripter.pressCheckKey();