#bindings #userspace #idiomatic #devices #build #source #link

xwiimote

Idiomatic Rust bindings to the xwiimote user-space library

9 releases

0.2.5 Sep 24, 2023
0.2.4 Sep 20, 2023
0.2.2 Aug 26, 2022
0.2.1 Jun 9, 2022
0.1.3 Jun 7, 2022

#271 in Hardware support

34 downloads per month

MIT license

48KB
782 lines

xwiimote

Crates.io docs.rs Build status

Idiomatic Rust bindings to the xwiimote user-space library.

Usage

You will need the following dependencies to build and use the library:

  • libudev >= 183
  • libxwiimote >= 2-2 (optional; set XWIIMOTE_SYS_STATIC=1 to build from source and link statically.)

The wiinote application showcases the functionality provided by this library.

License

MIT © Hugo Sanz González


lib.rs:

This library provides a safe Rust interface to the xwiimote user-space library.

Examples

Connect to the first Wii Remote found and print its battery level.

use xwiimote::{Device, Monitor};
use futures_util::TryStreamExt;

// A monitor enumerates the addresses of all connected Wii Remotes.
let mut monitor = Monitor::enumerate()?;
match monitor.try_next().await {
    Ok(Some(address)) => {
        // Connect to the Wii Remote specified by `address`.
        let device = Device::connect(&address)?;
        let level = device.battery()?;
        println!("the battery level is {}%", level);
    }
    Ok(None) => println!("found no connected device"),
    Err(e) => eprintln!("could not enumerate devices: {e}"),
};

Print device addresses as new Wii Remotes are discovered.

use xwiimote::{Device, Monitor};
use futures_util::TryStreamExt;

let mut monitor = Monitor::discover()?;
while let Ok(Some(address)) = monitor.try_next().await {
    println!("found device at {address:?}");
}

Dependencies

~0.8–3.5MB
~68K SLoC