update setTBRCommand to way faster methods in scripter
This commit is contained in:
parent
d35283ad74
commit
ac3859dcae
|
@ -21,6 +21,7 @@ import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.SET;
|
||||||
import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.SET_TBR;
|
import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.SET_TBR;
|
||||||
import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.SET_TIME;
|
import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.SET_TIME;
|
||||||
import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.TBR;
|
import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.TBR;
|
||||||
|
import static de.jotomo.ruffyscripter.commands.SetTbrCommand.State.TIME;
|
||||||
|
|
||||||
public class SetTbrCommand implements Command {
|
public class SetTbrCommand implements Command {
|
||||||
private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class);
|
private static final Logger log = LoggerFactory.getLogger(SetTbrCommand.class);
|
||||||
|
@ -66,6 +67,7 @@ public class SetTbrCommand implements Command {
|
||||||
MAIN,
|
MAIN,
|
||||||
TBR,
|
TBR,
|
||||||
SET_TBR,
|
SET_TBR,
|
||||||
|
TIME,
|
||||||
SET_TIME,
|
SET_TIME,
|
||||||
SET,
|
SET,
|
||||||
AFTER,
|
AFTER,
|
||||||
|
@ -102,6 +104,7 @@ public class SetTbrCommand implements Command {
|
||||||
timeout = timeoutSec*1000;
|
timeout = timeoutSec*1000;
|
||||||
}
|
}
|
||||||
private MenuType lastMenu;
|
private MenuType lastMenu;
|
||||||
|
private int retries = 0;
|
||||||
private void tick()
|
private void tick()
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
|
@ -112,42 +115,29 @@ public class SetTbrCommand implements Command {
|
||||||
updateState(MAIN,120);
|
updateState(MAIN,120);
|
||||||
lastMenu = MenuType.MAIN_MENU;
|
lastMenu = MenuType.MAIN_MENU;
|
||||||
log.debug("found MAIN_MENU -> state:MAIN");
|
log.debug("found MAIN_MENU -> state:MAIN");
|
||||||
|
retries=3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MAIN:
|
case MAIN:
|
||||||
if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_MENU)
|
if(retries>0)
|
||||||
{
|
if(scripter.goToMainMenuScreen(MenuType.TBR_MENU,30000))
|
||||||
updateState(TBR,30);
|
{
|
||||||
scripter.pressCheckKey();
|
updateState(TBR,30);
|
||||||
log.debug("found TBR_MENU -> state:TBR");
|
retries=0;
|
||||||
try {
|
|
||||||
Thread.sleep(750);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else if(scripter.currentMenu!=null && scripter.currentMenu.getType()!=lastMenu)
|
retries--;
|
||||||
{
|
|
||||||
lastMenu = scripter.currentMenu.getType();
|
|
||||||
updateState(MAIN,30);
|
|
||||||
scripter.pressMenuKey();
|
|
||||||
log.debug("found Menu:"+lastMenu+" -> state:MAIN");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
updateState(ERROR,30);
|
||||||
scripter.pressMenuKey();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TBR:
|
case TBR:
|
||||||
if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_SET)
|
if(scripter.enterMenu(MenuType.TBR_MENU,MenuType.TBR_SET, RuffyScripter.Key.CHECK,20000))
|
||||||
{
|
{
|
||||||
updateState(SET_TBR,60);
|
updateState(SET_TBR,60);
|
||||||
|
retries = 10;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
updateState(ERROR,30);
|
||||||
scripter.pressMenuKey();
|
|
||||||
updateState(TBR,60);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SET_TBR:
|
case SET_TBR:
|
||||||
if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_SET)
|
if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_SET)
|
||||||
|
@ -156,40 +146,46 @@ public class SetTbrCommand implements Command {
|
||||||
if(percentageObj != null && percentageObj instanceof Double)
|
if(percentageObj != null && percentageObj instanceof Double)
|
||||||
{
|
{
|
||||||
double currentPercentage = ((Double) percentageObj).doubleValue();
|
double currentPercentage = ((Double) percentageObj).doubleValue();
|
||||||
if(currentPercentage < percentage)
|
|
||||||
|
if(currentPercentage!=percentage)
|
||||||
{
|
{
|
||||||
scripter.pressUpKey();
|
if(retries>0) {
|
||||||
updateState(SET_TBR,30);
|
retries--;
|
||||||
}
|
int steps = (int) ((percentage - currentPercentage) / 10.0);
|
||||||
else if(currentPercentage > percentage)
|
scripter.step(steps,(steps<0? RuffyScripter.Key.DOWN: RuffyScripter.Key.UP), 3000);
|
||||||
{
|
}
|
||||||
scripter.pressDownKey();
|
else
|
||||||
updateState(SET_TBR,30);
|
updateState(ERROR,30);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(percentage==100)
|
if(percentage==100)
|
||||||
{
|
{
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
updateState(SET, 30);
|
updateState(SET,30);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scripter.pressMenuKey();
|
updateState(TIME, 30);
|
||||||
updateState(SET_TIME, 30);
|
|
||||||
}
|
}
|
||||||
|
retries=10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_DURATION)
|
|
||||||
{
|
|
||||||
scripter.pressMenuKey();
|
|
||||||
updateState(SET_TBR,60);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
updateState(ERROR,30);
|
updateState(ERROR,30);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TIME:
|
||||||
|
if((scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_DURATION) || scripter.enterMenu(MenuType.TBR_SET,MenuType.TBR_DURATION, RuffyScripter.Key.MENU,20000))
|
||||||
|
{
|
||||||
|
updateState(SET_TIME,60);
|
||||||
|
retries = 10;
|
||||||
|
}
|
||||||
|
else if(retries==0)
|
||||||
|
updateState(ERROR,30);
|
||||||
|
else retries--;
|
||||||
|
break;
|
||||||
case SET_TIME:
|
case SET_TIME:
|
||||||
if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_DURATION)
|
if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_DURATION)
|
||||||
{
|
{
|
||||||
|
@ -198,28 +194,26 @@ public class SetTbrCommand implements Command {
|
||||||
{
|
{
|
||||||
MenuTime time = (MenuTime) durationObj;
|
MenuTime time = (MenuTime) durationObj;
|
||||||
double currentDuration = (time.getHour()*60)+time.getMinute();
|
double currentDuration = (time.getHour()*60)+time.getMinute();
|
||||||
if(currentDuration < duration)
|
if(currentDuration!=duration)
|
||||||
{
|
{
|
||||||
scripter.pressUpKey();
|
if(retries>0) {
|
||||||
updateState(SET_TIME,30);
|
retries--;
|
||||||
|
int steps = (int)((currentDuration - duration)/15.0);
|
||||||
|
if(currentDuration+(steps*15)<duration)
|
||||||
|
steps++;
|
||||||
|
else if(currentDuration+(steps*15)>duration)
|
||||||
|
steps--;
|
||||||
|
scripter.step(steps,(steps>0? RuffyScripter.Key.UP: RuffyScripter.Key.DOWN), 3000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
updateState(ERROR,30);
|
||||||
}
|
}
|
||||||
else if(currentDuration > duration)
|
else {
|
||||||
{
|
|
||||||
scripter.pressDownKey();
|
|
||||||
updateState(SET_TIME,30);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
updateState(SET, 30);
|
updateState(SET, 30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(scripter.currentMenu!=null && scripter.currentMenu.getType()==MenuType.TBR_SET)
|
|
||||||
{
|
|
||||||
scripter.pressMenuKey();
|
|
||||||
updateState(SET_TIME,60);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
updateState(ERROR,60);
|
updateState(ERROR,60);
|
||||||
|
|
Loading…
Reference in a new issue