From ea88e87a3deae5a0631449914275be833be8d68e Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 23 Oct 2026 21:29:30 +0200 Subject: [PATCH] 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 --- k65studio/bragi.py | 27 +++++++++++++++++---------- tests/test_protocol.py | 23 ++++++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/k65studio/bragi.py b/k65studio/bragi.py index b2819e0..a97d56f 100644 --- a/k65studio/bragi.py +++ b/k65studio/bragi.py @@ -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(" int: diff --git a/tests/test_protocol.py b/tests/test_protocol.py index feb1c78..5e0d379 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -6,27 +6,36 @@ from k65studio.profiles import Config, Profile class PacketTests(unittest.TestCase): - def test_static_color_matches_known_good_capture(self): + def test_static_color(self): pkts = effects.encode(bragi.TARGET_PAIRED, "static", ["#ff0080"], False, "medium") self.assertEqual(len(pkts), 2) - self.assertEqual(pkts[0][:15].hex(" "), "09 06 01 5d 00 00 00 7e 20 01 00 00 00 01 ff") - self.assertEqual(pkts[0][15:18], bytes([0x80, 0x00, 0xFF])) # B, G, R + self.assertEqual(pkts[0][:7].hex(" "), "09 06 01 5e 00 00 00") # 97 byte body - 3 + self.assertEqual(pkts[0][7:14].hex(" "), "7e 20 01 00 00 00 01") + self.assertEqual(pkts[0][14:18], bytes([0xFF, 0x80, 0x00, 0xFF])) # A, B, G, R + self.assertEqual(pkts[0][18], len(bragi.K65_LEDS)) self.assertEqual(pkts[1][:3], bytes([0x09, 0x07, 0x01])) def test_rainbow_wave_header(self): pkt = effects.encode(bragi.TARGET_PAIRED, "rainbow_wave", [], False, "fast")[0] - self.assertEqual(pkt[3:12].hex(" "), "59 00 00 00 4c b9 00 05 04") + self.assertEqual(pkt[7:14].hex(" "), "4c b9 00 05 04 00 00") + self.assertEqual(pkt[14], len(bragi.K65_LEDS)) def test_random_colors_have_no_color_list(self): pkt = effects.encode(bragi.TARGET_PAIRED, "color_shift", ["#ffffff"], True, "slow")[0] - self.assertEqual(pkt[7:13].hex(" "), "fa a5 02 03 00 00") - self.assertEqual(pkt[13], 0) + self.assertEqual(pkt[7:14].hex(" "), "fa a5 02 03 00 00 00") + self.assertEqual(pkt[14], len(bragi.K65_LEDS)) - def test_two_specific_colors(self): + def test_two_specific_colors_then_leds(self): pkt = effects.encode(bragi.TARGET_PAIRED, "color_pulse", ["#010203", "#040506"], False, "medium")[0] self.assertEqual(pkt[9], bragi.COLORS_SPECIFIC) self.assertEqual(pkt[13], 2) self.assertEqual(pkt[14:22], bytes([0xFF, 3, 2, 1, 0xFF, 6, 5, 4])) + self.assertEqual(pkt[22], len(bragi.K65_LEDS)) + self.assertEqual(pkt[23:26], bytes([0, 1, 4])) + + def test_led_list_covers_all_layouts(self): + self.assertEqual(len(bragi.K65_LEDS), 85) + self.assertEqual(len(set(bragi.K65_LEDS)), 85) def test_packets_fit_report(self): for key in effects.EFFECTS: