From 68208278e087dd7c8ce0c4709d79cb6ab5e8941c Mon Sep 17 00:00:00 2001 From: zvecr Date: Wed, 11 May 2022 01:52:48 +0100 Subject: [PATCH] Render layers with 'qmk info' logic --- data/constants/keycodes_0.0.1.json | 6 +++--- lib/python/qmk/cli/xap/xap.py | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/data/constants/keycodes_0.0.1.json b/data/constants/keycodes_0.0.1.json index a3a1537ab1..7644ba223b 100644 --- a/data/constants/keycodes_0.0.1.json +++ b/data/constants/keycodes_0.0.1.json @@ -210,7 +210,7 @@ "0x0028": { "group": "basic", "key": "KC_ENTER", - "label": "0", + "label": "Enter", "aliases": [ "KC_ENT" ] @@ -218,7 +218,7 @@ "0x0029": { "group": "basic", "key": "KC_ESCAPE", - "label": "0", + "label": "Esc", "aliases": [ "KC_ESC" ] @@ -226,7 +226,7 @@ "0x002a": { "group": "basic", "key": "KC_BACKSPACE", - "label": "0", + "label": "Backspace", "aliases": [ "KC_BSPC" ] diff --git a/lib/python/qmk/cli/xap/xap.py b/lib/python/qmk/cli/xap/xap.py index e0af627ef3..8de1b56808 100644 --- a/lib/python/qmk/cli/xap/xap.py +++ b/lib/python/qmk/cli/xap/xap.py @@ -8,6 +8,7 @@ from platform import platform from milc import cli +from qmk.keyboard import render_layout from qmk.xap.common import get_xap_keycodes KEYCODE_MAP = get_xap_keycodes('latest') @@ -86,7 +87,7 @@ def _xap_transaction(device, sub, route, *args): device.write(buffer) # get resp - array_alpha = device.read(64, 100) + array_alpha = device.read(64, 250) # validate tok sent == resp if str(token) != str(array_alpha[:2]): @@ -250,7 +251,6 @@ class XAPShell(cmd.Cmd): rows = info['matrix_size']['rows'] cols = info['matrix_size']['cols'] - # TODO: render like qmk info? for r in range(rows): for c in range(cols): q = data + r.to_bytes(1, byteorder='little') + c.to_bytes(1, byteorder='little') @@ -259,6 +259,29 @@ class XAPShell(cmd.Cmd): print(f'| {self.keycodes.get(keycode, "unknown").ljust(7)} ', end='', flush=True) print('|') + def do_layer(self, arg): + """Renders keycode values of a certain layer + """ + data = bytes(map(int, arg.split())) + if len(data) != 1: + cli.log.error("Invalid args") + return + + info = _query_device_info(self.device) + + # Assumptions on selected layout rather than prompt + first_layout = next(iter(info['layouts'])) + layout = info['layouts'][first_layout]['layout'] + + keycodes = [] + for item in layout: + q = data + bytes(item['matrix']) + keycode = _xap_transaction(self.device, 0x04, 0x02, q) + keycode = int.from_bytes(keycode, "little") + keycodes.append(self.keycodes.get(keycode, "???")) + + print(render_layout(layout, False, keycodes)) + def do_exit(self, line): """Quit shell """