From c41b12492f2a6d87ce5f3c39de38cb2bed3b4819 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 27 Jul 2017 13:43:50 +0200 Subject: [PATCH] tbr capability retry change --- .../DetermineCapabilitiesCommand.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java index e78bd2f01c..adc740c13e 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/DetermineCapabilitiesCommand.java @@ -22,6 +22,7 @@ import de.jotomo.ruffyscripter.RuffyScripter; public class DetermineCapabilitiesCommand implements Command { private static final Logger log = LoggerFactory.getLogger(DetermineCapabilitiesCommand.class); public static final int UP_STEPS = 75; + public static final int RETRIES = 5; @Override public List validateArguments() { @@ -86,7 +87,7 @@ public class DetermineCapabilitiesCommand implements Command { for (int i = 0; i < UP_STEPS; i++) { scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); scripter.pressUpKey(); - SystemClock.sleep(100); + SystemClock.sleep(200); log.debug("Push #" + (i + 1)); } @@ -97,26 +98,25 @@ public class DetermineCapabilitiesCommand implements Command { //reset the TBR in a controlled manner long percentageChange = maximumTempBasal - activeTempBasal; long percentageSteps = percentageChange / 10; - log.debug("Pressing down " + percentageSteps + " times to get to previous value"); - for (int i = 0; i < percentageSteps; i++) { + + int retries= 0; + while (percentageSteps > 0 && retries < RETRIES) { + log.debug("Pressing down " + percentageSteps + " times to get to previous value. Retry " + retries); + for (int i = 0; i < percentageSteps; i++) { + scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); + scripter.pressDownKey(); + SystemClock.sleep(200); + log.debug("Push #" + (i + 1)); + } + //do the rest if button-presses failed. scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - scripter.pressDownKey(); - SystemClock.sleep(100); - log.debug("Push #" + (i + 1)); + long currentPercentage = readDisplayedTbrPercentage(scripter); + percentageChange = currentPercentage - activeTempBasal; + percentageSteps = percentageChange / 10; + retries++; } - //do the rest if button-presses failed. - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - int i= 0; - while (readDisplayedTbrPercentage(scripter) > activeTempBasal && i < percentageSteps) { - scripter.verifyMenuIsDisplayed(MenuType.TBR_SET); - scripter.pressDownKey(); - SystemClock.sleep(100); - log.debug("Push again as previous buttons failed: #" + i); - i++; - } - //exit menu scripter.pressCheckKey(); scripter.waitForMenuToBeLeft(MenuType.TBR_SET); @@ -125,7 +125,7 @@ public class DetermineCapabilitiesCommand implements Command { private long readDisplayedTbrPercentage(RuffyScripter scripter) { - SystemClock.sleep(250); + SystemClock.sleep(1000); // TODO v2 add timeout? Currently the command execution timeout would trigger if exceeded Object percentageObj = scripter.currentMenu.getAttribute(MenuAttribute.BASAL_RATE); // this as a bit hacky, the display value is blinking, so we might catch that, so