adafruit / Adafruit_CircuitPython_HID

USB Human Interface Device drivers.
MIT License
364 stars 106 forks source link

Is there a way to receive data? (from the PC it's connected to) #80

Closed jantielens closed 2 years ago

jantielens commented 2 years ago

Hi, I'm wondering if it is possible to use this library to instead of only sending data (keypresses) to the connected PC, also receive data from that PC. The scenario I'm thinking about is to use the LED's (or the screen) of the Adafruit Macropad to represent a state, for example:

I've been looking into the CircuitPython MIDI library, where it's possible to have IN and OUT data. But I'd prefer to have my Macropad act as a HID instead of a MIDI device.

Btw, I understand that on the PC there will have to be some code running to figure out a state and send the data/command to the Macropad. My question is related to the code on the Macropad itself to make this possible.

Thanks a lot! Jan

dhalbert commented 2 years ago

You can send up to 5 bits of data back from the host as LED keyboard light state, and read it with Keyboard.led_status. However, that's very limited. A more practical approach is to use the second USB serial (CDC) channel, known as usb_cdc.data. See https://learn.adafruit.com/customizing-usb-devices-in-circuitpython/circuitpy-midi-serial#usb-serial-console-repl-and-data-3096590-12 for more details.

If you'd like more help with support questions like this, feel free to inquire further at our discord (https://adafru.it/discord) or the forums (https://forums.adafruit.com/viewforum.php?f=60)