mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-04-18 05:05:40 +00:00
Use keycodes for xap version
This commit is contained in:
parent
41a5dcbfa7
commit
5028d6672a
@ -4,17 +4,13 @@ import cmd
|
|||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import gzip
|
import gzip
|
||||||
from pathlib import Path
|
|
||||||
from platform import platform
|
from platform import platform
|
||||||
|
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from qmk.json_schema import json_load
|
from qmk.xap.common import get_xap_keycodes
|
||||||
|
|
||||||
# TODO: get from xap "uses" for the current device
|
KEYCODE_MAP = get_xap_keycodes('0.2.0')
|
||||||
keycode_version = '0.0.1'
|
|
||||||
spec = json_load(Path(f'data/constants/keycodes_{keycode_version}.json'))
|
|
||||||
KEYCODE_MAP = {int(k, 16): v.get('aliases', [v.get('key')])[0] for k, v in spec['keycodes'].items()}
|
|
||||||
|
|
||||||
|
|
||||||
def _is_xap_usage(x):
|
def _is_xap_usage(x):
|
||||||
@ -210,6 +206,8 @@ class XAPShell(cmd.Cmd):
|
|||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
cmd.Cmd.__init__(self)
|
cmd.Cmd.__init__(self)
|
||||||
self.device = device
|
self.device = device
|
||||||
|
# cache keycodes for this device
|
||||||
|
self.keycodes = get_xap_keycodes(_query_device(device)['xap'])
|
||||||
|
|
||||||
def do_about(self, arg):
|
def do_about(self, arg):
|
||||||
"""Prints out the current version of QMK with a build date
|
"""Prints out the current version of QMK with a build date
|
||||||
@ -238,7 +236,7 @@ class XAPShell(cmd.Cmd):
|
|||||||
|
|
||||||
keycode = _xap_transaction(self.device, 0x04, 0x02, data)
|
keycode = _xap_transaction(self.device, 0x04, 0x02, data)
|
||||||
keycode = int.from_bytes(keycode, "little")
|
keycode = int.from_bytes(keycode, "little")
|
||||||
print(f'keycode:{KEYCODE_MAP.get(keycode, "unknown")}[{keycode}]')
|
print(f'keycode:{self.keycodes.get(keycode, "unknown")}[{keycode}]')
|
||||||
|
|
||||||
def do_keymap(self, arg):
|
def do_keymap(self, arg):
|
||||||
"""Prints out the keycode values of a certain layer
|
"""Prints out the keycode values of a certain layer
|
||||||
@ -258,7 +256,7 @@ class XAPShell(cmd.Cmd):
|
|||||||
q = data + r.to_bytes(1, byteorder='little') + c.to_bytes(1, byteorder='little')
|
q = data + r.to_bytes(1, byteorder='little') + c.to_bytes(1, byteorder='little')
|
||||||
keycode = _xap_transaction(self.device, 0x04, 0x02, q)
|
keycode = _xap_transaction(self.device, 0x04, 0x02, q)
|
||||||
keycode = int.from_bytes(keycode, "little")
|
keycode = int.from_bytes(keycode, "little")
|
||||||
print(f'| {KEYCODE_MAP.get(keycode, "unknown").ljust(7)} ', end='', flush=True)
|
print(f'| {self.keycodes.get(keycode, "unknown").ljust(7)} ', end='', flush=True)
|
||||||
print('|')
|
print('|')
|
||||||
|
|
||||||
def do_exit(self, line):
|
def do_exit(self, line):
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import hjson
|
import hjson
|
||||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
from pathlib import Path
|
||||||
from qmk.constants import QMK_FIRMWARE
|
|
||||||
from typing import OrderedDict
|
from typing import OrderedDict
|
||||||
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||||
|
|
||||||
|
from qmk.constants import QMK_FIRMWARE
|
||||||
|
from qmk.json_schema import json_load
|
||||||
|
|
||||||
|
|
||||||
def _get_jinja2_env(data_templates_xap_subdir: str):
|
def _get_jinja2_env(data_templates_xap_subdir: str):
|
||||||
@ -78,6 +81,32 @@ def latest_xap_defs():
|
|||||||
return _merge_ordered_dicts(definitions)
|
return _merge_ordered_dicts(definitions)
|
||||||
|
|
||||||
|
|
||||||
|
def get_xap_defs(version):
|
||||||
|
"""Gets the required version of the XAP definitions.
|
||||||
|
"""
|
||||||
|
files = get_xap_definition_files()
|
||||||
|
|
||||||
|
# Slice off anything newer than specified version
|
||||||
|
index = [idx for idx, s in enumerate(files) if version in str(s)][0]
|
||||||
|
files = files[:(index + 1)]
|
||||||
|
|
||||||
|
definitions = [hjson.load(file.open(encoding='utf-8')) for file in files]
|
||||||
|
return _merge_ordered_dicts(definitions)
|
||||||
|
|
||||||
|
|
||||||
|
def get_xap_keycodes(xap_version):
|
||||||
|
"""Gets keycode data for the required version of the XAP definitions.
|
||||||
|
"""
|
||||||
|
defs = get_xap_defs(xap_version)
|
||||||
|
|
||||||
|
# Load DD keycodes for the dependency
|
||||||
|
keycode_version = defs['uses']['keycodes']
|
||||||
|
spec = json_load(Path(f'data/constants/keycodes_{keycode_version}.json'))
|
||||||
|
|
||||||
|
# Transform into something more usable - { raw_value : first alias || keycode }
|
||||||
|
return {int(k, 16): v.get('aliases', [v.get('key')])[0] for k, v in spec['keycodes'].items()}
|
||||||
|
|
||||||
|
|
||||||
def route_conditions(route_stack):
|
def route_conditions(route_stack):
|
||||||
"""Handles building the C preprocessor conditional based on the current route.
|
"""Handles building the C preprocessor conditional based on the current route.
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user