update setTBRCommand to way faster methods in scripter

This commit is contained in:
Sandra Keßler 2017-08-04 16:39:03 +02:00
parent d35283ad74
commit ac3859dcae

View file

@ -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); updateState(TBR,30);
scripter.pressCheckKey(); retries=0;
log.debug("found TBR_MENU -> state:TBR");
try {
Thread.sleep(750);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else if(scripter.currentMenu!=null && scripter.currentMenu.getType()!=lastMenu)
{
lastMenu = scripter.currentMenu.getType();
updateState(MAIN,30);
scripter.pressMenuKey();
log.debug("found Menu:"+lastMenu+" -> state:MAIN");
} }
else else
{ retries--;
scripter.pressMenuKey(); else
} updateState(ERROR,30);
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,15 +146,16 @@ 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);
scripter.step(steps,(steps<0? RuffyScripter.Key.DOWN: RuffyScripter.Key.UP), 3000);
} }
else if(currentPercentage > percentage) else
{ updateState(ERROR,30);
scripter.pressDownKey();
updateState(SET_TBR,30);
} }
else else
{ {
@ -174,22 +165,27 @@ public class SetTbrCommand implements Command {
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);
else if(currentDuration > duration) if(currentDuration+(steps*15)<duration)
{ steps++;
scripter.pressDownKey(); else if(currentDuration+(steps*15)>duration)
updateState(SET_TIME,30); steps--;
scripter.step(steps,(steps>0? RuffyScripter.Key.UP: RuffyScripter.Key.DOWN), 3000);
} }
else else
{ updateState(ERROR,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);