Lighting menu in the window for pads that have backlight modes

A backend that lists lighting_modes gets a Lighting button in the footer:
one entry per mode and a colour picker for the custom one. The tick
follows what the pad reported in its last read, since every read of an
ITPROTECH pad carries the lighting along with the keys.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 19:37:44 +02:00
parent 4f33161c70
commit 625c95f09c
4 changed files with 197 additions and 3 deletions

View File

@@ -14,7 +14,8 @@ Three things about this firmware shape the code:
read again and has to come back byte for byte as sent. A write that
doesn't is reported as such, and the control is marked unknown.
Lighting and colour have no place in the GUI yet; they are a subcommand:
Lighting is pad wide rather than per key, so the GUI offers it in a
Lighting menu at the foot of the window, and the CLI as a subcommand:
macropad lighting show
macropad lighting rgb "press: blue"
@@ -37,9 +38,12 @@ class Itprotech(Backend):
max_keys = 12
max_knobs = 0
sequences = True # multikey: several keys, one modifier mask
lighting_modes = wire.RGB_MODES # offered by the GUI's Lighting menu
lighting_custom = wire.RGB_CUSTOM # the mode that takes a colour
def __init__(self):
self._data_len = {} # device path -> key record length seen
self._lighting = {} # device path -> (mode, colour) last read
# ------------------------------------------------------------ protocol
@@ -79,6 +83,8 @@ class Itprotech(Backend):
dump = wire.parse_dump(replies)
if dump["data_len"]:
self._data_len[device.path] = dump["data_len"]
if dump["rgb"] is not None:
self._lighting[device.path] = (dump["rgb"], dump["colour"])
return dump
def info(self, device):
@@ -105,6 +111,15 @@ class Itprotech(Backend):
dump = self._dump(device)
return dump["rgb"], dump["colour"]
def last_lighting(self, device):
"""
(mode, colour) from the most recent read of this pad, or None.
Every read returns the lighting along with the keys, so the GUI can
show it without asking the pad again.
"""
return self._lighting.get(device.path)
# --------------------------------------------------------------- write
def _send(self, device, report, _write=None):
@@ -164,6 +179,8 @@ class Itprotech(Backend):
self._send(device, wire.rgb_frame(mode), _write)
if mode == wire.RGB_CUSTOM and colour is not None:
self._send(device, wire.colour_frame(*colour), _write)
old = self._lighting.get(device.path, (None, None))
self._lighting[device.path] = (mode, colour if colour is not None else old[1])
# -------------------------------------------------------------- detect