CLI: Allow generation of both LED and RGB Matrix config (#22896)
This commit is contained in:
parent
e2517ff9a4
commit
1bebaa310a
2 changed files with 30 additions and 29 deletions
|
@ -9,21 +9,25 @@ from qmk.path import normpath
|
||||||
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
|
from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
|
||||||
|
|
||||||
|
|
||||||
def _gen_led_config(info_data):
|
def _gen_led_configs(info_data):
|
||||||
|
lines = []
|
||||||
|
|
||||||
|
if 'layout' in info_data.get('rgb_matrix', {}):
|
||||||
|
lines.extend(_gen_led_config(info_data, 'rgb_matrix'))
|
||||||
|
|
||||||
|
if 'layout' in info_data.get('led_matrix', {}):
|
||||||
|
lines.extend(_gen_led_config(info_data, 'led_matrix'))
|
||||||
|
|
||||||
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
def _gen_led_config(info_data, config_type):
|
||||||
"""Convert info.json content to g_led_config
|
"""Convert info.json content to g_led_config
|
||||||
"""
|
"""
|
||||||
cols = info_data['matrix_size']['cols']
|
cols = info_data['matrix_size']['cols']
|
||||||
rows = info_data['matrix_size']['rows']
|
rows = info_data['matrix_size']['rows']
|
||||||
|
|
||||||
config_type = None
|
|
||||||
if 'layout' in info_data.get('rgb_matrix', {}):
|
|
||||||
config_type = 'rgb_matrix'
|
|
||||||
elif 'layout' in info_data.get('led_matrix', {}):
|
|
||||||
config_type = 'led_matrix'
|
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
if not config_type:
|
|
||||||
return lines
|
|
||||||
|
|
||||||
matrix = [['NO_LED'] * cols for _ in range(rows)]
|
matrix = [['NO_LED'] * cols for _ in range(rows)]
|
||||||
pos = []
|
pos = []
|
||||||
|
@ -53,6 +57,7 @@ def _gen_led_config(info_data):
|
||||||
lines.append(f' {{ {", ".join(flags)} }},')
|
lines.append(f' {{ {", ".join(flags)} }},')
|
||||||
lines.append('};')
|
lines.append('};')
|
||||||
lines.append('#endif')
|
lines.append('#endif')
|
||||||
|
lines.append('')
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
@ -98,7 +103,7 @@ def generate_keyboard_c(cli):
|
||||||
# Build the layouts.h file.
|
# Build the layouts.h file.
|
||||||
keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', '']
|
keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', '']
|
||||||
|
|
||||||
keyboard_h_lines.extend(_gen_led_config(kb_info_json))
|
keyboard_h_lines.extend(_gen_led_configs(kb_info_json))
|
||||||
keyboard_h_lines.extend(_gen_matrix_mask(kb_info_json))
|
keyboard_h_lines.extend(_gen_matrix_mask(kb_info_json))
|
||||||
|
|
||||||
# Show the results
|
# Show the results
|
||||||
|
|
|
@ -686,27 +686,23 @@ def _extract_led_config(info_data, keyboard):
|
||||||
cols = info_data['matrix_size']['cols']
|
cols = info_data['matrix_size']['cols']
|
||||||
rows = info_data['matrix_size']['rows']
|
rows = info_data['matrix_size']['rows']
|
||||||
|
|
||||||
# Determine what feature owns g_led_config
|
for feature in ['rgb_matrix', 'led_matrix']:
|
||||||
feature = None
|
if info_data.get('features', {}).get(feature, False) or feature in info_data:
|
||||||
for feat in ['rgb_matrix', 'led_matrix']:
|
|
||||||
if info_data.get('features', {}).get(feat, False) or feat in info_data:
|
|
||||||
feature = feat
|
|
||||||
|
|
||||||
if feature:
|
# Only attempt search if dd led config is missing
|
||||||
# Only attempt search if dd led config is missing
|
if 'layout' not in info_data.get(feature, {}):
|
||||||
if 'layout' not in info_data.get(feature, {}):
|
# Process
|
||||||
# Process
|
for file in find_keyboard_c(keyboard):
|
||||||
for file in find_keyboard_c(keyboard):
|
try:
|
||||||
try:
|
ret = find_led_config(file, cols, rows)
|
||||||
ret = find_led_config(file, cols, rows)
|
if ret:
|
||||||
if ret:
|
info_data[feature] = info_data.get(feature, {})
|
||||||
info_data[feature] = info_data.get(feature, {})
|
info_data[feature]['layout'] = ret
|
||||||
info_data[feature]['layout'] = ret
|
except Exception as e:
|
||||||
except Exception as e:
|
_log_warning(info_data, f'led_config: {file.name}: {e}')
|
||||||
_log_warning(info_data, f'led_config: {file.name}: {e}')
|
|
||||||
|
|
||||||
if info_data[feature].get('layout', None) and not info_data[feature].get('led_count', None):
|
if info_data[feature].get('layout', None) and not info_data[feature].get('led_count', None):
|
||||||
info_data[feature]['led_count'] = len(info_data[feature]['layout'])
|
info_data[feature]['led_count'] = len(info_data[feature]['layout'])
|
||||||
|
|
||||||
return info_data
|
return info_data
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue