bosch_bme680/
error.rs

1use core::fmt::Formatter;
2use embedded_hal::i2c::ErrorType;
3
4/// All possible errors
5pub enum BmeError<I2C>
6where
7    I2C: ErrorType,
8{
9    /// Error during I2C write operation.
10    WriteError(I2C::Error),
11    /// Error during I2C WriteRead operation.
12    WriteReadError(I2C::Error),
13    /// Got an unexpected ChipId during sensor initalization.
14    UnexpectedChipId(u8),
15    /// After running the measurment the sensor blocks until the 'new data bit' of the sensor is set.
16    /// Should this take more than 5 tries an error is returned instead of incorrect data.
17    MeasuringTimeOut,
18    /// An [`AsyncBme680`](crate::AsyncBme680) has not yet been initialized.
19    #[cfg(feature = "embedded-hal-async")]
20    Uninitialized,
21}
22
23impl<I2C> core::fmt::Debug for BmeError<I2C>
24where
25    I2C: ErrorType,
26{
27    fn fmt(&self, f: &mut Formatter<'_>) -> core::result::Result<(), core::fmt::Error> {
28        match self {
29            BmeError::WriteReadError(e) => f.debug_tuple("WriteReadError").field(e).finish(),
30            BmeError::WriteError(e) => f.debug_tuple("WriteError").field(e).finish(),
31            BmeError::UnexpectedChipId(chip_id) => f
32                .debug_tuple("Got unimplemented chip id: ")
33                .field(chip_id)
34                .finish(),
35            BmeError::MeasuringTimeOut => f
36                .debug_tuple("Timed out while waiting for new measurement values. Either no new data or the sensor took unexpectedly long to finish measuring.").finish(),
37            #[cfg(feature = "embedded-hal-async")]
38            BmeError::Uninitialized => f.debug_tuple("Uninitialized").finish(),
39        }
40    }
41}