aquarium_control/sensors/
i2c_interface_channels.rs1#[cfg(any(test, all(target_os = "linux", feature = "target_hw")))]
10use crate::launch::channels::AquaChannelError;
11
12use crate::launch::channels::{AquaReceiver, AquaSender};
13use crate::sensors::i2c_interface::{I2cRequest, I2cResult};
14use crate::utilities::channel_content::InternalCommand;
15use std::fmt;
16
17pub struct I2cInterfaceChannels {
19 #[allow(unused)] pub tx_i2c_interface_to_atlas_scientific: AquaSender<I2cResult>,
21
22 #[allow(unused)] pub rx_i2c_interface_from_atlas_scientific: AquaReceiver<I2cRequest>,
24
25 #[allow(unused)] pub rx_i2c_interface_from_signal_handler: AquaReceiver<InternalCommand>,
27}
28
29impl I2cInterfaceChannels {
30 #[cfg(any(test, all(target_os = "linux", feature = "target_hw")))]
31 pub fn send_to_atlas_scientific(&mut self, result: I2cResult) -> Result<(), AquaChannelError> {
33 self.tx_i2c_interface_to_atlas_scientific.send(result)
34 }
35
36 #[cfg(all(target_os = "linux", feature = "target_hw"))]
37 pub fn receive_from_atlas_scientific(&mut self) -> Result<I2cRequest, AquaChannelError> {
39 self.rx_i2c_interface_from_atlas_scientific.try_recv()
40 }
41}
42
43#[cfg(feature = "debug_channels")]
44impl fmt::Display for I2cInterfaceChannels {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 writeln!(f, "=== I2cInterfaceChannels ===")?;
47 writeln!(
48 f,
49 "tx_i2c_interface_to_atlas_scientific: {}",
50 self.tx_i2c_interface_to_atlas_scientific.count
51 )?;
52 writeln!(
53 f,
54 "rx_i2c_interface_from_atlas_scientific: {}",
55 self.rx_i2c_interface_from_atlas_scientific.count
56 )?;
57 write!(
58 f,
59 "rx_i2c_interface_from_signal_handler: {}",
60 self.rx_i2c_interface_from_signal_handler.count
61 )
62 }
63}
64
65#[cfg(not(feature = "debug_channels"))]
66impl fmt::Display for I2cInterfaceChannels {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 write!(
69 f,
70 "Channel counters are not active. Use --features \"debug_channels\" to enable them."
71 )
72 }
73}