Send the LED list with every lighting effect

Most hardware effects (color wave, shift, pulse, rain, watercolor,
typing, visor) only run on the LEDs listed after the colors. Without
the list they lit nothing. Add the K65 PLUS LED indices (US/ISO/UK)
and always send the color count, so random-color effects get the
right layout too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-23 21:29:30 +02:00
1 parent 2a12166615
commit ea88e87a3d
2 files changed
+33 -17

No files matched your search

+17 -10
View File
@@ -144,19 +144,26 @@ class Rgb:
LIGHTING_BLOCK_SIZE = 96
# LEDs of the K65 PLUS (US, ISO and UK layouts). The index equals the key's HID usage,
# except the space bar, which has three LEDs (0, 1, 44).
K65_LEDS = bytes([
0, 1, *range(4, 70), 74, 75, 76, *range(78, 83), 100, 105, 106, 107, 108, 109, 110, 111, 122,
])
def lighting_packets(target: int, effect: int, color_mode: int = COLORS_NONE, speed: int = 0,
direction: int = 0, colors: list[Rgb] | tuple[Rgb, ...] = ()) -> list[bytes]:
"""Hardware lighting effect: id, color mode, speed, direction, then colors as (A, B, G, R)."""
direction: int = 0, colors: list[Rgb] | tuple[Rgb, ...] = (),
leds: bytes = K65_LEDS) -> list[bytes]:
"""Hardware lighting effect: id, color mode, speed, direction, colors as (A, B, G, R),
then the LEDs the effect runs on. Without the LED list most effects light nothing."""
body = bytearray(struct.pack("<H", effect))
body += bytes([color_mode, speed, direction, 0x00])
if colors:
body.append(len(colors))
for c in colors:
body += bytes([0xFF, c.b, c.g, c.r])
# Same declared lengths OpenLinkHub uses; everything past the colors is zero padding.
declared = 93 if effect == FX_STATIC else 89
return block_packets(target, bytes(body.ljust(LIGHTING_BLOCK_SIZE, b"\x00")), declared)
body += bytes([color_mode, speed, direction, 0x00, len(colors)])
for c in colors:
body += bytes([0xFF, c.b, c.g, c.r])
body += bytes([len(leds)]) + leds
body = body.ljust(LIGHTING_BLOCK_SIZE, b"\x00")
# The length excludes the effect id and color mode (93 for a plain static color).
return block_packets(target, bytes(body), len(body) - 3)
def parse_u16(resp: bytes, offset: int = 3) -> int: