Medius - Rust LibraryLifecycle

Lifecycle

Holding injected input alive and recovering a dropped link

The library holds deliberate overrides past the box's silence-timeout clear, and restores them if the link drops and reopens.

  • keepalive (automatic) holds an override past the silence timeout.
  • reapply re-sends the held overrides so the box matches the library.
  • reconnect rescans, reopens the port, and restores held state after a dropped link.

reapply

Re-send the held overrides so the box matches the library
fn reapply(&self) -> Result<()>

Fire-and-forget

One frame goes out per held override; reconnect does this for you after a drop.

EXAMPLE
device.press(Button::Left)?;
device.reapply()?; // re-assert the held override, e.g. if the box reset under you
EXAMPLE
// The no-op case: reset clears every override, so reapply sends nothing.
device.reset()?;
device.reapply()?; // does nothing, no buttons are held

Overrides 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 state
fn 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:

  1. Rescans for the box by its USB identity, vendor ID 0x1A86 and product ID 0x55D3 (see Transport).
  2. Reopens the port.
  3. Re-applies the held overrides, the same work as reapply.
  4. Bumps the reconnect counter.
EXAMPLE
// 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 direct

AsyncDevice 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.

EXAMPLE
use medius::AsyncDevice;

let device = AsyncDevice::open("/dev/ttyACM0")?;
device.reapply()?;     // re-assert held overrides
device.reconnect()?;   // blocks: rescan + reopen

See async for the full async surface and how into_inner and into_async move between the two views.