diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java index 0a78f2a147..2bdd4bba46 100644 --- a/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/CommandResult.java @@ -5,6 +5,8 @@ public class CommandResult { public boolean enacted; public Exception exception; public String message; + public State state; + public History history; public CommandResult() { } @@ -29,6 +31,16 @@ public class CommandResult { return this; } + public CommandResult state(State state) { + this.state = state; + return this; + } + + public CommandResult history(History history) { + this.history = history; + return this; + } + @Override public String toString() { return "CommandResult{" + diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/History.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/History.java new file mode 100644 index 0000000000..ca322f4ac3 --- /dev/null +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/History.java @@ -0,0 +1,5 @@ +package de.jotomo.ruffyscripter.commands; + +/** The history data read from "My data" */ +public class History { +} diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadStateCommand.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadStateCommand.java new file mode 100644 index 0000000000..e4d87a7d9f --- /dev/null +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/ReadStateCommand.java @@ -0,0 +1,44 @@ +package de.jotomo.ruffyscripter.commands; + +import org.monkey.d.ruffy.ruffy.driver.display.Menu; +import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute; +import org.monkey.d.ruffy.ruffy.driver.display.MenuType; +import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import de.jotomo.ruffyscripter.RuffyScripter; + +/** + * Reads the status displayed in the main menu. Usually TBR state or warning/error if any. + * This command is 'read-only', no buttons are pushed and so no vibrations are caused. + */ +public class ReadStateCommand implements Command { + private static final Logger log = LoggerFactory.getLogger(ReadStateCommand.class); + + @Override + public CommandResult execute(RuffyScripter scripter) { + try { + State state = new State(); + Menu displayedMenu = scripter.currentMenu; + MenuType displayedMenuType = displayedMenu.getType(); + if (displayedMenuType == MenuType.MAIN_MENU) { + Double tbrPercentage = (Double) displayedMenu.getAttribute(MenuAttribute.TBR); + if (tbrPercentage != 100) { + state.tbrActive = true; + MenuTime durationMenuTime = ((MenuTime) displayedMenu.getAttribute(MenuAttribute.RUNTIME)); + state.tbrRemainingDuration = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute(); + } + } else if (displayedMenuType == MenuType.WARNING_OR_ERROR) { + state.isErrorOrWarning = true; + state.errorCode = (int) displayedMenu.getAttribute(MenuAttribute.ERROR); + } else { + throw new CommandException().success(false).message("Neither MAIN_MENU nor WARNING_OR_ERROR is displayed, but " + displayedMenuType); + } + + return new CommandResult().success(true).enacted(false).state(state); + } catch (CommandException e) { + return e.toCommandResult(); + } + } +} diff --git a/app/src/main/java/de/jotomo/ruffyscripter/commands/State.java b/app/src/main/java/de/jotomo/ruffyscripter/commands/State.java new file mode 100644 index 0000000000..e2bc75a58f --- /dev/null +++ b/app/src/main/java/de/jotomo/ruffyscripter/commands/State.java @@ -0,0 +1,48 @@ +package de.jotomo.ruffyscripter.commands; + +/** + * State represeting the state of the MAIN_MENU + */ +public class State { + public boolean tbrActive = false; + public int tbrPercent = -1; + public int tbrRemainingDuration = -1; + public boolean isErrorOrWarning = false; + public int errorCode = -1; + + public State tbrActive(boolean tbrActive) { + this.tbrActive = tbrActive; + return this; + } + + public State tbrPercent(int tbrPercent) { + this.tbrPercent = tbrPercent; + return this; + } + + public State tbrRemainingDuration(int tbrRemainingDuration) { + this.tbrRemainingDuration = tbrRemainingDuration; + return this; + } + + public State isErrorOrWarning(boolean isErrorOrWarning) { + this.isErrorOrWarning = isErrorOrWarning; + return this; + } + + public State errorCode(int errorCode) { + this.errorCode = errorCode; + return this; + } + + @Override + public String toString() { + return "State{" + + "tbrActive=" + tbrActive + + ", tbrPercent=" + tbrPercent + + ", tbrRemainingDuration=" + tbrRemainingDuration + + ", isErrorOrWarning=" + isErrorOrWarning + + ", errorCode=" + errorCode + + '}'; + } +}