class USB_HID – USB Human Interface Device (HID)¶
The USB_HID class represents the OpenMV Cam’s USB Human Interface Device interface. It can be used to emulate a peripheral such as a mouse or keyboard.
Before constructing a USB_HID object, call pyb.usb_mode() with
a mode that includes HID (e.g. 'VCP+HID') – this enumerates
the USB HID class on the host. The report descriptor passed to
usb_mode selects the device class; pre-built tuples are available
as pyb.hid_mouse and pyb.hid_keyboard.
Example – send a mouse left-click then move it 5 pixels right:
import pyb
pyb.usb_mode("VCP+HID", hid=pyb.hid_mouse)
hid = pyb.USB_HID()
# report layout: (buttons, dx, dy, wheel)
hid.send((1, 0, 0, 0)) # press left button
hid.send((0, 0, 0, 0)) # release
hid.send((0, 5, 0, 0)) # move +5 in X
Constructors¶
- class pyb.USB_HID¶
Create a new USB_HID object. There is only one HID interface, so the constructor returns the singleton object.
Methods¶
- send(data: Tuple[int, ...] | List[int] | bytes | bytearray) None¶
Send an HID input report to the USB host.
datais a tuple/list of integers or abytes-like buffer whose layout depends on the report descriptor in use. For the built-in mouse descriptor the report is(buttons, dx, dy, wheel); for the keyboard descriptor it is(modifiers, 0, key1, key2, key3, key4, key5, key6). Seepyb.hid_mouseandpyb.hid_keyboard.
- recv(data: int | bytearray, *, timeout: int = 5000) bytes | int¶
Receive an HID output report from the USB host (e.g. keyboard LED state). Returns immediately if a report is already buffered.
datais either anint(the number of bytes to read into a fresh buffer) or a mutable buffer to fill with received bytes.timeoutis the maximum time in milliseconds to wait for a report.
If
datais an integer a freshbytesobject is returned; otherwise the number of bytes written intodatais returned.