diff options
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-x | lib/python/qmk/cli/generate/keyboard_c.py | 22 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/keyboard_h.py | 23 |
2 files changed, 22 insertions, 23 deletions
diff --git a/lib/python/qmk/cli/generate/keyboard_c.py b/lib/python/qmk/cli/generate/keyboard_c.py index a9b742f323..9004b41abb 100755 --- a/lib/python/qmk/cli/generate/keyboard_c.py +++ b/lib/python/qmk/cli/generate/keyboard_c.py @@ -25,17 +25,17 @@ def _gen_led_config(info_data): if not config_type: return lines - matrix = [['NO_LED'] * cols for i in range(rows)] + matrix = [['NO_LED'] * cols for _ in range(rows)] pos = [] flags = [] - led_config = info_data[config_type]['layout'] - for index, item in enumerate(led_config, start=0): - if 'matrix' in item: - (x, y) = item['matrix'] - matrix[x][y] = str(index) - pos.append(f'{{ {item.get("x", 0)},{item.get("y", 0)} }}') - flags.append(str(item.get('flags', 0))) + led_layout = info_data[config_type]['layout'] + for index, led_data in enumerate(led_layout): + if 'matrix' in led_data: + row, col = led_data['matrix'] + matrix[row][col] = str(index) + pos.append(f'{{{led_data.get("x", 0)}, {led_data.get("y", 0)}}}') + flags.append(str(led_data.get('flags', 0))) if config_type == 'rgb_matrix': 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(' {') for line in matrix: - lines.append(f' {{ {",".join(line)} }},') + lines.append(f' {{ {", ".join(line)} }},') lines.append(' },') - lines.append(f' {{ {",".join(pos)} }},') - lines.append(f' {{ {",".join(flags)} }},') + lines.append(f' {{ {", ".join(pos)} }},') + lines.append(f' {{ {", ".join(flags)} }},') lines.append('};') lines.append('#endif') diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py index 910bd6a08d..152921bdce 100755 --- a/lib/python/qmk/cli/generate/keyboard_h.py +++ b/lib/python/qmk/cli/generate/keyboard_h.py @@ -25,32 +25,31 @@ def _generate_layouts(keyboard): row_num = kb_info_json['matrix_size']['rows'] lines = [] - for layout_name in kb_info_json['layouts']: - if kb_info_json['layouts'][layout_name]['c_macro']: + for layout_name, layout_data in kb_info_json['layouts'].items(): + if layout_data['c_macro']: continue - if 'matrix' not in kb_info_json['layouts'][layout_name]['layout'][0]: - cli.log.debug(f'{keyboard}/{layout_name}: No matrix data!') + if not all('matrix' in key_data for key_data in layout_data['layout']): + cli.log.debug(f'{keyboard}/{layout_name}: No or incomplete matrix data!') continue 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']): - row = key['matrix'][0] - col = key['matrix'][1] - identifier = 'k%s%s' % (ROW_LETTERS[row], COL_LETTERS[col]) + for index, key_data in enumerate(layout_data['layout']): + row, col = key_data['matrix'] + identifier = f'k{ROW_LETTERS[row]}{COL_LETTERS[col]}' try: layout_matrix[row][col] = identifier layout_keys.append(identifier) except IndexError: - key_name = key.get('label', identifier) - cli.log.error(f'Matrix data out of bounds for layout {layout_name} at index {i} ({key_name}): [{row}, {col}]') + key_name = key_data.get('label', identifier) + cli.log.error(f'{keyboard}/{layout_name}: Matrix data out of bounds at index {index} ({key_name}): [{row}, {col}]') return [] 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 += ' \\' |