Generate python effect constants

This commit is contained in:
zvecr
2022-10-13 01:42:27 +01:00
parent 9e93a37c5c
commit d1e3036ce2
7 changed files with 151 additions and 6 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ def xap_generate_python(cli):
defs = latest_xap_defs()
parent = QMK_FIRMWARE / 'lib' / 'python' / 'xap_client'
for name in ['types.py', 'routes.py']:
for name in ['types.py', 'routes.py', 'constants.py']:
lines = [GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE]
output = render_xap_output('client/python', f'{name}.j2', defs)
+9 -2
View File
@@ -9,7 +9,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
from qmk.casing import to_snake
from qmk.constants import QMK_FIRMWARE
from qmk.json_schema import validate
from qmk.json_schema import json_load, validate
from qmk.decorators import lru_cache
from qmk.keymap import locate_keymap
from qmk.path import keyboard
@@ -25,7 +25,14 @@ def _get_jinja2_env(data_templates_xap_subdir: str):
def render_xap_output(data_templates_xap_subdir, file_to_render, defs):
j2 = _get_jinja2_env(data_templates_xap_subdir)
return j2.get_template(file_to_render).render(xap=defs, xap_str=hjson.dumps(defs), to_snake=to_snake)
j2.globals['to_snake'] = to_snake
constants = {}
for feature in ['rgblight', 'rgb_matrix']:
constants[feature] = json_load(Path(f'data/constants/{feature}_0.0.1.json'))
return j2.get_template(file_to_render).render(xap=defs, xap_str=hjson.dumps(defs), constants=constants)
def _find_kb_spec(kb):
@@ -25,8 +25,8 @@ PREFIX_MAP = {
}
def _get_lighting_spec(xap_defs, feature):
version = xap_defs['uses'][feature]
def _get_lighting_spec(feature):
version = '0.0.1'
spec = json_load(Path(f'data/constants/{feature}_{version}.json'))
# preprocess for gross rgblight "mode + n"
@@ -407,7 +407,7 @@ def _append_lighting_mapping(lines, xap_defs):
''')
for feature in PREFIX_MAP.keys():
spec = _get_lighting_spec(xap_defs, feature)
spec = _get_lighting_spec(feature)
lines.append(f'#ifdef {feature.upper()}_ENABLE')
_append_lighting_map(lines, feature, spec)