Skip to content

Commit

Permalink
Merge pull request #113 from dhalbert/fix-led-status
Browse files Browse the repository at this point in the history
Remember LED status
  • Loading branch information
dhalbert authored Mar 20, 2023
2 parents 1288942 + 7258db8 commit b93f918
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion adafruit_hid/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def __init__(self, devices: Sequence[usb_hid.Device]) -> None:
# View onto bytes 2-7 in report.
self.report_keys = memoryview(self.report)[2:]

# No keyboard LEDs on.
self._led_status = b"\x00"

# Do a no-op to test if HID device is ready.
# If not, wait a bit and try once more.
try:
Expand Down Expand Up @@ -178,7 +181,10 @@ def _remove_keycode_from_report(self, keycode: int) -> None:
def led_status(self) -> bytes:
"""Returns the last received report"""
# get_last_received_report() returns None when nothing was received
return self._keyboard_device.get_last_received_report() or b"\x00"
led_report = self._keyboard_device.get_last_received_report()
if led_report is not None:
self._led_status = led_report
return self._led_status

def led_on(self, led_code: int) -> bool:
"""Returns whether an LED is on based on the led code
Expand Down

0 comments on commit b93f918

Please sign in to comment.