Skip to content

Commit cfce656

Browse files
authored
Merge pull request #37 from hw0lff/fix-bindata
Add Attribute::get_bytes and fix Sensor::get_bin_data
2 parents 7026c9b + 2208091 commit cfce656

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/attribute.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ impl Attribute {
118118
})
119119
}
120120

121+
/// Returns the current content of the wrapped file.
122+
pub fn get_bytes(&self) -> Ev3Result<Vec<u8>> {
123+
let mut value: Vec<u8> = Vec::new();
124+
let mut file = self.file.lock().unwrap();
125+
file.seek(SeekFrom::Start(0))?;
126+
file.read_to_end(&mut value)?;
127+
Ok(value)
128+
}
129+
121130
/// Returns the current value of the wrapped file.
122131
fn get_str(&self) -> Ev3Result<String> {
123132
let mut value = String::new();

src/sensors/sensor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::{Device, Ev3Result};
66
pub trait Sensor: Device {
77
/// Reading the file will give the unscaled raw values in the `value<N>` attributes.
88
/// Use `bin_data_format`, `num_values` and the individual sensor documentation to determine how to interpret the data.
9-
fn get_bin_data(&self) -> Ev3Result<String> {
10-
self.get_attribute("bin_data").get()
9+
fn get_bin_data(&self) -> Ev3Result<Vec<u8>> {
10+
self.get_attribute("bin_data").get_bytes()
1111
}
1212

1313
/// Returns the format of the values in `bin_data` for the current mode. Possible values are:

0 commit comments

Comments
 (0)