Render layers with 'qmk info' logic

This commit is contained in:
zvecr 2022-05-11 01:52:48 +01:00
parent 87106e44c8
commit 68208278e0
2 changed files with 28 additions and 5 deletions

View file

@ -210,7 +210,7 @@
"0x0028": { "0x0028": {
"group": "basic", "group": "basic",
"key": "KC_ENTER", "key": "KC_ENTER",
"label": "0", "label": "Enter",
"aliases": [ "aliases": [
"KC_ENT" "KC_ENT"
] ]
@ -218,7 +218,7 @@
"0x0029": { "0x0029": {
"group": "basic", "group": "basic",
"key": "KC_ESCAPE", "key": "KC_ESCAPE",
"label": "0", "label": "Esc",
"aliases": [ "aliases": [
"KC_ESC" "KC_ESC"
] ]
@ -226,7 +226,7 @@
"0x002a": { "0x002a": {
"group": "basic", "group": "basic",
"key": "KC_BACKSPACE", "key": "KC_BACKSPACE",
"label": "0", "label": "Backspace",
"aliases": [ "aliases": [
"KC_BSPC" "KC_BSPC"
] ]

View file

@ -8,6 +8,7 @@ from platform import platform
from milc import cli from milc import cli
from qmk.keyboard import render_layout
from qmk.xap.common import get_xap_keycodes from qmk.xap.common import get_xap_keycodes
KEYCODE_MAP = get_xap_keycodes('latest') KEYCODE_MAP = get_xap_keycodes('latest')
@ -86,7 +87,7 @@ def _xap_transaction(device, sub, route, *args):
device.write(buffer) device.write(buffer)
# get resp # get resp
array_alpha = device.read(64, 100) array_alpha = device.read(64, 250)
# validate tok sent == resp # validate tok sent == resp
if str(token) != str(array_alpha[:2]): if str(token) != str(array_alpha[:2]):
@ -250,7 +251,6 @@ class XAPShell(cmd.Cmd):
rows = info['matrix_size']['rows'] rows = info['matrix_size']['rows']
cols = info['matrix_size']['cols'] cols = info['matrix_size']['cols']
# TODO: render like qmk info?
for r in range(rows): for r in range(rows):
for c in range(cols): for c in range(cols):
q = data + r.to_bytes(1, byteorder='little') + c.to_bytes(1, byteorder='little') 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(f'| {self.keycodes.get(keycode, "unknown").ljust(7)} ', end='', flush=True)
print('|') 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): def do_exit(self, line):
"""Quit shell """Quit shell
""" """