Struct Sample
pub struct Sample { /* private fields */ }sensors only.Expand description
Represents a value obtained from a sensor device, along with its metadata.
§Scaling
The scaling value obtained from the sensor driver with
Sensor::reading_channels() must be taken into account using the
following formula:
For instance, in the case of a temperature sensor, if Self::value() returns 2225 and the
scaling value is -2, this means that the temperature measured and returned by the sensor
device is 22.25 (the measurement error must additionally be taken into
account).
This is required to avoid handling floats.
§Unit of measurement
The unit of measurement can be obtained using
ReadingChannel::unit().
§Accuracy
The accuracy can be obtained through Self::metadata().
Implementations§
§impl Sample
impl Sample
pub const fn new(value: i32, metadata: SampleMetadata) -> Sample
pub const fn new(value: i32, metadata: SampleMetadata) -> Sample
Creates a new sample.
This constructor is intended for sensor driver implementors only.
pub fn value(&self) -> Result<i32, SampleError>
pub fn value(&self) -> Result<i32, SampleError>
pub fn metadata(&self) -> SampleMetadata
pub fn metadata(&self) -> SampleMetadata
Returns the measurement metadata, including accuracy if available.