aquarium_control/sensors/
i2c_error.rs1use thiserror::Error;
10
11#[derive(Error, Debug)]
13pub enum I2cError {
14 #[cfg(all(target_os = "linux", feature = "target_hw"))]
16 #[error("[{location}] Initialization of I2C interface failed.")]
17 InitializationFailure {
18 location: String,
19
20 #[source]
21 source: rppal::i2c::Error,
22 },
23
24 #[cfg(all(target_os = "linux", feature = "target_hw"))]
26 #[error("[{location}] Setting timeout for transactions failed.")]
27 SetTimeoutError {
28 location: String,
29
30 #[source]
31 source: rppal::i2c::Error,
32 },
33
34 #[cfg(all(target_os = "linux", feature = "target_hw"))]
36 #[error("[{location}] I2C write operation failed.")]
37 WriteFailure {
38 location: String,
39
40 #[source]
41 source: rppal::i2c::Error,
42 },
43
44 #[cfg(all(test, not(any(target_os = "linux", feature = "target_hw"))))]
46 #[error("[{0}] I2C write operation failed.")]
47 WriteFailure(String),
48
49 #[cfg(all(test, not(feature = "target_hw"), target_os = "linux"))]
51 #[error("[{0}] I2C write operation failed.")]
52 WriteFailure(String),
53
54 #[cfg(all(target_os = "linux", feature = "target_hw"))]
56 #[error("[{0}] I2C write operation was incomplete: Target={1}, Realized={2}")]
57 InsufficientWrite(String, usize, usize),
58
59 #[cfg(all(target_os = "linux", feature = "target_hw"))]
61 #[error("[{location}] I2C read operation was incomplete")]
62 InsufficientRead {
63 location: String,
64
65 #[source]
66 source: rppal::i2c::Error,
67 },
68
69 #[cfg(all(target_os = "linux", feature = "target_hw"))]
71 #[error("[{location}] Failed to set I2C slave address to {address}")]
72 SetAddressError {
73 location: String,
74 address: u16,
75
76 #[source]
77 source: rppal::i2c::Error,
78 },
79
80 #[cfg(all(target_os = "linux", feature = "target_hw"))]
82 #[error("[{0}] I2C response has incorrect length: Expected: {1} Received: {2}")]
83 IncorrectResponseLength(String, usize, usize),
84
85 #[allow(unused)] #[error("[{location}]: I2C command (length: {actual_len}) exceeds the maximum allowed length ({max_len}).")]
88 CommandTooLong {
89 location: String,
90 max_len: usize,
91 actual_len: usize,
92 },
93
94 #[cfg(all(target_os = "linux", feature = "target_hw"))]
96 #[error("[{location}]: Provided buffer (size: {buffer_size}) is too small for the expected response (size: {expected_size}).")]
97 ProvidedBufferTooSmall {
98 location: String,
99 buffer_size: usize,
100 expected_size: usize,
101 },
102}