pub struct Measurement {
pub co2_ppm: u16,
pub temperature_raw: u16,
pub humidity_raw: u16,
}Expand description
One SCD4x measurement, as the three words of read_measurement.
The temperature and humidity words are kept raw so the decode stays exact; the methods convert them.
Fields§
§co2_ppm: u16The CO2 concentration in parts per million (word[0]).
temperature_raw: u16The 16-bit temperature word (word[1]).
humidity_raw: u16The 16-bit humidity word (word[2]).
Implementations§
Source§impl Measurement
impl Measurement
Sourcepub fn parse(frame: &[u8; 9]) -> Result<Measurement, SensorError>
pub fn parse(frame: &[u8; 9]) -> Result<Measurement, SensorError>
Parses the nine bytes read after command::READ_MEASUREMENT.
Table 11: CO2, temperature, and humidity words in that order, each most significant byte first and followed by its CRC.
§Arguments
frame- the nine response bytes.
§Returns
The measurement.
§Errors
Returns SensorError::Crc if any of the three CRC bytes does not match
its word.
Sourcepub fn from_physical(
co2_ppm: u16,
milli_celsius: i32,
humidity_milli_percent: u32,
) -> Measurement
pub fn from_physical( co2_ppm: u16, milli_celsius: i32, humidity_milli_percent: u32, ) -> Measurement
Builds a measurement from physical values.
The inverse of the decode methods, so a node can be fed the frame a sensor would send for a chosen reading.
§Arguments
co2_ppm- the CO2 concentration in ppm.milli_celsius- the temperature in milli-degrees Celsius.humidity_milli_percent- the relative humidity in milli-percent.
§Returns
The measurement with its raw words built by temperature_raw and
humidity_raw.
Sourcepub fn to_bytes(&self) -> [u8; 9]
pub fn to_bytes(&self) -> [u8; 9]
Builds the nine bytes a sensor sends for this measurement.
The inverse of Measurement::parse.
§Returns
The three word frames, each word followed by its CRC.
Sourcepub fn milli_celsius(&self) -> i32
pub fn milli_celsius(&self) -> i32
Returns the temperature in milli-degrees Celsius.
Sourcepub fn humidity_milli_percent(&self) -> u32
pub fn humidity_milli_percent(&self) -> u32
Returns the relative humidity in milli-percent.
Sourcepub fn relative_humidity_percent(&self) -> f32
pub fn relative_humidity_percent(&self) -> f32
Returns the relative humidity in percent.
Trait Implementations§
Source§impl Clone for Measurement
impl Clone for Measurement
Source§fn clone(&self) -> Measurement
fn clone(&self) -> Measurement
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Measurement
Source§impl Debug for Measurement
impl Debug for Measurement
impl Eq for Measurement
Source§impl PartialEq for Measurement
impl PartialEq for Measurement
Source§fn eq(&self, other: &Measurement) -> bool
fn eq(&self, other: &Measurement) -> bool
self and other values to be equal, and is used by ==.