WarpPI/core/src/main/java/it/cavallium/warppi/device/Keyboard.java

1118 lines
37 KiB
Java
Raw Normal View History

package it.cavallium.warppi.device;
2016-09-02 20:32:37 +02:00
2018-09-04 12:12:41 +02:00
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.Platform.ConsoleUtils;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.device.chip.ParallelToSerial;
import it.cavallium.warppi.device.chip.SerialToParallel;
import it.cavallium.warppi.event.Key;
import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.event.KeyReleasedEvent;
import it.cavallium.warppi.event.KeyboardEventListener;
2018-10-05 16:00:15 +02:00
import it.cavallium.warppi.extra.mario.MarioScreen;
2018-10-06 16:37:44 +02:00
import it.cavallium.warppi.extra.tetris.TetrisScreen;
import it.cavallium.warppi.gui.GUIErrorMessage;
import it.cavallium.warppi.gui.screens.KeyboardDebugScreen;
import it.cavallium.warppi.gui.screens.Screen;
2016-09-02 20:32:37 +02:00
public class Keyboard {
public static volatile boolean alpha = false;
public static volatile boolean shift = false;
2016-09-02 20:32:37 +02:00
//From Serial
private static final int RCK_pin = 35;
private static final int SCK_and_CLK_pin = 38;
private static final int SER_pin = 36;
//To Serial
private static final int SH_LD_pin = 37;
private static final int QH_pin = 40;
private static final int CLK_INH_pin = 33;
private static volatile boolean[][] precedentStates = new boolean[8][8];
public static volatile boolean[][] debugKeysDown = new boolean[8][8];
public static volatile int debugKeyCode = -1;
2018-04-01 01:01:57 +02:00
public static volatile int debugKeyCodeRelease = -1;
private static volatile boolean refreshRequest = false;
2017-04-09 22:01:03 +02:00
private static KeyboardEventListener additionalListener;
public synchronized void startKeyboard() {
final Thread kt = new Thread(() -> {
2018-10-06 16:37:44 +02:00
if (Engine.getPlatform().isRunningOnRaspberry() == false) {
2017-01-16 17:57:09 +01:00
try {
while (true) {
2018-09-22 11:17:30 +02:00
if (Keyboard.debugKeyCode != -1) {
2018-10-06 16:37:44 +02:00
Keyboard.debugKey(Keyboard.debugKeyCode, false);
2018-09-22 11:17:30 +02:00
Keyboard.debugKeyCode = -1;
2017-01-16 17:57:09 +01:00
}
2018-09-22 11:17:30 +02:00
if (Keyboard.debugKeyCodeRelease != -1) {
2018-10-06 16:37:44 +02:00
Keyboard.debugKey(Keyboard.debugKeyCodeRelease, true);
2018-09-22 11:17:30 +02:00
Keyboard.debugKeyCodeRelease = -1;
2018-04-01 01:01:57 +02:00
}
2017-01-16 17:57:09 +01:00
Thread.sleep(50);
}
} catch (final InterruptedException e) {}
2018-09-28 11:39:28 +02:00
} else {
2018-09-22 11:17:30 +02:00
Engine.getPlatform().getGpio().pinMode(Keyboard.CLK_INH_pin, Engine.getPlatform().getGpio().valueOutput());
Engine.getPlatform().getGpio().pinMode(Keyboard.RCK_pin, Engine.getPlatform().getGpio().valueOutput());
Engine.getPlatform().getGpio().pinMode(Keyboard.SER_pin, Engine.getPlatform().getGpio().valueOutput());
Engine.getPlatform().getGpio().pinMode(Keyboard.SH_LD_pin, Engine.getPlatform().getGpio().valueOutput());
Engine.getPlatform().getGpio().pinMode(Keyboard.SCK_and_CLK_pin, Engine.getPlatform().getGpio().valueOutput());
Engine.getPlatform().getGpio().pinMode(Keyboard.QH_pin, Engine.getPlatform().getGpio().valueInput());
Engine.getPlatform().getGpio().digitalWrite(Keyboard.CLK_INH_pin, false);
Engine.getPlatform().getGpio().digitalWrite(Keyboard.RCK_pin, false);
Engine.getPlatform().getGpio().digitalWrite(Keyboard.SER_pin, false);
Engine.getPlatform().getGpio().digitalWrite(Keyboard.SH_LD_pin, false);
Engine.getPlatform().getGpio().digitalWrite(Keyboard.SCK_and_CLK_pin, false);
Engine.getPlatform().getGpio().digitalWrite(Keyboard.QH_pin, false);
final SerialToParallel chip1 = new SerialToParallel(Keyboard.RCK_pin, Keyboard.SCK_and_CLK_pin /*SCK*/, Keyboard.SER_pin);
final ParallelToSerial chip2 = new ParallelToSerial(Keyboard.SH_LD_pin, Keyboard.CLK_INH_pin, Keyboard.QH_pin, Keyboard.SCK_and_CLK_pin/*CLK*/);
2017-01-16 17:57:09 +01:00
KeyboardDebugScreen.log("Started keyboard system");
while (true) {
2016-09-02 20:32:37 +02:00
boolean[] data;
for (int col = 0; col < 8; col++) {
data = new boolean[8];
data[col] = true;
chip1.write(data);
2016-09-02 20:32:37 +02:00
data = chip2.read();
// KeyboardDebugScreen.ks[col] = data;
2016-09-02 20:32:37 +02:00
for (int row = 0; row < 8; row++) {
2018-09-28 11:39:28 +02:00
if (data[row] == true && Keyboard.precedentStates[row][col] == false) {
2018-09-22 11:17:30 +02:00
// System.out.println("Pressed button at " + (row + 1) + ", " + (col + 1));
// KeyboardDebugScreen.log("Pressed button at " + (row + 1) + ", " + (col + 1));
2018-10-06 16:37:44 +02:00
Keyboard.keyRaw(row, col, false);
2018-09-28 11:39:28 +02:00
} else if (data[row] == false && Keyboard.precedentStates[row][col] == true) {
2018-10-06 16:37:44 +02:00
Keyboard.keyRaw(row, col, true);
2018-09-28 11:39:28 +02:00
}
// KeyboardDebugScreen.log("Released button at " + (row + 1) + ", " + (col + 1));
2018-09-22 11:17:30 +02:00
Keyboard.precedentStates[row][col] = data[row];
2016-09-02 20:32:37 +02:00
}
}
}
2017-01-16 17:57:09 +01:00
}
});
2018-09-04 12:12:41 +02:00
Engine.getPlatform().setThreadName(kt, "Keyboard thread");
kt.setPriority(Thread.NORM_PRIORITY + 1);
2018-09-04 12:12:41 +02:00
Engine.getPlatform().setThreadDaemon(kt);
2017-01-16 17:57:09 +01:00
kt.start();
}
2018-08-28 02:39:41 +02:00
2018-10-06 16:37:44 +02:00
/**
*
* @param k
* @param released true: released, false: pressed
*/
private static void debugKey(Key k, boolean released) {
if (released) {
Keyboard.keyReleased(k);
} else {
Keyboard.keyPressed(k);
}
}
/**
*
* @param keyCode
* @param released true: released, false: pressed
*/
public static void debugKey(final int keyCode, boolean released) {
switch (keyCode) {
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_ESCAPE:
2018-10-06 16:37:44 +02:00
debugKey(Key.BACK, released);
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_S:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.ARCSINE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_S, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.SINE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_C:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.ARCCOSINE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_C, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.COSINE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_T:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.ARCTANGENT, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_T, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.TANGENT, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_D:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.debug_DEG, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_D, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_R:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.debug_RAD, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_R, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_G:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.debug_GRA, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_G, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_X:
2018-09-28 11:39:28 +02:00
if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_X, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_P:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_P, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.PI, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_E:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_E, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.EULER_NUMBER, released);
2018-09-28 11:39:28 +02:00
}
2018-05-06 16:37:25 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_Y:
2018-09-28 11:39:28 +02:00
if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_Y, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_B:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.BRIGHTNESS_CYCLE_REVERSE, released);
2018-09-28 11:39:28 +02:00
} else if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.BRIGHTNESS_CYCLE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_B, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_L:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LOGARITHM, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_L, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.LOGARITHM, released);
2018-09-28 11:39:28 +02:00
}
2018-05-05 23:06:36 +02:00
break;
case KeyboardJogampValues.VK_ENTER:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_ENTER:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.STEP, released);
2018-09-28 11:39:28 +02:00
} else if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.SIMPLIFY, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
int row = 2;
int col = 1;
Keyboard.debugKeysDown[row - 1][col - 1] = true;
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_1:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM1, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_2:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM2, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_3:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM3, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_4:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM4, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_5:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM5, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_6:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM6, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_7:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM7, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
if (Engine.getPlatform().isRunningOnRaspberry() == false) {
debugKey(Key.DIVIDE, released);
2018-09-28 11:39:28 +02:00
}
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_8:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM8, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.PARENTHESIS_OPEN, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_9:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM9, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.PARENTHESIS_CLOSE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_0:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NUM0, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.EQUAL, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_M:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.SURD_MODE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_M, released);
2018-09-28 11:39:28 +02:00
}
2017-12-24 12:57:36 +01:00
break;
case KeyboardJogampValues.VK_ADD:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_ADD:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.PLUS, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.PLUS_MINUS, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_SUBTRACT:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_SUBTRACT:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.MINUS, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_MULTIPLY:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_MULTIPLY:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.MULTIPLY, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_DIVIDE:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_DIVIDE:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.DIVIDE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_BACK_SPACE:
2018-10-06 16:37:44 +02:00
debugKey(Key.DELETE, released);
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_DELETE:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_DELETE:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.RESET, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_LEFT:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_LEFT:
2017-01-16 17:57:09 +01:00
//LEFT
row = 2;
col = 3;
Keyboard.debugKeysDown[row - 1][col - 1] = true;
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LEFT, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_RIGHT:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_RIGHT:
2017-01-16 17:57:09 +01:00
//RIGHT
row = 2;
col = 5;
Keyboard.debugKeysDown[row - 1][col - 1] = true;
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.RIGHT, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_UP:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_UP:
//UP
row = 1;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = true;
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.UP, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
break;
case KeyboardJogampValues.VK_DOWN:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_DOWN:
//DOWN
row = 3;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = true;
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.DOWN, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
break;
case (short) 12:
//DOWN
row = 2;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = true;
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.OK, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
break;
case KeyboardJogampValues.VK_NUMPAD4:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_NUMPAD4:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.HISTORY_BACK, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_NUMPAD6:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_NUMPAD6:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.HISTORY_FORWARD, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_PERIOD:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.DOT, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_A:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_A, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_F:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_F, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_H:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_H, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_I:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_I, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_J:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_J, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_K:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_K, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_N:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_N, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_O:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_O, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_Q:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_Q, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_U:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_U, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_V:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_V, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_W:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_W, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_Z:
2018-09-28 11:39:28 +02:00
if (!Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha && !Keyboard.shift) {
2018-10-06 16:37:44 +02:00
debugKey(Key.LETTER_Z, released);
2018-09-28 11:39:28 +02:00
} else if (Keyboard.shift && !Keyboard.alpha) {
2018-10-06 16:37:44 +02:00
debugKey(Key.ZOOM_MODE, released);
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
debugKey(Key.NONE, released);
2018-09-28 11:39:28 +02:00
}
2018-08-29 00:07:45 +02:00
break;
case KeyboardJogampValues.VK_SHIFT:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_SHIFT:
2018-10-06 16:37:44 +02:00
debugKey(Key.SHIFT, released);
2017-01-16 17:57:09 +01:00
break;
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_CONTROL:
2018-10-06 16:37:44 +02:00
debugKey(Key.ALPHA, released);
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_NUMPAD1:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_NUMPAD1:
2018-10-06 16:37:44 +02:00
debugKey(Key.SQRT, released);
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_NUMPAD2:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_NUMPAD2:
2018-10-06 16:37:44 +02:00
debugKey(Key.ROOT, released);
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_NUMPAD3:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_NUMPAD3:
2018-10-06 16:37:44 +02:00
debugKey(Key.POWER_OF_2, released);
2017-01-16 17:57:09 +01:00
break;
case KeyboardJogampValues.VK_NUMPAD5:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_NUMPAD5:
2018-10-06 16:37:44 +02:00
debugKey(Key.POWER_OF_x, released);
2017-01-16 17:57:09 +01:00
break;
2016-09-02 20:32:37 +02:00
}
}
2018-09-22 11:17:30 +02:00
private synchronized static void debugKeyReleased(final int keyCode) {
2018-04-01 01:01:57 +02:00
switch (keyCode) {
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_ENTER:
2018-04-01 01:01:57 +02:00
int row = 2;
int col = 1;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case KeyboardJogampValues.VK_LEFT:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_LEFT:
2018-04-01 01:01:57 +02:00
//LEFT
row = 2;
col = 3;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case KeyboardJogampValues.VK_RIGHT:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_RIGHT:
2018-04-01 01:01:57 +02:00
//RIGHT
row = 2;
col = 5;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
System.out.println("RELEASE");
break;
case KeyboardJogampValues.VK_UP:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_UP:
2018-04-01 01:01:57 +02:00
//UP
row = 1;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case KeyboardJogampValues.VK_DOWN:
2018-10-15 23:10:44 +02:00
case KeyboardAWTValues.VK_DOWN:
2018-04-01 01:01:57 +02:00
//DOWN
row = 3;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case (short) 12:
//DOWN
row = 2;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
}
}
2018-10-06 16:37:44 +02:00
/**
*
* @param row
* @param col
* @return
*/
@Deprecated
2018-09-22 11:17:30 +02:00
public static boolean isKeyDown(final int row, final int col) {
2018-10-06 16:37:44 +02:00
if (Engine.getPlatform().isRunningOnRaspberry()) {
2018-09-22 11:17:30 +02:00
return Keyboard.precedentStates[row - 1][col - 1];
2018-09-28 11:39:28 +02:00
} else {
2018-09-22 11:17:30 +02:00
return Keyboard.debugKeysDown[row - 1][col - 1];
2018-09-28 11:39:28 +02:00
}
2016-09-02 20:32:37 +02:00
}
static final String[][][] KeyLabelsMap = /* [ROW, COLUMN, (0:normal 1:shift 2:alpha)] */
2018-09-22 11:17:30 +02:00
{ { /* ROW 0 */
{ "⇪", "⇪", null }, /* 0,0 */
{ "A", null, "A" }, /* 0,1 */
{ "", null, null }, /* 0,2 */
{ "⇧", null, null }, /* 0,3 */
{ "", null, null }, /* 0,4 */
{ "", null, null }, /* 0,5 */
{ "☼", "☼", null }, /* 0,6 */
{ "↩", null, null } /* 0,7 */
}, { /* ROW 1 */
{ "", null, null }, /* 1,0 */
{ "", null, null }, /* 1,1 */
{ "⇦", null, null }, /* 1,2 */
{ "OK", null, null }, /* 1,3 */
{ "⇨", null, null }, /* 1,4 */
2018-10-06 16:37:44 +02:00
{ "≪", null, null }, /* 1,5 */
{ "≫", null, null }, /* 1,6 */
2018-09-22 11:17:30 +02:00
{ "", null, null } /* 1,7 */
}, { /* ROW 2 */
{ "", null, null }, /* 2,0 */
2018-09-22 14:10:36 +02:00
{ "√▯", null, null }, /* 2,1 */
2018-09-22 11:17:30 +02:00
{ "", null, null }, /* 2,2 */
{ "⇩", null, null }, /* 2,3 */
{ "↶", null, null }, /* 2,4 */
{ "", null, null }, /* 2,5 */
{ "", null, null }, /* 2,6 */
{ "", null, null } /* 2,7 */
}, { /* ROW 3 */
{ "", null, null }, /* 3,0 */
{ "", null, null }, /* 3,1 */
2018-09-22 14:10:36 +02:00
{ "â–¯^â–¯", null, null }, /* 3,2 */
{ "â–¯^2", null, null }, /* 3,3 */
2018-09-22 11:17:30 +02:00
{ "", null, null }, /* 3,4 */
{ "", null, null }, /* 3,5 */
{ "", null, null }, /* 3,6 */
{ ".", null, "y" } /* 3,7 */
}, { /* ROW 4 */
{ "", null, null }, /* 4,0 */
{ "", null, null }, /* 4,1 */
2018-09-22 14:10:36 +02:00
{ "(â–¯)", null, null }, /* 4,2 */
2018-09-22 11:17:30 +02:00
{ ")", null, null }, /* 4,3 */
{ "", null, null }, /* 4,4 */
{ "S⇔D", null, null }, /* 4,5 */
{ "", null, null }, /* 4,6 */
{ "0", null, "x" } /* 4,7 */
}, { /* ROW 5 */
{ "7", null, null }, /* 5,0 */
{ "8", null, null }, /* 5,1 */
{ "9", null, null }, /* 5,2 */
{ "⌫", null, null }, /* 5,3 */
{ "RESET", null, null }, /* 5,4 */
{ "", null, null }, /* 5,5 */
{ "", null, null }, /* 5,6 */
{ "", null, null } /* 5,7 */
}, { /* ROW 6 */
{ "4", null, null }, /* 6,0 */
{ "5", null, null }, /* 6,1 */
{ "6", null, null }, /* 6,2 */
{ "*", null, null }, /* 6,3 */
{ "/", null, null }, /* 6,4 */
{ "", null, null }, /* 6,5 */
{ "", null, null }, /* 6,6 */
{ "", null, null } /* 6,7 */
}, { /* ROW 7 */
{ "1", null, null }, /* 7,0 */
{ "2", null, null }, /* 7,1 */
{ "3", null, null }, /* 7,2 */
{ "+", null, null }, /* 7,3 */
{ "-", null, null }, /* 7,4 */
{ "", null, null }, /* 7,5 */
{ "", null, null }, /* 7,6 */
{ "", null, null } /* 7,7 */
} };
static final Key[][][] keyMap = /* [ROW, COLUMN, (0:normal 1:shift 2:alpha)] */
2018-05-12 21:18:29 +02:00
{ { /* ROW 0 */
{ Key.SHIFT, Key.SHIFT, Key.SHIFT }, /* 0,0 */
{ Key.ALPHA, Key.ALPHA, Key.ALPHA }, /* 0,1 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,2 */
2018-10-16 20:03:12 +02:00
{ Key.UP, Key.NONE, Key.NONE }, /* 0,3 */
2018-05-12 21:18:29 +02:00
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,4 */
{ Key.SETTINGS, Key.NONE, Key.NONE }, /* 0,5 */
{ Key.BRIGHTNESS_CYCLE, Key.BRIGHTNESS_CYCLE_REVERSE, Key.ZOOM_MODE }, /* 0,6 */
{ Key.SIMPLIFY, Key.STEP, Key.NONE } /* 0,7 */
}, { /* ROW 1 */
{ Key.F4, Key.F4, Key.F4 }, /* 1,0 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 1,1 */
{ Key.LEFT, Key.NONE, Key.NONE }, /* 1,2 */
{ Key.OK, Key.NONE, Key.NONE }, /* 1,3 */
{ Key.RIGHT, Key.NONE, Key.NONE }, /* 1,4 */
{ Key.HISTORY_BACK, Key.NONE, Key.NONE }, /* 1,5 */
{ Key.HISTORY_FORWARD, Key.NONE, Key.NONE }, /* 1,6 */
{ Key.NONE, Key.PI, Key.DRG_CYCLE } /* 1,7 */
}, { /* ROW 2 */
2018-09-15 18:10:42 +02:00
{ Key.F3, Key.F3, Key.F3 }, /* 2,0 */
2018-05-12 21:18:29 +02:00
{ Key.SQRT, Key.ROOT, Key.NONE }, /* 2,1 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 2,2 */
{ Key.DOWN, Key.NONE, Key.NONE }, /* 2,3 */
{ Key.BACK, Key.NONE, Key.NONE }, /* 2,4 */
2018-09-15 18:10:42 +02:00
{ Key.NONE, Key.NONE, Key.NONE }, /* 2,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 2,6 */
2018-05-12 21:18:29 +02:00
{ Key.NONE, Key.NONE, Key.LETTER_Z } /* 2,7 */
}, { /* ROW 3 */
{ Key.F2, Key.F2, Key.F2 }, /* 3,0 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,1 */
{ Key.POWER_OF_x, Key.NONE, Key.NONE }, /* 3,2 */
{ Key.POWER_OF_2, Key.NONE, Key.NONE }, /* 3,3 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,6 */
{ Key.DOT, Key.NONE, Key.LETTER_Y } /* 3,7 */
}, { /* ROW 4 */
{ Key.F1, Key.F1, Key.F1 }, /* 4,0 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 4,1 */
{ Key.PARENTHESIS_OPEN, Key.NONE, Key.NONE }, /* 4,2 */
{ Key.PARENTHESIS_CLOSE, Key.NONE, Key.NONE }, /* 4,3 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 4,4 */
{ Key.SURD_MODE, Key.NONE, Key.NONE }, /* 4,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 4,6 */
{ Key.NUM0, Key.NONE, Key.LETTER_X } /* 4,7 */
}, { /* ROW 5 */
{ Key.NUM7, Key.NONE, Key.NONE }, /* 5,0 */
{ Key.NUM8, Key.NONE, Key.NONE }, /* 5,1 */
{ Key.NUM9, Key.NONE, Key.NONE }, /* 5,2 */
{ Key.DELETE, Key.NONE, Key.NONE }, /* 5,3 */
{ Key.RESET, Key.NONE, Key.NONE }, /* 5,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 5,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 5,6 */
{ Key.NONE, Key.NONE, Key.NONE } /* 5,7 */
}, { /* ROW 6 */
{ Key.NUM4, Key.NONE, Key.NONE }, /* 6,0 */
{ Key.NUM5, Key.NONE, Key.NONE }, /* 6,1 */
{ Key.NUM6, Key.NONE, Key.NONE }, /* 6,2 */
{ Key.MULTIPLY, Key.NONE, Key.NONE }, /* 6,3 */
{ Key.DIVIDE, Key.NONE, Key.NONE }, /* 6,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 6,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 6,6 */
{ Key.NONE, Key.NONE, Key.NONE } /* 6,7 */
}, { /* ROW 7 */
{ Key.NUM1, Key.NONE, Key.NONE }, /* 7,0 */
{ Key.NUM2, Key.NONE, Key.NONE }, /* 7,1 */
{ Key.NUM3, Key.NONE, Key.NONE }, /* 7,2 */
{ Key.PLUS, Key.PLUS_MINUS, Key.NONE }, /* 7,3 */
{ Key.MINUS, Key.NONE, Key.NONE }, /* 7,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 7,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 7,6 */
{ Key.NONE, Key.NONE, Key.NONE } /* 7,7 */
} };
2018-09-22 11:17:30 +02:00
public static String getKeyName(final int row, final int col) {
return Keyboard.getKeyName(row, col, Keyboard.shift, Keyboard.alpha);
}
2018-09-22 11:17:30 +02:00
public static String getKeyName(final int row, final int col, final boolean shift, final boolean alpha) {
final String[] keyValues = Keyboard.KeyLabelsMap[row][col];
if (shift) {
2018-09-28 11:39:28 +02:00
if (keyValues[1] != null) {
return keyValues[1];
2018-09-28 11:39:28 +02:00
}
} else if (alpha) {
if (keyValues[2] != null) {
return keyValues[2];
2018-09-28 11:39:28 +02:00
}
}
return keyValues[0];
}
2018-09-22 11:17:30 +02:00
public static boolean hasKeyName(final int row, final int col) {
final String[] keyValues = Keyboard.KeyLabelsMap[row][col];
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
return keyValues[1] != null;
2018-09-28 11:39:28 +02:00
} else if (Keyboard.alpha) {
return keyValues[2] != null;
2018-09-28 11:39:28 +02:00
} else {
return true;
2018-09-28 11:39:28 +02:00
}
}
2018-05-12 21:18:29 +02:00
2018-10-06 16:37:44 +02:00
/**
*
* @param row
* @param col
* @param released true: released, false: pressed
*/
public static synchronized void keyRaw(final int row, final int col, final boolean released) {
// KeyboardDebugScreen.keyX = row;
// KeyboardDebugScreen.keyY = col;
2018-09-22 11:17:30 +02:00
final Key k = Keyboard.keyMap[row][col][Keyboard.shift ? 1 : Keyboard.alpha ? 2 : 0];
2018-09-28 11:39:28 +02:00
if (k != null) {
2018-10-06 16:37:44 +02:00
if (released) {
Keyboard.keyReleased(k);
} else {
Keyboard.keyPressed(k);
}
2018-09-28 11:39:28 +02:00
} else {
2018-10-06 16:37:44 +02:00
if (released) {
Keyboard.keyReleased(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
2018-09-28 11:39:28 +02:00
}
2016-09-02 20:32:37 +02:00
}
public static void stopKeyboard() {
2018-10-06 16:37:44 +02:00
if (Engine.getPlatform().isRunningOnRaspberry()) {
2018-09-04 12:12:41 +02:00
Engine.getPlatform().getGpio().digitalWrite(33, false);
Engine.getPlatform().getGpio().digitalWrite(35, false);
Engine.getPlatform().getGpio().digitalWrite(36, false);
Engine.getPlatform().getGpio().digitalWrite(37, false);
Engine.getPlatform().getGpio().digitalWrite(38, false);
Engine.getPlatform().getGpio().digitalWrite(40, false);
2016-09-02 20:32:37 +02:00
}
}
2018-09-22 11:17:30 +02:00
public synchronized static void keyPressed(final Key k) {
2017-04-09 22:01:03 +02:00
boolean done = false;
2018-09-28 11:39:28 +02:00
if (Keyboard.additionalListener != null) {
2017-04-09 22:01:03 +02:00
try {
2018-09-22 11:17:30 +02:00
done = Keyboard.additionalListener.onKeyPressed(new KeyPressedEvent(k));
} catch (final Exception ex) {
2017-04-09 22:01:03 +02:00
new GUIErrorMessage(ex);
}
2018-09-28 11:39:28 +02:00
}
if (Engine.INSTANCE.getHardwareDevice().getDisplayManager() != null) {
final Screen scr = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
2016-09-02 20:32:37 +02:00
boolean refresh = false;
2017-04-09 22:01:03 +02:00
boolean scrdone = false;
try {
scrdone = scr.onKeyPressed(new KeyPressedEvent(k));
} catch (final Exception ex) {
2017-04-09 22:01:03 +02:00
new GUIErrorMessage(ex);
}
2018-09-28 11:39:28 +02:00
if (scr != null && scr.initialized && scrdone) {
2016-09-02 20:32:37 +02:00
refresh = true;
2018-09-28 11:39:28 +02:00
} else {
2016-09-02 20:32:37 +02:00
switch (k) {
case POWEROFF:
Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.destroy();
2016-09-02 20:32:37 +02:00
break;
case NONE:
break;
case BRIGHTNESS_CYCLE:
2018-10-06 16:37:44 +02:00
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new TetrisScreen()); //TODO: rimuovere: prova
Engine.INSTANCE.getHardwareDevice().getDisplayManager().cycleBrightness(false);
2016-09-02 20:32:37 +02:00
refresh = true;
break;
case BRIGHTNESS_CYCLE_REVERSE:
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MarioScreen()); //TODO: rimuovere: prova
Engine.INSTANCE.getHardwareDevice().getDisplayManager().cycleBrightness(true);
2016-09-02 20:32:37 +02:00
refresh = true;
break;
2018-03-31 18:02:36 +02:00
case ZOOM_MODE:
2018-09-22 11:17:30 +02:00
final float newZoom = StaticVars.windowZoom.getLastValue() % 3 + 1;
2019-11-01 15:23:34 +01:00
StaticVars.windowZoom.submit(newZoom);
2018-09-04 12:12:41 +02:00
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Keyboard", "Zoom: " + newZoom);
2018-03-31 18:42:21 +02:00
// StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f;
2018-03-31 18:02:36 +02:00
refresh = true;
2018-10-04 21:29:39 +02:00
break;
2016-09-02 20:32:37 +02:00
case HISTORY_BACK:
Engine.INSTANCE.getHardwareDevice().getDisplayManager().goBack();
2016-09-02 20:32:37 +02:00
refresh = true;
break;
case HISTORY_FORWARD:
Engine.INSTANCE.getHardwareDevice().getDisplayManager().goForward();
2016-09-02 20:32:37 +02:00
refresh = true;
break;
2018-10-05 16:00:15 +02:00
case BACK:
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Closing current screen.");
Engine.INSTANCE.getHardwareDevice().getDisplayManager().closeScreen();
refresh = true;
break;
2016-09-02 20:32:37 +02:00
default:
break;
}
2018-09-28 11:39:28 +02:00
}
2016-09-02 20:32:37 +02:00
switch (k) {
case SHIFT:
2018-09-28 11:39:28 +02:00
if (Keyboard.alpha) {
2018-09-04 12:12:41 +02:00
Engine.getPlatform().alphaChanged(Keyboard.alpha = false);
2018-09-28 11:39:28 +02:00
}
2018-09-04 12:12:41 +02:00
Engine.getPlatform().shiftChanged(Keyboard.shift = !Keyboard.shift);
2016-09-02 20:32:37 +02:00
refresh = true;
break;
case ALPHA:
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-09-04 12:12:41 +02:00
Engine.getPlatform().shiftChanged(Keyboard.shift = false);
2018-09-28 11:39:28 +02:00
}
2018-09-04 12:12:41 +02:00
Engine.getPlatform().alphaChanged(Keyboard.alpha = !Keyboard.alpha);
2016-09-02 20:32:37 +02:00
refresh = true;
break;
default:
2018-09-02 12:45:51 +02:00
if (k != Key.NONE) {
2018-09-28 11:39:28 +02:00
if (Keyboard.shift) {
2018-09-04 12:12:41 +02:00
Engine.getPlatform().shiftChanged(Keyboard.shift = false);
2018-09-28 11:39:28 +02:00
}
if (Keyboard.alpha) {
2018-09-04 12:12:41 +02:00
Engine.getPlatform().alphaChanged(Keyboard.alpha = false);
2018-09-28 11:39:28 +02:00
}
2018-09-02 12:45:51 +02:00
}
2016-09-02 20:32:37 +02:00
break;
}
2018-09-28 11:39:28 +02:00
if (refresh) {
2018-09-22 11:17:30 +02:00
Keyboard.refreshRequest = true;
2018-09-28 11:39:28 +02:00
}
} else if (!done) {
2018-09-04 12:12:41 +02:00
Engine.getPlatform().getConsoleUtils().out().println(1, "Key " + k.toString() + " ignored.");
2018-09-28 11:39:28 +02:00
}
2016-09-02 20:32:37 +02:00
}
2018-09-22 11:17:30 +02:00
public synchronized static void keyReleased(final Key k) {
2017-04-09 22:01:03 +02:00
boolean done = false;
2018-09-28 11:39:28 +02:00
if (Keyboard.additionalListener != null) {
2018-09-22 11:17:30 +02:00
done = Keyboard.additionalListener.onKeyReleased(new KeyReleasedEvent(k));
2018-09-28 11:39:28 +02:00
}
2016-09-02 20:32:37 +02:00
boolean refresh = false;
if (Engine.INSTANCE.getHardwareDevice().getDisplayManager() != null) {
final Screen scr = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
2018-09-28 11:39:28 +02:00
if (scr != null && scr.initialized && scr.onKeyReleased(new KeyReleasedEvent(k))) {
2016-09-02 20:32:37 +02:00
refresh = true;
2018-09-28 11:39:28 +02:00
} else {
2016-09-02 20:32:37 +02:00
switch (k) {
case NONE:
break;
default:
break;
}
2018-09-28 11:39:28 +02:00
}
if (refresh) {
2018-09-22 11:17:30 +02:00
Keyboard.refreshRequest = true;
2018-09-28 11:39:28 +02:00
}
} else if (!done) {
2018-09-04 12:12:41 +02:00
Engine.getPlatform().getConsoleUtils().out().println(1, "Key " + k.toString() + " ignored.");
2018-09-28 11:39:28 +02:00
}
2016-09-02 20:32:37 +02:00
}
2018-09-22 11:17:30 +02:00
public void setAdditionalKeyboardListener(final KeyboardEventListener l) {
Keyboard.additionalListener = l;
2017-04-09 22:01:03 +02:00
}
2016-09-02 20:32:37 +02:00
public static boolean popRefreshRequest() {
2018-09-22 11:17:30 +02:00
if (Keyboard.refreshRequest) {
Keyboard.refreshRequest = false;
return true;
}
return false;
2016-09-02 20:32:37 +02:00
}
2017-01-16 17:57:09 +01:00
2016-09-02 20:32:37 +02:00
}
/*
2017-01-16 17:57:09 +01:00
2016-09-02 20:32:37 +02:00
Keyboard:
Example button:
|ROW,COLUMN----|
| NORMAL STATE |
| SHIFT STATE |
| ALPHA STATE |
|--------------|
2018-09-22 11:17:30 +02:00
Physical keyboard:
|0,0-----|0,1-----|########|0,3-----|########|0,5-----|0,6-----|
| SHIFT | ALPHA |########| ^ |########|SETTINGS|+BRIGHT |
| NORMAL | ALPHA |########| |########| |-BRIGHT |
2018-03-31 18:02:36 +02:00
| SHIFT | NORMAL |########| |########| |ZOOMMODE|
|1,0-----|1,1-----|1,2-----|1,3-----|1,4-----|1,5-----|1,6-----|
| F_4 | | < | OK | > | Back | Fwd |
| F_4 | | | | | | |
| F_4 | | | | | | |
|2,0-----|2,1-----|--------|2,3-----|--------|2,5-----|2,6-----|
| F_3 | SQRT |########| v | BACK | | |
| F_3 | ROOT |########| | | | |
| F_3 | |########| | | | |
|3,0-----|3,1-----|3,2-----|3,3-----|3,4-----|3,5-----|3,6-----|
| F_2 | | POW x | POW 2 | | | |
| F_2 | | | | | | |
| F_2 | | | | | | |
|4,0-----|4,1-----|4,2-----|4,3-----|4,4-----|4,5-----|4,6-----|
| F_1 | | ( | ) | | S<=>D | |
| F_1 | | | | | | |
| F_1 | | | | | | |
|5,0-----|5,1-----|5,2-----|5,3-----|5,4-----|5,5-----|5,6-----|
| 7 | 8 | 9 | DEL | RESET |
| | | | | |
| | | | | |
|6,0-----|6,1-----|6,2-----|6,3-----|6,4-----------------------|
| 4 | 5 | 6 | * | / |
| | | | | |
| | | | | |
|7,0-----|7,1-----|7,2-----|7,3-----|7,4-----------------------|
| 1 | 2 | 3 | + | - |
| | | | | |
| | | | | |
|4,7-----|3,7-----|2,7-----|1,7-----|0,7-----------------------|
| 0 | . | | | SIMPLIFY |
| | | |PI | STEP |
| X | Y | Z |DRG CYCL| |
|--------|--------|--------|--------|--------------------------|
SCREEN F_n:
MathInputScreen:
Default:
2018-09-22 11:17:30 +02:00
[F_1] Normal: Solve for X Shift: Solve for _ Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Variables & constants Shift: Alpha:
[F_4] Normal: Functions f(x) Shift: Alpha:
Variable popup:
2018-09-22 11:17:30 +02:00
[F_1] Normal(if constant):Set value Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
MarioScreen
2018-09-22 11:17:30 +02:00
[F_1] Normal: Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
ChooseVariableValueScreen
2018-09-22 11:17:30 +02:00
[F_1] Normal: Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
SolveForXScreen
2018-09-22 11:17:30 +02:00
[F_1] Normal: Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
2016-09-02 20:32:37 +02:00
*/