1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use core::fmt::Formatter;
use embedded_hal::i2c::{I2c, SevenBitAddress};


/// All possible errors
pub enum BmeError<I2C>
where
    I2C: I2c<SevenBitAddress>
{
    /// Error during I2C write operation.
    WriteError(I2C::Error),
    /// Error during I2C WriteRead operation.
    WriteReadError(I2C::Error),
    /// Got an unexpected ChipId during sensor initalization.
    UnexpectedChipId(u8),
    /// After running the measurment the sensor blocks until the 'new data bit' of the sensor is set.
    /// Should this take more than 5 tries an error is returned instead of incorrect data.
    MeasuringTimeOut,
}

impl<I2C> core::fmt::Debug for BmeError<I2C>
where
    I2C: I2c<SevenBitAddress>
{
    fn fmt(&self, f: &mut Formatter<'_>) -> core::result::Result<(), core::fmt::Error> {
        match self {
            BmeError::WriteReadError(e) => f.debug_tuple("WriteReadError").field(e).finish(),
            BmeError::WriteError(e) => f.debug_tuple("WriteError").field(e).finish(),
            BmeError::UnexpectedChipId(chip_id) => f
                .debug_tuple("Got unimplemented chip id: ")
                .field(chip_id)
                .finish(),
            BmeError::MeasuringTimeOut => f
                .debug_tuple("Timed out while waiting for new measurement values. Either no new data or the sensor took unexpectedly long to finish measuring.").finish()
        }
    }
}