pub struct Hdc1080<I2C, D> { /* private fields */ }Expand description
An HDC1080 on an I2C bus, measuring temperature and humidity on demand.
init checks the manufacturer and device id registers and
writes the configuration: the mode that measures temperature and humidity in one
sequence, at the chosen resolutions. measure follows the
datasheet’s transaction: a pointer write to the temperature register triggers
the acquisition, the conversion time for both resolutions passes, and one
four-byte read returns temperature then humidity. The part does not acknowledge
a read before the results are ready, which surfaces as a bus error rather than a
stale value. As a [Sensor] its reading is the Measurement; one channel is
selected with [Sensor::map].
§Examples
A humidor’s climate, read from an HDC1080 that is not plugged in yet: the simulated part holds 21.5 °C and 45 % relative humidity, and the driver waits out both conversions before it reads them.
use pamoja_core::Sensor;
use pamoja_hal::script::{block_on, DelayLog};
use pamoja_sensors::hdc1080::{sim, Hdc1080};
let mut sensor = Hdc1080::new(sim::reporting(21.5, 45.0), DelayLog::new());
let climate = block_on(sensor.read())?;
assert!((climate.milli_celsius() - 21_500).abs() < 10);
assert!((climate.relative_humidity() - 45.0).abs() < 0.1);Implementations§
Source§impl<I2C, D> Hdc1080<I2C, D>
impl<I2C, D> Hdc1080<I2C, D>
Sourcepub fn with_resolutions(
self,
temperature: TemperatureResolution,
humidity: HumidityResolution,
) -> Self
pub fn with_resolutions( self, temperature: TemperatureResolution, humidity: HumidityResolution, ) -> Self
Sourcepub fn configuration(&self) -> Configuration
pub fn configuration(&self) -> Configuration
Returns the configuration the driver writes.
Source§impl<I2C: I2c, D: DelayNs> Hdc1080<I2C, D>
impl<I2C: I2c, D: DelayNs> Hdc1080<I2C, D>
Sourcepub fn init(&mut self) -> Result<(), DriverError<I2C::Error>>
pub fn init(&mut self) -> Result<(), DriverError<I2C::Error>>
Checks the part’s identity and writes the configuration.
§Errors
Returns DriverError::Bus if the bus fails, and DriverError::Sensor
with SensorError::Identity if either id register is not an HDC1080’s.
Sourcepub fn measure(&mut self) -> Result<Measurement, DriverError<I2C::Error>>
pub fn measure(&mut self) -> Result<Measurement, DriverError<I2C::Error>>
Triggers one acquisition of both channels and reads the results.
Initializes the part first if init has not run.
§Returns
The temperature and humidity registers as a Measurement.
§Errors
Returns DriverError::Bus if the bus fails, which includes the part not
acknowledging a read before its results are ready, or any error of
init.
Sourcepub fn heater(&mut self, on: bool) -> Result<(), DriverError<I2C::Error>>
pub fn heater(&mut self, on: bool) -> Result<(), DriverError<I2C::Error>>
Switches the heater, which runs only during acquisitions, on or off.
§Arguments
on- whether the heater runs.
§Errors
Returns DriverError::Bus if the bus fails.