Skip to content

Remember LED status #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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