Lifecycle
Holding injected input alive and recovering a dropped linkThe library holds deliberate overrides past the box's silence-timeout clear, and restores them if the link drops and reopens.
reapply
Re-send the held overrides so the box matches the libraryfn reapply(&self) -> Result<()>
Fire-and-forget
One frame goes out per held override; reconnect does this for you after a drop.
device.press(Button::Left)?;
device.reapply()?; // re-assert the held override, e.g. if the box reset under you// The no-op case: reset clears every override, so reapply sends nothing.
device.reset()?;
device.reapply()?; // does nothing, no buttons are heldOverrides are keyed by their Usage (a button, key, or media usage). press and force_release add a held override; release and reset clear them.
reconnect
Rescan, reopen the port, and restore held statefn reconnect(&self) -> Result<()>
The reader thread auto-reconnects on any read error; call this by hand only to force a rescan. It blocks while it rescans and reopens the port, and returns an error if the box can't be found or opened, but it never waits on a box reply.
On each call:
- Rescans for the box by its USB identity, vendor ID
0x1A86and product ID0x55D3(see Transport). - Reopens the port.
- Re-applies the held overrides, the same work as
reapply. - Bumps the reconnect counter.
// After a known unplug and replug, force a rescan and confirm it took.
let before = device.counters().reconnects;
device.reconnect()?;
let after = device.counters().reconnects;
assert!(after > before);The reconnect count is the reconnects field in diagnostics. Held state is keyed by Usage, so the right inputs come back after a reopen.
On AsyncDevice
reapply and reconnect, still directAsyncDevice exposes reapply and reconnect directly, same signatures. reapply is a fire-and-forget frame; reconnect blocks while it rescans and reopens the port, so keep it off a latency-sensitive task.
use medius::AsyncDevice;
let device = AsyncDevice::open("/dev/ttyACM0")?;
device.reapply()?; // re-assert held overrides
device.reconnect()?; // blocks: rescan + reopenSee async for the full async surface and how into_inner and into_async move between the two views.