pixix4 / ev3dev-lang-rust

Rust language bindings for http://ev3dev.org
MIT License
71 stars 14 forks source link

Add support for getting "raw" data #14

Closed Eoghanmc22 closed 3 years ago

Eoghanmc22 commented 3 years ago

I could be wrong but currently I do not think it is possible to get the data described here through this library. Main use case would be to get a more accurate wheel position.

pixix4 commented 3 years ago

Cause this is an advanced feature I did not add an explicit wrapper. But I opened the Attribute module for arbitrary paths. With this module you can easily take advantage of the file handler caching and typed accessor methods. There are two usage options.

First you can use this module with an explicit path:

use ev3dev_lang_rust::Attribute;

let a = Attribute:: from_path("/sys/bus/iio/devices/iio:device1/in_count0_raw")?;
println!("{}", a.get::<i32>()?);

Second you can use a create method with a discriminator. This method helps to find the right subdirectory within a root_path:

use ev3dev_lang_rust::Attribute;

let a = Attribute::from_path_with_discriminator(
        "/sys/bus/iio/devices", // root_path
        "in_count0_raw",        // attribute_path
        "name",                 // discriminator_path
        "ev3-tacho"             // discriminator_value
)?;
println!("{}", a.get::<i32>()?);

More details for this variant can be found in the docs and at the example.