class documentation

USB HID Consumer Control device for media key input.

Builds a composite USB descriptor by appending a HID Consumer Control interface to the existing CDC configuration so both the REPL serial port and the media keys are available at the same time.

Method __init__ Create a USBMedia instance.
Method init Initialise and activate the composite CDC + HID Consumer Control device.
Method press Send a Consumer Control key press and immediately release it.
Constant HID_IAD Undocumented
Constant HID_REPORT_DESC Undocumented
Constant USAGE_MUTE Undocumented
Constant USAGE_NEXT_TRACK Undocumented
Constant USAGE_PLAY_PAUSE Undocumented
Constant USAGE_PREV_TRACK Undocumented
Constant USAGE_STOP Undocumented
Constant USAGE_VOL_DOWN Undocumented
Constant USAGE_VOL_UP Undocumented
Method _on_control_xfer_cb Control-transfer callback for HID class requests.
Method _on_xfer_cb Transfer-complete callback; unblocks _wait when EP 0x83 finishes.
Method _wait Block until the previous HID transfer completes or the timeout expires.
Instance Variable _manufacturer Undocumented
Instance Variable _product Undocumented
Instance Variable _serial Undocumented
Instance Variable _usbdev Undocumented
Instance Variable _xfer_done Undocumented
def __init__(self, manufacturer='MicroPython', product='Pico Media', serial='000002'):

Create a USBMedia instance.

Parameters
manufacturer:strManufacturer string in the USB device descriptor. Defaults to "MicroPython".
product:strProduct string in the USB device descriptor. Defaults to "Pico Media".
serial:strSerial number string in the USB device descriptor. Defaults to "000002".
def init(self):

Initialise and activate the composite CDC + HID Consumer Control device.

Appends a HID Consumer Control interface to the built-in CDC descriptor, re-configures the USBDevice, and activates it. Must be called once before any key-sending methods are used.

def press(self, usage):

Send a Consumer Control key press and immediately release it.

Parameters
usage:intHID Consumer Control usage ID (e.g. USAGE_PLAY_PAUSE).
HID_IAD =

Undocumented

Value
bytes([8, 11, 2, 1, 3, 1, 1, 0])
HID_REPORT_DESC =

Undocumented

Value
bytes([5,
       12,
       9,
       1,
       161,
       1,
       21,
...
USAGE_MUTE: int =

Undocumented

Value
226
USAGE_NEXT_TRACK: int =

Undocumented

Value
181
USAGE_PLAY_PAUSE: int =

Undocumented

Value
205
USAGE_PREV_TRACK: int =

Undocumented

Value
182
USAGE_STOP: int =

Undocumented

Value
183
USAGE_VOL_DOWN: int =

Undocumented

Value
234
USAGE_VOL_UP: int =

Undocumented

Value
233
def _on_control_xfer_cb(self, stage, request):

Control-transfer callback for HID class requests.

Parameters
stage:intTransfer stage (1 = SETUP, 3 = ACK).
request:bytesRaw 8-byte SETUP packet.
Returns
bytes, boolRequested data, True to ACK with no data, or False to stall.
def _on_xfer_cb(self, ep, res, num_bytes):

Transfer-complete callback; unblocks _wait when EP 0x83 finishes.

Parameters
ep:intEndpoint address that completed the transfer.
res:intResult code from the USB stack.
num_bytes:intNumber of bytes transferred.
def _wait(self, timeout_ms=500):

Block until the previous HID transfer completes or the timeout expires.

Parameters
timeout_ms:intMaximum number of milliseconds to wait. Defaults to 500.
Returns
boolTrue if the transfer completed within the timeout, False otherwise.
_manufacturer =

Undocumented

_product =

Undocumented

_serial =

Undocumented

_usbdev =

Undocumented

_xfer_done: bool =

Undocumented