summaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk')
-rwxr-xr-xlib/python/qmk/cli/info.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py
index 5925b57258..26f7f0269d 100755
--- a/lib/python/qmk/cli/info.py
+++ b/lib/python/qmk/cli/info.py
@@ -102,6 +102,48 @@ def show_matrix(kb_info_json, title_caps=True):
102 print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels)) 102 print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels))
103 103
104 104
105def show_leds(kb_info_json, title_caps=True):
106 """Render LED indices per key, using the keyboard's key layout geometry.
107
108 We build a map from (row, col) -> LED index using rgb_matrix/led_matrix layout,
109 then label each key with its LED index. Keys without an associated LED are left blank.
110 """
111 # Prefer rgb_matrix, fall back to led_matrix
112 led_feature = None
113 for feature in ['rgb_matrix', 'led_matrix']:
114 if 'layout' in kb_info_json.get(feature, {}):
115 led_feature = feature
116 break
117
118 if not led_feature:
119 cli.echo('{fg_yellow}No rgb_matrix/led_matrix layout found to derive LED indices.{fg_reset}')
120 return
121
122 # Build mapping from matrix position -> LED indices for faster lookup later
123 by_matrix = {}
124 for idx, led in enumerate(kb_info_json[led_feature]['layout']):
125 if 'matrix' in led:
126 led_key = tuple(led.get('matrix'))
127 by_matrix[led_key] = idx
128
129 # For each keyboard layout (e.g., LAYOUT), render keys labeled with LED index (or blank)
130 for layout_name, layout in kb_info_json['layouts'].items():
131 labels = []
132 for key in layout['layout']:
133 led_key = tuple(key.get('matrix'))
134 label = str(by_matrix[led_key]) if led_key in by_matrix else ''
135
136 labels.append(label)
137
138 # Header
139 if title_caps:
140 cli.echo('{fg_blue}LED indices for "%s"{fg_reset}:', layout_name)
141 else:
142 cli.echo('{fg_blue}leds_%s{fg_reset}:', layout_name)
143
144 print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels))
145
146
105def print_friendly_output(kb_info_json): 147def print_friendly_output(kb_info_json):
106 """Print the info.json in a friendly text format. 148 """Print the info.json in a friendly text format.
107 """ 149 """
@@ -169,6 +211,7 @@ def print_parsed_rules_mk(keyboard_name):
169@cli.argument('-km', '--keymap', help='Keymap to show info for (Optional).') 211@cli.argument('-km', '--keymap', help='Keymap to show info for (Optional).')
170@cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') 212@cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.')
171@cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.') 213@cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.')
214@cli.argument('-L', '--leds', action='store_true', help='Render the LED layout with LED indices (rgb_matrix/led_matrix).')
172@cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).') 215@cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).')
173@cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.') 216@cli.argument('--ascii', action='store_true', default=not UNICODE_SUPPORT, help='Render layout box drawings in ASCII only.')
174@cli.argument('-r', '--rules-mk', action='store_true', help='Render the parsed values of the keyboard\'s rules.mk file.') 217@cli.argument('-r', '--rules-mk', action='store_true', help='Render the parsed values of the keyboard\'s rules.mk file.')
@@ -227,5 +270,8 @@ def info(cli):
227 if cli.config.info.matrix: 270 if cli.config.info.matrix:
228 show_matrix(kb_info_json, title_caps) 271 show_matrix(kb_info_json, title_caps)
229 272
273 if cli.config.info.leds:
274 show_leds(kb_info_json, title_caps)
275
230 if cli.config.info.keymap: 276 if cli.config.info.keymap:
231 show_keymap(kb_info_json, title_caps) 277 show_keymap(kb_info_json, title_caps)