Skip to main content

Hdc1080

Struct Hdc1080 

Source
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>

Source

pub fn new(bus: I2C, delay: D) -> Self

Wraps an I2C bus; the part has one address.

§Arguments
  • bus - the I2C bus the part is on.
  • delay - the timer that paces the acquisitions.
§Returns

The driver, measuring both channels at 14 bits.

Source

pub fn with_resolutions( self, temperature: TemperatureResolution, humidity: HumidityResolution, ) -> Self

Sets the resolution of each channel, which sets the conversion time.

§Arguments
  • temperature - 11 or 14 bits.
  • humidity - 8, 11, or 14 bits.
§Returns

The driver.

Source

pub fn configuration(&self) -> Configuration

Returns the configuration the driver writes.

Source

pub fn release(self) -> (I2C, D)

Gives back the bus and the delay.

§Returns

The bus and delay the driver was built from.

Source§

impl<I2C: I2c, D: DelayNs> Hdc1080<I2C, D>

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<I2C: Debug, D: Debug> Debug for Hdc1080<I2C, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I2C, D> Sensor for Hdc1080<I2C, D>
where I2C: I2c + Send, I2C::Error: Debug, D: DelayNs + Send,

Source§

type Reading = Measurement

The value produced by a single read, for example a temperature or a fix.
Source§

async fn read(&mut self) -> Result<Measurement>

Takes a single reading from the sensor. Read more
§

fn map<F, T>(self, select: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Reading) -> T,

Wraps this sensor so every reading passes through select first. Read more

Auto Trait Implementations§

§

impl<I2C, D> Freeze for Hdc1080<I2C, D>
where I2C: Freeze, D: Freeze,

§

impl<I2C, D> RefUnwindSafe for Hdc1080<I2C, D>

§

impl<I2C, D> Send for Hdc1080<I2C, D>
where I2C: Send, D: Send,

§

impl<I2C, D> Sync for Hdc1080<I2C, D>
where I2C: Sync, D: Sync,

§

impl<I2C, D> Unpin for Hdc1080<I2C, D>
where I2C: Unpin, D: Unpin,

§

impl<I2C, D> UnsafeUnpin for Hdc1080<I2C, D>
where I2C: UnsafeUnpin, D: UnsafeUnpin,

§

impl<I2C, D> UnwindSafe for Hdc1080<I2C, D>
where I2C: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.