Use keycodes for xap version
This commit is contained in:
parent
41a5dcbfa7
commit
5028d6672a
2 changed files with 37 additions and 10 deletions
|
@ -2,9 +2,12 @@
|
|||
"""
|
||||
import os
|
||||
import hjson
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from qmk.constants import QMK_FIRMWARE
|
||||
from pathlib import Path
|
||||
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):
|
||||
|
@ -78,6 +81,32 @@ def latest_xap_defs():
|
|||
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):
|
||||
"""Handles building the C preprocessor conditional based on the current route.
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue