make keypress wait up to 2000ms for key response
This commit is contained in:
parent
763cc23939
commit
efb73ba4f2
1 changed files with 37 additions and 15 deletions
|
@ -51,6 +51,11 @@ public class RuffyScripter {
|
||||||
|
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
|
|
||||||
|
private Object keylock = new Object();
|
||||||
|
private int keynotwait = 0;
|
||||||
|
|
||||||
|
private Object screenlock = new Object();
|
||||||
|
|
||||||
public RuffyScripter() {
|
public RuffyScripter() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -167,6 +172,11 @@ public class RuffyScripter {
|
||||||
currentMenu = menu;
|
currentMenu = menu;
|
||||||
menuLastUpdated = System.currentTimeMillis();
|
menuLastUpdated = System.currentTimeMillis();
|
||||||
|
|
||||||
|
synchronized (screenlock)
|
||||||
|
{
|
||||||
|
screenlock.notifyAll();
|
||||||
|
}
|
||||||
|
|
||||||
connected = true;
|
connected = true;
|
||||||
|
|
||||||
// note that a WARNING_OR_ERROR menu can be a valid temporary state (cancelling TBR)
|
// note that a WARNING_OR_ERROR menu can be a valid temporary state (cancelling TBR)
|
||||||
|
@ -186,7 +196,10 @@ public class RuffyScripter {
|
||||||
public void keySent(int sequence) throws RemoteException {
|
public void keySent(int sequence) throws RemoteException {
|
||||||
synchronized (keylock)
|
synchronized (keylock)
|
||||||
{
|
{
|
||||||
keylock.notify();
|
if(keynotwait>0)
|
||||||
|
keynotwait--;
|
||||||
|
else
|
||||||
|
keylock.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +210,6 @@ public class RuffyScripter {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private Object keylock = new Object();
|
|
||||||
public boolean isPumpBusy() {
|
public boolean isPumpBusy() {
|
||||||
return activeCmd != null;
|
return activeCmd != null;
|
||||||
}
|
}
|
||||||
|
@ -379,35 +391,35 @@ public class RuffyScripter {
|
||||||
// so this class can focus on providing a connection to run commands
|
// so this class can focus on providing a connection to run commands
|
||||||
// (or maybe reconsider putting it into a base class)
|
// (or maybe reconsider putting it into a base class)
|
||||||
|
|
||||||
private static class Key {
|
public static class Key {
|
||||||
static byte NO_KEY = (byte) 0x00;
|
public static byte NO_KEY = (byte) 0x00;
|
||||||
static byte MENU = (byte) 0x03;
|
public static byte MENU = (byte) 0x03;
|
||||||
static byte CHECK = (byte) 0x0C;
|
public static byte CHECK = (byte) 0x0C;
|
||||||
static byte UP = (byte) 0x30;
|
public static byte UP = (byte) 0x30;
|
||||||
static byte DOWN = (byte) 0xC0;
|
public static byte DOWN = (byte) 0xC0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pressUpKey() {
|
public void pressUpKey() {
|
||||||
log.debug("Pressing up key");
|
log.debug("Pressing up key");
|
||||||
pressKey(Key.UP);
|
pressKey(Key.UP,2000);
|
||||||
log.debug("Releasing up key");
|
log.debug("Releasing up key");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pressDownKey() {
|
public void pressDownKey() {
|
||||||
log.debug("Pressing down key");
|
log.debug("Pressing down key");
|
||||||
pressKey(Key.DOWN);
|
pressKey(Key.DOWN,2000);
|
||||||
log.debug("Releasing down key");
|
log.debug("Releasing down key");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pressCheckKey() {
|
public void pressCheckKey() {
|
||||||
log.debug("Pressing check key");
|
log.debug("Pressing check key");
|
||||||
pressKey(Key.CHECK);
|
pressKey(Key.CHECK,2000);
|
||||||
log.debug("Releasing check key");
|
log.debug("Releasing check key");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pressMenuKey() {
|
public void pressMenuKey() {
|
||||||
log.debug("Pressing menu key");
|
log.debug("Pressing menu key");
|
||||||
pressKey(Key.MENU);
|
pressKey(Key.MENU,2000);
|
||||||
log.debug("Releasing menu key");
|
log.debug("Releasing menu key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,14 +445,24 @@ public class RuffyScripter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pressKey(final byte key) {
|
private void pressKey(final byte key, long timeout) {
|
||||||
try {
|
try {
|
||||||
ruffyService.rtSendKey(key, true);
|
ruffyService.rtSendKey(key, true);
|
||||||
//SystemClock.sleep(200);
|
//SystemClock.sleep(200);
|
||||||
ruffyService.rtSendKey(Key.NO_KEY, true);
|
ruffyService.rtSendKey(Key.NO_KEY, true);
|
||||||
synchronized (keylock)
|
if(timeout > 0)
|
||||||
{
|
{
|
||||||
keylock.wait(2500);
|
synchronized (keylock)
|
||||||
|
{
|
||||||
|
keylock.wait(timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
synchronized (keylock)
|
||||||
|
{
|
||||||
|
keynotwait++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CommandException().exception(e).message("Error while pressing buttons");
|
throw new CommandException().exception(e).message("Error while pressing buttons");
|
||||||
|
|
Loading…
Reference in a new issue