mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-11-25 01:47:10 +06:00
Typographic updates to source generation (#19160)
This commit is contained in:
parent
1d0b4c8d38
commit
3137883956
|
@ -25,17 +25,17 @@ def _gen_led_config(info_data):
|
||||||
if not config_type:
|
if not config_type:
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
matrix = [['NO_LED'] * cols for i in range(rows)]
|
matrix = [['NO_LED'] * cols for _ in range(rows)]
|
||||||
pos = []
|
pos = []
|
||||||
flags = []
|
flags = []
|
||||||
|
|
||||||
led_config = info_data[config_type]['layout']
|
led_layout = info_data[config_type]['layout']
|
||||||
for index, item in enumerate(led_config, start=0):
|
for index, led_data in enumerate(led_layout):
|
||||||
if 'matrix' in item:
|
if 'matrix' in led_data:
|
||||||
(x, y) = item['matrix']
|
row, col = led_data['matrix']
|
||||||
matrix[x][y] = str(index)
|
matrix[row][col] = str(index)
|
||||||
pos.append(f'{{ {item.get("x", 0)},{item.get("y", 0)} }}')
|
pos.append(f'{{{led_data.get("x", 0)}, {led_data.get("y", 0)}}}')
|
||||||
flags.append(str(item.get('flags', 0)))
|
flags.append(str(led_data.get('flags', 0)))
|
||||||
|
|
||||||
if config_type == 'rgb_matrix':
|
if config_type == 'rgb_matrix':
|
||||||
lines.append('#ifdef RGB_MATRIX_ENABLE')
|
lines.append('#ifdef RGB_MATRIX_ENABLE')
|
||||||
|
@ -47,10 +47,10 @@ def _gen_led_config(info_data):
|
||||||
lines.append('__attribute__ ((weak)) led_config_t g_led_config = {')
|
lines.append('__attribute__ ((weak)) led_config_t g_led_config = {')
|
||||||
lines.append(' {')
|
lines.append(' {')
|
||||||
for line in matrix:
|
for line in matrix:
|
||||||
lines.append(f' {{ {",".join(line)} }},')
|
lines.append(f' {{ {", ".join(line)} }},')
|
||||||
lines.append(' },')
|
lines.append(' },')
|
||||||
lines.append(f' {{ {",".join(pos)} }},')
|
lines.append(f' {{ {", ".join(pos)} }},')
|
||||||
lines.append(f' {{ {",".join(flags)} }},')
|
lines.append(f' {{ {", ".join(flags)} }},')
|
||||||
lines.append('};')
|
lines.append('};')
|
||||||
lines.append('#endif')
|
lines.append('#endif')
|
||||||
|
|
||||||
|
|
|
@ -25,32 +25,31 @@ def _generate_layouts(keyboard):
|
||||||
row_num = kb_info_json['matrix_size']['rows']
|
row_num = kb_info_json['matrix_size']['rows']
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for layout_name in kb_info_json['layouts']:
|
for layout_name, layout_data in kb_info_json['layouts'].items():
|
||||||
if kb_info_json['layouts'][layout_name]['c_macro']:
|
if layout_data['c_macro']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if 'matrix' not in kb_info_json['layouts'][layout_name]['layout'][0]:
|
if not all('matrix' in key_data for key_data in layout_data['layout']):
|
||||||
cli.log.debug(f'{keyboard}/{layout_name}: No matrix data!')
|
cli.log.debug(f'{keyboard}/{layout_name}: No or incomplete matrix data!')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
layout_keys = []
|
layout_keys = []
|
||||||
layout_matrix = [['KC_NO' for i in range(col_num)] for i in range(row_num)]
|
layout_matrix = [['KC_NO'] * col_num for _ in range(row_num)]
|
||||||
|
|
||||||
for i, key in enumerate(kb_info_json['layouts'][layout_name]['layout']):
|
for index, key_data in enumerate(layout_data['layout']):
|
||||||
row = key['matrix'][0]
|
row, col = key_data['matrix']
|
||||||
col = key['matrix'][1]
|
identifier = f'k{ROW_LETTERS[row]}{COL_LETTERS[col]}'
|
||||||
identifier = 'k%s%s' % (ROW_LETTERS[row], COL_LETTERS[col])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
layout_matrix[row][col] = identifier
|
layout_matrix[row][col] = identifier
|
||||||
layout_keys.append(identifier)
|
layout_keys.append(identifier)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
key_name = key.get('label', identifier)
|
key_name = key_data.get('label', identifier)
|
||||||
cli.log.error(f'Matrix data out of bounds for layout {layout_name} at index {i} ({key_name}): [{row}, {col}]')
|
cli.log.error(f'{keyboard}/{layout_name}: Matrix data out of bounds at index {index} ({key_name}): [{row}, {col}]')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
lines.append('')
|
lines.append('')
|
||||||
lines.append('#define %s(%s) {\\' % (layout_name, ', '.join(layout_keys)))
|
lines.append(f'#define {layout_name}({", ".join(layout_keys)}) {{ \\')
|
||||||
|
|
||||||
rows = ', \\\n'.join(['\t {' + ', '.join(row) + '}' for row in layout_matrix])
|
rows = ', \\\n'.join(['\t {' + ', '.join(row) + '}' for row in layout_matrix])
|
||||||
rows += ' \\'
|
rows += ' \\'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user