From d1bac1f50a1e78e2df3f82237cb35d9d2dfdc30b Mon Sep 17 00:00:00 2001 From: jr4 Date: Sat, 21 Dec 2024 13:48:49 -0600 Subject: [PATCH] protocol for pause and IR enable --- src/led_ble_hf/protocol.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/led_ble_hf/protocol.py b/src/led_ble_hf/protocol.py index e9e87fb..d640a62 100644 --- a/src/led_ble_hf/protocol.py +++ b/src/led_ble_hf/protocol.py @@ -22,11 +22,15 @@ def construct_state_change(self, turn_on: int) -> bytearray: bytearray([0xAA, 0x02, 0x01, 1 if turn_on else 0]) ) - def construct_message(self, raw_bytes: bytearray) -> bytearray: - """Calculate checksum of byte array and add to end.""" - csum = sum(raw_bytes) & 0xFF - raw_bytes.append(csum) - return raw_bytes + def construct_pause(self, pause: bool) -> bytearray: + """The bytes to send for pausing or unpausing.""" + return self.construct_message(bytearray([0xAA, 0x11, 0x01, 1 if pause else 0])) + + def construct_ir_state(self, turn_on: bool) -> bytearray: + """The bytes to send for enabling/disabling the IR remote.""" + return self.construct_message( + bytearray([0xAA, 0x0F, 0x01, 1 if turn_on else 0]) + ) def construct_levels_change( self, @@ -117,3 +121,9 @@ def construct_motion(self, speed: int, transition: int) -> list[bytearray]: bytearray([0xAA, 0xD0, 0x04, transition, 0x64, speed, 0x01]) ) ] + + def construct_message(self, raw_bytes: bytearray) -> bytearray: + """Calculate checksum of byte array and add to end.""" + csum = sum(raw_bytes) & 0xFF + raw_bytes.append(csum) + return raw_bytes