adafruit / Adafruit_CircuitPython_HID

USB Human Interface Device drivers.
MIT License
377 stars 105 forks source link

adafruit_hid.keyboard.Keyboard.led_on only returns True once only #112

Closed andreasbrett closed 1 year ago

andreasbrett commented 1 year ago

CircuitPython version

Adafruit CircuitPython 8.0.4 on 2023-03-15; Raspberry Pi Zero W with bcm2835

Code/REPL

import time
import usb_hid
from adafruit_hid.keyboard import Keyboard

kbd = Keyboard(usb_hid.devices)
while True:
    print(kbd.led_on(Keyboard.LED_CAPS_LOCK))
    time.sleep(0.1)

Behavior

adafruit_hid.keyboard.Keyboard.led_on only reports True once and not the whole time the LED is on.

The above code should print out True while caps lock is on and False otherwise. Testing this code in a RPi Pico confirms this behavior. On the RPi Zero though True is only printed once per loop then immediately returns back to False even though the caps lock is still on.

Description

No response

Additional information

No response

andreasbrett commented 1 year ago

tested and same behaviour for:

dhalbert commented 1 year ago

Transferred issue to the library. This is occurring because of https://github.com/adafruit/circuitpython/pull/6767, which fixed .get_last_received_report(). But the library was not updated to handle the new semantics. The library now needs to keep a state variable that reflects what the last received report is, instead of just querying .get_last_received_report().