Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Using the irbt library

The irbt crate is the library behind the CLI: port discovery, framing and a typed client for every command. Add the registry (see Installing the CLI), then:

cargo add irbt --registry selu

Example

use std::time::Duration;

use irbt::{Device, HidKey, Notification};

fn main() -> Result<(), irbt::Error> {
    let device = Device::open(None)?; // auto-detect the bridge

    let info = device.info()?;
    println!("firmware {} (protocol v{})", info.firmware_version, info.protocol_version);

    device.set_mapping(0x00FF_02FD, HidKey::Home)?;
    for mapping in device.keymap()? {
        println!("0x{:08X} -> {}", mapping.ir, mapping.key);
    }

    // Stream received IR codes.
    device.set_monitor(true)?;
    while let Some(notification) = device.next_notification(Duration::from_secs(30))? {
        if let Notification::Event(event) = notification {
            println!("{event:?}");
        }
    }
    Ok(())
}
  • Device::open takes a port path, or None to pick the only connected bridge. find_ports lists them.
  • Each method sends one command and waits for its reply. set_timeout changes how long it waits.
  • Events, log lines and unframed output (bootloader text, panic dumps) arrive as Notifications through next_notification.
  • Device::from_io runs the client over any reader/writer pair, e.g. in tests.

The protocol types are re-exported from irbt-proto as irbt::proto.