Transport¶
transport ¶
Async wrappers for blocking HID I/O and input polling.
Bridges the synchronous hidapi calls into asyncio using a shared
:class:~concurrent.futures.ThreadPoolExecutor. Provides an async
input polling loop that yields parsed events.
HidWriteTimeout ¶
async_hid_call
async
¶
async_hid_call(func: Callable[..., object], *args: object, timeout: float = HID_WRITE_TIMEOUT) -> object
Run a blocking HID function in the shared executor with a timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
The blocking function to execute (e.g. |
required |
*args
|
object
|
Arguments to pass to func. |
()
|
timeout
|
float
|
Maximum time in seconds before raising :class: |
HID_WRITE_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
object
|
The return value of func. |
Raises:
| Type | Description |
|---|---|
HidWriteTimeout
|
If the call exceeds timeout seconds. |
HidApiError
|
If the underlying HID operation fails. |
Source code in src/deux/runtime/hid/transport.py
poll_input
async
¶
poll_input(device: HidDevice, poll_interval_ms: int = DEFAULT_POLL_INTERVAL_MS) -> AsyncIterator[InputEvent]
Async generator that polls a device for input events.
Runs device.read_input() in the executor at the specified interval,
yielding parsed events as they arrive. Stops when the device is closed
or disconnected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
HidDevice
|
An open HID device. |
required |
poll_interval_ms
|
int
|
HID read timeout per poll cycle in milliseconds. |
50
|
Yields:
| Type | Description |
|---|---|
InputEvent
|
Parsed input events (key press, touch, encoder). |
Raises:
| Type | Description |
|---|---|
HidApiError
|
If the device disconnects unexpectedly. |