From a03404381c0f5053abce33957b92bb72171b1430 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Thu, 17 Oct 2019 08:02:12 +0300 Subject: [PATCH] Game Button functional part complete (template to disable buttons in 'Game Mode'). --- .../logiled/Controllers/MainController.java | 2 - src/main/java/logiled/USB/GameModeThread.java | 48 ++++++++++++++----- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/main/java/logiled/Controllers/MainController.java b/src/main/java/logiled/Controllers/MainController.java index d9b576e..70b2863 100644 --- a/src/main/java/logiled/Controllers/MainController.java +++ b/src/main/java/logiled/Controllers/MainController.java @@ -65,8 +65,6 @@ public class MainController implements Initializable { } else { // Consider as GameMode; refactor in case more tabs added. List disKeysList = GameModeController.getKeys(); - if (disKeysList.isEmpty()) - return; GameModeThread gameModeThread = new GameModeThread(disKeysList); Thread commThread = new Thread(gameModeThread); commThread.setDaemon(true); diff --git a/src/main/java/logiled/USB/GameModeThread.java b/src/main/java/logiled/USB/GameModeThread.java index e4ee1ab..39b65f9 100644 --- a/src/main/java/logiled/USB/GameModeThread.java +++ b/src/main/java/logiled/USB/GameModeThread.java @@ -1,34 +1,54 @@ package logiled.USB; import logiled.MessagesConsumer; +import logiled.RainbowHexDump; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class GameModeThread extends LoThread implements Runnable{ - // Game-key settings - //private static final byte[] game_key_rule - private static final byte[] game_key_set_default = { + private static final byte[] game_key_prepare = { 0x11, (byte) 0xff, 0x03, 0x3c, 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 gameModeCommands; /** * Used to set keys & leds * @param keysToDisable : list of keys that has to be disables in 'Game Mode', always not empty and not null * */ public GameModeThread(List 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 public void run() { - /* - if (command == null) - return; - UsbConnect usbConnect = new UsbConnect(); if (!usbConnect.isConnected()) @@ -36,11 +56,17 @@ public class GameModeThread extends LoThread implements Runnable{ 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!"); usbConnect.close(); - */ } - }