Add ReadStateCommand.
This commit is contained in:
parent
8b21bb1203
commit
5631488cc8
4 changed files with 109 additions and 0 deletions
|
@ -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{" +
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package de.jotomo.ruffyscripter.commands;
|
||||
|
||||
/** The history data read from "My data" */
|
||||
public class History {
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue