Skip to content

Commit 7258db8

Browse files
committed
Remember LED status
1 parent 1288942 commit 7258db8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

adafruit_hid/keyboard.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def __init__(self, devices: Sequence[usb_hid.Device]) -> None:
6262
# View onto bytes 2-7 in report.
6363
self.report_keys = memoryview(self.report)[2:]
6464

65+
# No keyboard LEDs on.
66+
self._led_status = b"\x00"
67+
6568
# Do a no-op to test if HID device is ready.
6669
# If not, wait a bit and try once more.
6770
try:
@@ -178,7 +181,10 @@ def _remove_keycode_from_report(self, keycode: int) -> None:
178181
def led_status(self) -> bytes:
179182
"""Returns the last received report"""
180183
# get_last_received_report() returns None when nothing was received
181-
return self._keyboard_device.get_last_received_report() or b"\x00"
184+
led_report = self._keyboard_device.get_last_received_report()
185+
if led_report is not None:
186+
self._led_status = led_report
187+
return self._led_status
182188

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

0 commit comments

Comments
 (0)