pub struct Measurement {
pub temperature_raw: u16,
pub humidity_raw: u16,
}Expand description
One temperature and humidity data pair, as the part returns it.
The part sends the temperature word, its CRC, the humidity word, and its CRC, in
that order, after a single-shot command or command::FETCH_DATA. parse
checks both CRCs before exposing either word.
§Examples
use pamoja_sensors::sht3x::{
humidity_raw_from_milli_percent, temperature_raw_from_milli_celsius, Measurement,
};
// What a part at 25.0 °C and 60.0 %RH puts on the bus after a single-shot command.
let bytes = Measurement {
temperature_raw: temperature_raw_from_milli_celsius(25_000),
humidity_raw: humidity_raw_from_milli_percent(60_000),
}
.to_bytes();
assert_eq!(bytes, [0x66, 0x66, 0x93, 0x99, 0x99, 0xBE]);
let measurement = Measurement::parse(&bytes)?;
assert_eq!(measurement.temperature_milli_celsius(), 25_000);
assert_eq!(measurement.humidity_milli_percent(), 60_000);Fields§
§temperature_raw: u16The 16-bit temperature word, S_T in the datasheet.
humidity_raw: u16The 16-bit humidity word, S_RH in the datasheet.
Implementations§
Source§impl Measurement
impl Measurement
Sourcepub fn parse(bytes: &[u8; 6]) -> Result<Measurement, SensorError>
pub fn parse(bytes: &[u8; 6]) -> Result<Measurement, SensorError>
Parses and CRC-checks a six-byte measurement frame.
§Arguments
bytes- the six bytes in the order the part sends them: temperature MSB, LSB, CRC, then humidity MSB, LSB, CRC.
§Returns
The two raw words.
§Errors
Returns SensorError::Crc if either CRC byte does not match its two data
bytes, so the read was corrupted and must be repeated.
Sourcepub fn temperature_milli_celsius(&self) -> i32
pub fn temperature_milli_celsius(&self) -> i32
Returns the temperature in millidegrees Celsius.
§Returns
The temperature, rounded to the nearest millidegree.
Sourcepub fn temperature_celsius(&self) -> f32
pub fn temperature_celsius(&self) -> f32
Sourcepub fn temperature_milli_fahrenheit(&self) -> i32
pub fn temperature_milli_fahrenheit(&self) -> i32
Returns the temperature in millidegrees Fahrenheit.
§Returns
The temperature, rounded to the nearest millidegree.
Sourcepub fn temperature_fahrenheit(&self) -> f32
pub fn temperature_fahrenheit(&self) -> f32
Sourcepub fn humidity_milli_percent(&self) -> u32
pub fn humidity_milli_percent(&self) -> u32
Returns the relative humidity in thousandths of a percent.
§Returns
The relative humidity, rounded to the nearest thousandth of a percent.
Sourcepub fn relative_humidity(&self) -> f32
pub fn relative_humidity(&self) -> f32
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 ==.