Skip to content

Commit

Permalink
feat: protocol for pause and IR enable
Browse files Browse the repository at this point in the history
  • Loading branch information
jr4 committed Dec 21, 2024
1 parent 19fb87c commit cb10703
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/led_ble_hf/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit cb10703

Please sign in to comment.