si7021_t_rh/error.rs
1// use core::fmt::Formatter;
2
3// use embedded_hal::i2c::{I2c, SevenBitAddress};
4// use embedded_hal::i2c::{Error as I2cError, ErrorKind as I2cErrorKind};
5
6/// All possible errors
7/// Display not implemented for no_std support
8#[derive(Clone, Copy, Debug)]
9pub enum Error<E> {
10 NotConnected,
11 /// parameter out of range
12 OutOfRange(u8),
13 /// measurement timeout
14 MeasurementTimeout(),
15 /// An error in the underlying I²C system
16 I2c(E),
17}
18
19// impl<E> From<E> for Error<E>
20// where
21// E: I2cError,
22// {
23// fn from(error: E) -> Self {
24// Self::I2c(error.kind())
25// }
26// }
27
28
29/****
30pub enum Si7021Error<I2C>
31where
32 I2C: I2c<SevenBitAddress>
33{
34 /// Error during I2C write operation.
35 WriteError(I2C::Error),
36 /// Error during I2C WriteRead operation.
37 WriteReadError(I2C::Error),
38 /// Got an unexpected Part Id during sensor initalization.
39 UnexpectedChipId(u8),
40
41 /// sths34pf80 device not connected to I2C bus
42 NotConnected,
43 /// parameter out of range
44 OutOfRange(u8),
45 /// measurement timeout
46 MeasurementTimeout(),
47}
48
49impl<I2C> core::fmt::Debug for Si7021Error<I2C>
50where
51 I2C: I2c<SevenBitAddress>
52{
53 fn fmt(&self, f: &mut Formatter<'_>) -> core::result::Result<(), core::fmt::Error> {
54 match self {
55 Si7021Error::WriteReadError(e) => f.debug_tuple("WriteReadError").field(e).finish(),
56 Si7021Error::WriteError(e) => f.debug_tuple("WriteError").field(e).finish(),
57 Si7021Error::UnexpectedChipId(chip_id) => f
58 .debug_tuple("Expected part id 0xd3, got : ") // ToDo: fix this one
59 .field(chip_id)
60 .finish(),
61 Si7021Error::NotConnected => f
62 .debug_tuple("Si7021 series device is not connected to microcontroller")
63 .finish(),
64
65 Si7021Error::OutOfRange(value) => f
66 .debug_tuple("Set value out of range, check Si7021 datasheet")
67 .field(value)
68 .finish(),
69 Si7021Error::MeasurementTimeout() => f
70 .debug_tuple("timeout waiting for new measurement data ready")
71 .finish(),
72 }
73 }
74}
75
76
77*************/