qmk_settings: initial prototype

main
Ilya Zhuravlev 2021-06-29 19:43:21 -04:00
parent fc5fa1ac66
commit 49948a7e76
3 changed files with 78 additions and 3 deletions

View File

@ -52,6 +52,10 @@ CMD_VIAL_UNLOCK_START = 0x06
CMD_VIAL_UNLOCK_POLL = 0x07
CMD_VIAL_LOCK = 0x08
CMD_VIAL_QMK_SETTINGS_QUERY = 0x09
CMD_VIAL_QMK_SETTINGS_GET = 0x0A
CMD_VIAL_QMK_SETTINGS_SET = 0x0B
# how much of a macro/keymap buffer we can read/write per packet
BUFFER_FETCH_CHUNK = 28
@ -637,6 +641,23 @@ class Keyboard:
macros = macros[:self.macro_count]
return [self.macro_deserialize(x) for x in macros]
def qmk_settings_query(self):
raise NotImplementedError
def qmk_settings_get(self, qsid):
data = self.usb_send(self.dev, struct.pack("<BBH", CMD_VIA_VIAL_PREFIX, CMD_VIAL_QMK_SETTINGS_GET, qsid),
retries=20)
if data[0] != 0:
return b""
return data[1:]
def qmk_settings_set(self, qsid, value):
print("change setting {} to value {}".format(qsid, value.hex()))
data = self.usb_send(self.dev, struct.pack("<BBH", CMD_VIA_VIAL_PREFIX, CMD_VIAL_QMK_SETTINGS_SET, qsid) + value,
retries=20)
print("resp", data.hex())
return data[0]
class DummyKeyboard(Keyboard):

View File

@ -16,6 +16,7 @@ from keymap_editor import KeymapEditor
from keymaps import KEYMAPS
from layout_editor import LayoutEditor
from macro_recorder import MacroRecorder
from qmk_settings import QmkSettings
from rgb_configurator import RGBConfigurator
from unlocker import Unlocker
from util import tr, find_vial_devices, EXAMPLE_KEYBOARDS
@ -56,12 +57,13 @@ class MainWindow(QMainWindow):
self.keymap_editor = KeymapEditor(self.layout_editor)
self.firmware_flasher = FirmwareFlasher(self)
self.macro_recorder = MacroRecorder()
self.qmk_settings = QmkSettings()
self.matrix_tester = MatrixTest(self.layout_editor)
self.rgb_configurator = RGBConfigurator()
self.editors = [(self.keymap_editor, "Keymap"), (self.layout_editor, "Layout"), (self.macro_recorder, "Macros"),
(self.rgb_configurator, "Lighting"), (self.matrix_tester, "Matrix tester"),
(self.firmware_flasher, "Firmware updater")]
(self.rgb_configurator, "Lighting"), (self.qmk_settings, "QMK Settings"),
(self.matrix_tester, "Matrix tester"), (self.firmware_flasher, "Firmware updater")]
Unlocker.global_layout_editor = self.layout_editor
@ -254,7 +256,7 @@ class MainWindow(QMainWindow):
self.current_device.keyboard.reload()
for e in [self.layout_editor, self.keymap_editor, self.firmware_flasher, self.macro_recorder,
self.matrix_tester, self.rgb_configurator]:
self.qmk_settings, self.matrix_tester, self.rgb_configurator]:
e.rebuild(self.current_device)
def refresh_tabs(self):

View File

@ -0,0 +1,52 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import struct
from PyQt5 import QtCore
from PyQt5.QtWidgets import QVBoxLayout, QCheckBox, QGridLayout, QLabel, QWidget, QSizePolicy
from basic_editor import BasicEditor
from vial_device import VialKeyboard
class QmkSettings(BasicEditor):
def __init__(self):
super().__init__()
w = QWidget()
w.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
self.container = QGridLayout()
w.setLayout(self.container)
self.addWidget(w)
self.setAlignment(w, QtCore.Qt.AlignHCenter)
self.container.addWidget(QLabel("Always send Escape if Alt is pressed"), 0, 0)
self.container.addWidget(QCheckBox(), 0, 1)
self.container.addWidget(QLabel("Always send Escape if Control is pressed"), 1, 0)
self.chk_ctrl = QCheckBox()
self.chk_ctrl.stateChanged.connect(self.on_checked)
self.container.addWidget(self.chk_ctrl, 1, 1)
self.container.addWidget(QLabel("Always send Escape if GUI is pressed"), 2, 0)
self.container.addWidget(QCheckBox(), 2, 1)
self.container.addWidget(QLabel("Always send Escape if Shift is pressed"), 3, 0)
self.container.addWidget(QCheckBox(), 3, 1)
self.keyboard = None
def reload_settings(self):
gresc = self.keyboard.qmk_settings_get(1)[0]
self.chk_ctrl.setChecked(gresc & 2)
def on_checked(self, state):
data = struct.pack("B", int(self.chk_ctrl.isChecked()) * 2)
self.keyboard.qmk_settings_set(1, data)
def rebuild(self, device):
super().rebuild(device)
if self.valid():
self.keyboard = device.keyboard
self.reload_settings()
def valid(self):
return isinstance(self.device, VialKeyboard) and \
(self.device.keyboard and self.device.keyboard.vial_protocol >= 3) # TODO(xyz): protocol bump