mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-26 05:06:42 +00:00
Generate python effect constants
This commit is contained in:
parent
9e93a37c5c
commit
d1e3036ce2
1
.gitignore
vendored
1
.gitignore
vendored
@ -82,6 +82,7 @@ secrets.tar
|
||||
# Python things
|
||||
__pycache__
|
||||
.python-version
|
||||
*.egg-info
|
||||
|
||||
# Prerequisites for updating ChibiOS
|
||||
/util/fmpp*
|
||||
|
14
data/templates/xap/client/python/constants.py.j2
Normal file
14
data/templates/xap/client/python/constants.py.j2
Normal file
@ -0,0 +1,14 @@
|
||||
from enum import IntEnum
|
||||
|
||||
|
||||
# version: 0.0.1
|
||||
class RgblightModes(IntEnum):
|
||||
{%- for id, effect in constants.rgblight.effects | dictsort %}
|
||||
{{ effect.key }} = {{ id }}
|
||||
{%- endfor %}
|
||||
|
||||
|
||||
class RgbMatrixModes(IntEnum):
|
||||
{%- for id, effect in constants.rgb_matrix.effects | dictsort %}
|
||||
{{ effect.key }} = {{ id }}
|
||||
{%- endfor %}
|
@ -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,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)
|
||||
|
@ -3,3 +3,4 @@
|
||||
from .types import * # noqa: F403
|
||||
from .client import * # noqa: F403
|
||||
from .routes import * # noqa: F403
|
||||
from .constants import * # noqa: F403
|
||||
|
122
lib/python/xap_client/constants.py
Normal file
122
lib/python/xap_client/constants.py
Normal file
@ -0,0 +1,122 @@
|
||||
# Copyright 2022 QMK
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# 88888888888 888 d8b .d888 d8b 888 d8b
|
||||
# 888 888 Y8P d88P" Y8P 888 Y8P
|
||||
# 888 888 888 888
|
||||
# 888 88888b. 888 .d8888b 888888 888 888 .d88b. 888 .d8888b
|
||||
# 888 888 "88b 888 88K 888 888 888 d8P Y8b 888 88K
|
||||
# 888 888 888 888 "Y8888b. 888 888 888 88888888 888 "Y8888b.
|
||||
# 888 888 888 888 X88 888 888 888 Y8b. 888 X88
|
||||
# 888 888 888 888 88888P' 888 888 888 "Y8888 888 88888P'
|
||||
#
|
||||
# 888 888
|
||||
# 888 888
|
||||
# 888 888
|
||||
# .d88b. .d88b. 88888b. .d88b. 888d888 8888b. 888888 .d88b. .d88888
|
||||
# d88P"88b d8P Y8b 888 "88b d8P Y8b 888P" "88b 888 d8P Y8b d88" 888
|
||||
# 888 888 88888888 888 888 88888888 888 .d888888 888 88888888 888 888
|
||||
# Y88b 888 Y8b. 888 888 Y8b. 888 888 888 Y88b. Y8b. Y88b 888
|
||||
# "Y88888 "Y8888 888 888 "Y8888 888 "Y888888 "Y888 "Y8888 "Y88888
|
||||
# 888
|
||||
# Y8b d88P
|
||||
# "Y88P"
|
||||
#
|
||||
################################################################################
|
||||
|
||||
from enum import IntEnum
|
||||
|
||||
|
||||
# version: 0.0.1
|
||||
class RgblightModes(IntEnum):
|
||||
STATIC_LIGHT = 0x00
|
||||
BREATHING = 0x01
|
||||
BREATHING_2 = 0x02
|
||||
BREATHING_3 = 0x03
|
||||
BREATHING_4 = 0x04
|
||||
RAINBOW_MOOD = 0x05
|
||||
RAINBOW_MOOD_2 = 0x06
|
||||
RAINBOW_MOOD_3 = 0x07
|
||||
RAINBOW_SWIRL = 0x08
|
||||
RAINBOW_SWIRL_2 = 0x09
|
||||
RAINBOW_SWIRL_3 = 0x0A
|
||||
RAINBOW_SWIRL_4 = 0x0B
|
||||
RAINBOW_SWIRL_5 = 0x0C
|
||||
RAINBOW_SWIRL_6 = 0x0D
|
||||
SNAKE = 0x0E
|
||||
SNAKE_2 = 0x0F
|
||||
SNAKE_3 = 0x10
|
||||
SNAKE_4 = 0x11
|
||||
SNAKE_5 = 0x12
|
||||
SNAKE_6 = 0x13
|
||||
KNIGHT = 0x14
|
||||
KNIGHT_2 = 0x15
|
||||
KNIGHT_3 = 0x16
|
||||
CHRISTMAS = 0x17
|
||||
STATIC_GRADIENT = 0x18
|
||||
STATIC_GRADIENT_2 = 0x19
|
||||
STATIC_GRADIENT_3 = 0x1A
|
||||
STATIC_GRADIENT_4 = 0x1B
|
||||
STATIC_GRADIENT_5 = 0x1C
|
||||
STATIC_GRADIENT_6 = 0x1D
|
||||
STATIC_GRADIENT_7 = 0x1E
|
||||
STATIC_GRADIENT_8 = 0x1F
|
||||
STATIC_GRADIENT_9 = 0x20
|
||||
STATIC_GRADIENT_10 = 0x21
|
||||
RGB_TEST = 0x22
|
||||
ALTERNATING = 0x23
|
||||
TWINKLE = 0x24
|
||||
TWINKLE_2 = 0x25
|
||||
TWINKLE_3 = 0x26
|
||||
TWINKLE_4 = 0x27
|
||||
TWINKLE_5 = 0x28
|
||||
TWINKLE_6 = 0x29
|
||||
|
||||
|
||||
class RgbMatrixModes(IntEnum):
|
||||
SOLID_COLOR = 0x00
|
||||
ALPHAS_MODS = 0x01
|
||||
GRADIENT_UP_DOWN = 0x02
|
||||
GRADIENT_LEFT_RIGHT = 0x03
|
||||
BREATHING = 0x04
|
||||
BAND_SAT = 0x05
|
||||
BAND_VAL = 0x06
|
||||
BAND_PINWHEEL_SAT = 0x07
|
||||
BAND_PINWHEEL_VAL = 0x08
|
||||
BAND_SPIRAL_SAT = 0x09
|
||||
BAND_SPIRAL_VAL = 0x0A
|
||||
CYCLE_ALL = 0x0B
|
||||
CYCLE_LEFT_RIGHT = 0x0C
|
||||
CYCLE_UP_DOWN = 0x0D
|
||||
CYCLE_OUT_IN = 0x0E
|
||||
CYCLE_OUT_IN_DUAL = 0x0F
|
||||
RAINBOW_MOVING_CHEVRON = 0x10
|
||||
CYCLE_PINWHEEL = 0x11
|
||||
CYCLE_SPIRAL = 0x12
|
||||
DUAL_BEACON = 0x13
|
||||
RAINBOW_BEACON = 0x14
|
||||
RAINBOW_PINWHEELS = 0x15
|
||||
RAINDROPS = 0x16
|
||||
JELLYBEAN_RAINDROPS = 0x17
|
||||
HUE_BREATHING = 0x18
|
||||
HUE_PENDULUM = 0x19
|
||||
HUE_WAVE = 0x1A
|
||||
PIXEL_FRACTAL = 0x1B
|
||||
PIXEL_FLOW = 0x1C
|
||||
PIXEL_RAIN = 0x1D
|
||||
TYPING_HEATMAP = 0x1E
|
||||
DIGITAL_RAIN = 0x1F
|
||||
SOLID_REACTIVE_SIMPLE = 0x20
|
||||
SOLID_REACTIVE = 0x21
|
||||
SOLID_REACTIVE_WIDE = 0x22
|
||||
SOLID_REACTIVE_MULTIWIDE = 0x23
|
||||
SOLID_REACTIVE_CROSS = 0x24
|
||||
SOLID_REACTIVE_MULTICROSS = 0x25
|
||||
SOLID_REACTIVE_NEXUS = 0x26
|
||||
SOLID_REACTIVE_MULTINEXUS = 0x27
|
||||
SPLASH = 0x28
|
||||
MULTISPLASH = 0x29
|
||||
SOLID_SPLASH = 0x2A
|
||||
SOLID_MULTISPLASH = 0x2B
|
Loading…
Reference in New Issue
Block a user