diff --git a/cli_entry_point.py b/cli_entry_point.py old mode 100644 new mode 100755 diff --git a/lib/data_mappers/command_bytearray.py b/lib/data_mappers/command_bytearray.py index 1f80ddf..b19299c 100644 --- a/lib/data_mappers/command_bytearray.py +++ b/lib/data_mappers/command_bytearray.py @@ -22,5 +22,14 @@ 'play_pause': bytearray(b'\x02\x08'), 'stop': bytearray(b'\x02\x04'), 'next_song': bytearray(b'\x02\x01'), - 'prev_song': bytearray(b'\x02\x02') -} \ No newline at end of file + 'prev_song': bytearray(b'\x02\x02'), +} + +for base in range(1, 10): + for secondary in range(base + 1, 10): + base_g_command = commands['g' + str(base)] + secondary_g_command = commands['g' + str(secondary)] + combined_keys_command = bytearray(base_g_command); + for index, byte in enumerate(secondary_g_command): + combined_keys_command[index] = base_g_command[index] | secondary_g_command[index] + commands['g'+str(base)+'+g'+str(secondary)] = combined_keys_command diff --git a/lib/data_mappers/config_reader.py b/lib/data_mappers/config_reader.py index 8ceffd6..fc360bb 100644 --- a/lib/data_mappers/config_reader.py +++ b/lib/data_mappers/config_reader.py @@ -61,21 +61,26 @@ def validate_config(config_dic : dict): if keyboard_mapping not in supported_configs.keyboard_mappings: return {"keyboard_mapping": keyboard_mapping+" does not exist!"}, None - for i in range(1,10): - setting_for_gkey =config_dic.get("g"+str(i), {}) + combinations = ['g' + str(i) for i in range(1,10)] + for base in range(1, 10): + for secondary in range(base + 1, 10): + combinations.append('g'+str(base)+'+g'+str(secondary)) + + for g_key in combinations: + setting_for_gkey =config_dic.get(g_key, {}) hotkey_type = setting_for_gkey.get("hotkey_type",supported_configs.default_hotkey_type) - errors["g" + str(i)] = {} + errors[g_key] = {} if hotkey_type not in supported_configs.hotkey_types: - errors["g" + str(i)]["hotkey_type"] = hotkey_type + " does not exist!" + errors[g_key]["hotkey_type"] = hotkey_type + " does not exist!" do = setting_for_gkey.get("do",supported_configs.default_hotkey_do) do_validation = validate_hotkey_action(do, hotkey_type, keyboard_mapping) if do_validation: - errors["g" + str(i)]["do"] = do_validation.copy() + errors[g_key]["do"] = do_validation.copy() do = "" hotkey_type = "nothing" - if len(errors["g" + str(i)]) == 0: - errors.pop("g" + str(i)) - return_config["g" + str(i)] = {"hotkey_type": hotkey_type, "do": do} + if len(errors[g_key]) == 0: + errors.pop(g_key) + return_config[g_key] = {"hotkey_type": hotkey_type, "do": do} if len(errors) == 0: return None, return_config @@ -95,7 +100,6 @@ def read(): if config: return config - log.debug("Reading config from " + paths.config_path) try: with open(paths.config_path, "r") as f: try: diff --git a/lib/functionalities/gkey_functionality.py b/lib/functionalities/gkey_functionality.py index 0836086..ccbfe4e 100644 --- a/lib/functionalities/gkey_functionality.py +++ b/lib/functionalities/gkey_functionality.py @@ -25,6 +25,8 @@ def resolve_config(key): config = config_reader.read() + + if key not in config.keys(): log.info(key+" pressed, unbound in config, doing nothing!") return lambda _: None @@ -87,3 +89,6 @@ def g8(device): def g9(device): resolve_config(inspect.stack()[0][3])(device) + +def g_combo(device, key): + resolve_config(key)(device) diff --git a/lib/g910_gkey_mapper.py b/lib/g910_gkey_mapper.py index f6a39de..83ca8b9 100644 --- a/lib/g910_gkey_mapper.py +++ b/lib/g910_gkey_mapper.py @@ -11,9 +11,11 @@ import sys import os import fcntl +import itertools log = logger.logger(__name__) +combinations = frozenset(['g'+str(k[0])+'+g'+str(k[1]) for k in itertools.product(range(1,10), range(1,10)) if k[0] < k[1]]) def emitKeys(device, key): if key == 'g1': @@ -36,6 +38,8 @@ def emitKeys(device, key): gkey_functionality.g9(device) elif key == "release": gkey_functionality.release(device) + elif key in combinations: + gkey_functionality.g_combo(device, key) elif media_static_keys_functionality.resolve_key(device, key): pass @@ -101,11 +105,11 @@ def main(): if b in command_bytearray.commands.values(): key = list(command_bytearray.commands.keys())[ list(command_bytearray.commands.values()).index(b)] - log.debug(f"Pressed {key}, bytecode: {b}") + log.info(f"Pressed {key}, bytecode: {b}") emitKeys(device, key) - elif b[:3] in (bytearray(b'\x11\xff\x0f'), bytearray(b'\x11\xff\x10'), bytearray(b'\x11\xff\xff')): - #Suppress warnings on these values, these are return values from LEDs being set. - pass +# elif b[:3] in (bytearray(b'\x11\xff\x0f'), bytearray(b'\x11\xff\x10'), bytearray(b'\x11\xff\xff')): +# #Suppress warnings on these values, these are return values from LEDs being set. +# pass else: log.warning(str(b) + ' no match') except SystemExit: