Struct Sensor

Source
pub struct Sensor<I2C> { /* private fields */ }
Expand description

Struct representing an interface to the HTU21D(F) on the I²C bus.

Implementations§

Source§

impl<I2C, E> Sensor<I2C>
where I2C: Read<Error = E> + Write<Error = E>,

Source

pub fn new( i2c: I2C, delay: Option<&mut impl DelayMs<u16>>, ) -> Result<Self, Error<E>>

Create a new struct Sensor for the given I²C interface with the HTU21D listening on the default bus address. If delay is passed, an initial reset is performed as recommended in the datasheet.

Cf. p. 10 of the datasheet.

Source

pub fn destroy(self) -> I2C

Release the owned I²C device by consuming self.

This can be useful for sharing the same bus between multiple drivers manually without resorting to a manager like the shared-bus crate.

Source

pub fn with_address( i2c: I2C, delay: Option<&mut impl DelayMs<u16>>, addr: u8, ) -> Result<Self, Error<E>>

Create a new struct Sensor for the given I²C interface with a custom bus address. If delay is passed, an initial reset is performed as recommended in the datasheet.

Use this e. g. if you’ve resolved a bus address conflict with a multiplexer and the HTU21D is listening on a non-default address.

Source

pub fn start_measurement<const C: u8>(&mut self) -> Result<(), Error<E>>

Initiate a measurement of a particular type.

This will return immediately after submitting the measurement command over I²C without waiting for the sensor to become ready for reading the result. It can be used paired with measurement_result() to implement non-blocking APIs.

Source

pub fn measurement_result<M>(&mut self) -> Result<M, Error<E>>
where M: From<RawMeasurement>,

Read a value for which a measurement has been initiated.

This will return immediately after reading the value from the I²C without waiting for the sensor to become ready first. It can be used together with start_measurement() to implement non-blocking APIs.

Note that this API provides no safeguards against conflating measurement types or insufficient delay since initiating the measurement. Ensuring read readiness of the sensor is up to caller.

Source

pub fn measure_temperature( &mut self, delay: &mut impl DelayMs<u16>, ) -> Result<Temperature, Error<E>>

Perform one blocking temperature measurement for the given measurement type, waiting the appropriate amount of time before reading the value.

Source

pub fn measure_humidity( &mut self, delay: &mut impl DelayMs<u16>, ) -> Result<Humidity, Error<E>>

Perform one blocking humidity measurement for the given measurement type, waiting the appropriate amount of time before reading the value.

Source

pub fn reset(&mut self, delay: &mut impl DelayMs<u16>) -> Result<(), Error<E>>

Send a soft reset command to the sensor and wait for the appropriate time for the device to initialize itself.

Cf. p. 12 of the datasheet.

Trait Implementations§

Source§

impl<I2C: Debug> Debug for Sensor<I2C>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I2C> Freeze for Sensor<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for Sensor<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Sensor<I2C>
where I2C: Send,

§

impl<I2C> Sync for Sensor<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Sensor<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Sensor<I2C>
where I2C: 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.