Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for g-keys combinations #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified cli_entry_point.py
100644 → 100755
Empty file.
13 changes: 11 additions & 2 deletions lib/data_mappers/command_bytearray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
'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
22 changes: 13 additions & 9 deletions lib/data_mappers/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions lib/functionalities/gkey_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
12 changes: 8 additions & 4 deletions lib/g910_gkey_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down