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>
impl<I2C, E> Sensor<I2C>
Sourcepub fn new(
i2c: I2C,
delay: Option<&mut impl DelayMs<u16>>,
) -> Result<Self, Error<E>>
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.
Sourcepub fn destroy(self) -> I2C
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.
Sourcepub fn with_address(
i2c: I2C,
delay: Option<&mut impl DelayMs<u16>>,
addr: u8,
) -> Result<Self, Error<E>>
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.
Sourcepub fn start_measurement<const C: u8>(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn measurement_result<M>(&mut self) -> Result<M, Error<E>>where
M: From<RawMeasurement>,
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.
Sourcepub fn measure_temperature(
&mut self,
delay: &mut impl DelayMs<u16>,
) -> Result<Temperature, Error<E>>
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.