Lighting as a macropad subcommand; knobless pads start in the flat view

Running the backend module directly made runpy warn, since the package
had already imported it. The lighting commands now sit with doctor, state
and write. A pad without knobs lies flat on the desk, so it is drawn flat
unless an orientation has been chosen.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 19:26:46 +02:00
parent 80c6a5da1c
commit 021f9f7fa1
4 changed files with 58 additions and 64 deletions

View File

@@ -14,12 +14,11 @@ 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.
Run this module for the two things the GUI has no place for yet, lighting
and colour:
Lighting and colour have no place in the GUI yet; they are a subcommand:
python3 -m macropad_gui.backends.itprotech show
python3 -m macropad_gui.backends.itprotech rgb "press: blue"
python3 -m macropad_gui.backends.itprotech colour ff8800
macropad lighting show
macropad lighting rgb "press: blue"
macropad lighting colour ff8800
"""
import errno
@@ -195,60 +194,3 @@ class Itprotech(Backend):
model=f"ITPROTECH {model}")
# -------------------------------------------------------------------- cli
def _main(argv):
import sys
from .. import core
def usage():
print(__doc__.split("Run this module")[1].strip("\n"))
return 2
if not argv or argv[0] not in ("show", "rgb", "colour", "color"):
return usage()
d = core.diagnose(keyd=False)
if not d.device or d.device.vid != wire.VID:
print("No ITPROTECH pad found." if not d.device else d.headline)
return 1
backend = Itprotech()
dev = d.device
if argv[0] == "show":
dump = backend._dump(dev)
for index, report in sorted(dump["keys"].items()):
got = wire.decode(report)
label = got[1].label() if got and got[1] else "(not decodable)"
print(f" key{index:<3} {report[:8].hex(' ')} {label}")
mode = dump["rgb"]
name = wire.RGB_MODES[mode] if mode is not None and mode < len(wire.RGB_MODES) else "?"
print(f" lighting: {mode} ({name}), colour "
f"{'#%02x%02x%02x' % dump['colour'] if dump['colour'] else '?'}")
return 0
if not d.ready:
print(d.headline)
return 1
if argv[0] == "rgb":
if len(argv) < 2:
return usage()
want = argv[1].lower()
mode = int(want) if want.isdigit() else (
wire.RGB_MODES.index(want) if want in wire.RGB_MODES else None)
if mode is None:
print("Modes: " + ", ".join(f"{i} {m}" for i, m in enumerate(wire.RGB_MODES)))
return 1
backend.set_lighting(dev, mode)
print(f"Lighting set to {mode} ({wire.RGB_MODES[mode]}).")
return 0
hexcol = argv[1].lstrip("#") if len(argv) > 1 else ""
if len(hexcol) != 6:
print("Give the colour as RRGGBB, e.g. ff8800")
return 1
rgb = tuple(int(hexcol[i:i + 2], 16) for i in (0, 2, 4))
backend.set_lighting(dev, wire.RGB_CUSTOM, rgb)
print(f"Custom colour #{hexcol} set, lighting mode {wire.RGB_CUSTOM}.")
return 0
if __name__ == "__main__":
import sys
sys.exit(_main(sys.argv[1:]))