Game Button functional part complete (template to disable buttons in 'Game Mode').
This commit is contained in:
parent
1ef37aa224
commit
a03404381c
2 changed files with 37 additions and 13 deletions
|
@ -65,8 +65,6 @@ public class MainController implements Initializable {
|
|||
}
|
||||
else { // Consider as GameMode; refactor in case more tabs added.
|
||||
List<Byte> disKeysList = GameModeController.getKeys();
|
||||
if (disKeysList.isEmpty())
|
||||
return;
|
||||
GameModeThread gameModeThread = new GameModeThread(disKeysList);
|
||||
Thread commThread = new Thread(gameModeThread);
|
||||
commThread.setDaemon(true);
|
||||
|
|
|
@ -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<byte[]> 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<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
|
||||
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();
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue