Game Button functional part complete (template to disable buttons in 'Game Mode').

This commit is contained in:
Dmitry Isaenko 2019-10-17 08:02:12 +03:00
parent 1ef37aa224
commit a03404381c
2 changed files with 37 additions and 13 deletions

View file

@ -65,8 +65,6 @@ public class MainController implements Initializable {
} }
else { // Consider as GameMode; refactor in case more tabs added. else { // Consider as GameMode; refactor in case more tabs added.
List<Byte> disKeysList = GameModeController.getKeys(); List<Byte> disKeysList = GameModeController.getKeys();
if (disKeysList.isEmpty())
return;
GameModeThread gameModeThread = new GameModeThread(disKeysList); GameModeThread gameModeThread = new GameModeThread(disKeysList);
Thread commThread = new Thread(gameModeThread); Thread commThread = new Thread(gameModeThread);
commThread.setDaemon(true); commThread.setDaemon(true);

View file

@ -1,34 +1,54 @@
package logiled.USB; package logiled.USB;
import logiled.MessagesConsumer; import logiled.MessagesConsumer;
import logiled.RainbowHexDump;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class GameModeThread extends LoThread implements Runnable{ public class GameModeThread extends LoThread implements Runnable{
// Game-key settings private static final byte[] game_key_prepare = {
//private static final byte[] game_key_rule
private static final byte[] game_key_set_default = {
0x11, (byte) 0xff, 0x03, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, (byte) 0xff, 0x03, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00
}; };
private static final byte[] game_key_list = {
0x11, (byte) 0xff, 0x03, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
private byte[] command; private List<byte[]> gameModeCommands;
/** /**
* Used to set keys & leds * Used to set keys & leds
* @param keysToDisable : list of keys that has to be disables in 'Game Mode', always not empty and not null * @param keysToDisable : list of keys that has to be disables in 'Game Mode', always not empty and not null
* */ * */
public GameModeThread(List<Byte> keysToDisable){ public GameModeThread(List<Byte> keysToDisable){
gameModeCommands = new ArrayList<>();
// Prepare to send commands
gameModeCommands.add(game_key_prepare);
// Set keys to disable
byte[] command = Arrays.copyOfRange(game_key_list, 0, game_key_list.length);
int pointer = 4;
for (byte keyCode: keysToDisable) {
if (pointer == 19){
gameModeCommands.add(command);
command = Arrays.copyOfRange(game_key_list, 0, game_key_list.length);
pointer = 4;
}
command[pointer++] = keyCode;
}
// Add command that is not fulfilled to 100% OR In case nothing in the list
if (pointer <= 19)
gameModeCommands.add(command);
} }
@Override @Override
public void run() { public void run() {
/*
if (command == null)
return;
UsbConnect usbConnect = new UsbConnect(); UsbConnect usbConnect = new UsbConnect();
if (!usbConnect.isConnected()) if (!usbConnect.isConnected())
@ -36,11 +56,17 @@ public class GameModeThread extends LoThread implements Runnable{
handler = usbConnect.getHandlerKbrd(); handler = usbConnect.getHandlerKbrd();
if (! write(command)) boolean notFailed = true;
for (byte[] cmd : gameModeCommands)
if (write(cmd)){
notFailed = false;
break;
}
if (notFailed)
MessagesConsumer.getInstance().inform("Complete!"); MessagesConsumer.getInstance().inform("Complete!");
usbConnect.close(); usbConnect.close();
*/
} }
} }