afe4404/led_current/
configuration.rs

1use uom::si::{electric_current::milliampere, f32::ElectricCurrent};
2
3use crate::modes::{LedMode, ThreeLedsMode, TwoLedsMode};
4
5/// Represents the currents of the LEDs.
6#[derive(Clone, Copy, Debug)]
7pub struct LedCurrentConfiguration<MODE: LedMode> {
8    led1: ElectricCurrent,
9    led2: ElectricCurrent,
10    led3: ElectricCurrent,
11    mode: core::marker::PhantomData<MODE>,
12}
13
14impl<MODE> LedCurrentConfiguration<MODE>
15where
16    MODE: LedMode,
17{
18    /// Gets an immutable reference of the current of LED1.
19    pub fn led1(&self) -> &ElectricCurrent {
20        &self.led1
21    }
22
23    /// Gets an immutable reference of the current of LED2.
24    pub fn led2(&self) -> &ElectricCurrent {
25        &self.led2
26    }
27
28    /// Gets a mutable reference of the current of LED1.
29    pub fn led1_mut(&mut self) -> &mut ElectricCurrent {
30        &mut self.led1
31    }
32
33    /// Gets a mutable reference of the current of LED2.
34    pub fn led2_mut(&mut self) -> &mut ElectricCurrent {
35        &mut self.led2
36    }
37}
38
39impl LedCurrentConfiguration<ThreeLedsMode> {
40    /// Creates a new `LedCurrentConfiguration`.
41    pub fn new(led1: ElectricCurrent, led2: ElectricCurrent, led3: ElectricCurrent) -> Self {
42        Self {
43            led1,
44            led2,
45            led3,
46            mode: core::marker::PhantomData,
47        }
48    }
49
50    /// Gets an immutable reference of the current of LED3.
51    pub fn led3(&self) -> &ElectricCurrent {
52        &self.led3
53    }
54
55    /// Gets a mutable reference of the current of LED3.
56    pub fn led3_mut(&mut self) -> &mut ElectricCurrent {
57        &mut self.led3
58    }
59}
60
61impl LedCurrentConfiguration<TwoLedsMode> {
62    /// Creates a new `LedCurrentConfiguration`.
63    pub fn new(led1: ElectricCurrent, led2: ElectricCurrent) -> Self {
64        Self {
65            led1,
66            led2,
67            led3: ElectricCurrent::new::<milliampere>(0.0),
68            mode: core::marker::PhantomData,
69        }
70    }
71}
72
73/// Represents the offset currents of the LEDs.
74#[derive(Clone, Copy, Debug)]
75pub struct OffsetCurrentConfiguration<MODE: LedMode> {
76    led1: ElectricCurrent,
77    led2: ElectricCurrent,
78    ambient1: ElectricCurrent,
79    ambient2_or_led3: ElectricCurrent,
80    mode: core::marker::PhantomData<MODE>,
81}
82
83impl<MODE> OffsetCurrentConfiguration<MODE>
84where
85    MODE: LedMode,
86{
87    /// Gets an immutable reference of the offset current of LED1.
88    pub fn led1(&self) -> &ElectricCurrent {
89        &self.led1
90    }
91
92    /// Gets an immutable reference of the offset current of LED2.
93    pub fn led2(&self) -> &ElectricCurrent {
94        &self.led2
95    }
96
97    /// Gets a mutable reference of the offset current of LED1.
98    pub fn led1_mut(&mut self) -> &mut ElectricCurrent {
99        &mut self.led1
100    }
101
102    /// Gets a mutable reference of the offset current of LED2.
103    pub fn led2_mut(&mut self) -> &mut ElectricCurrent {
104        &mut self.led2
105    }
106}
107
108impl OffsetCurrentConfiguration<ThreeLedsMode> {
109    /// Creates a new `OffsetCurrentConfiguration` for the three LEDs mode.
110    pub fn new(
111        led1: ElectricCurrent,
112        led2: ElectricCurrent,
113        led3: ElectricCurrent,
114        ambient: ElectricCurrent,
115    ) -> Self {
116        Self {
117            led1,
118            led2,
119            ambient1: ambient,
120            ambient2_or_led3: led3,
121            mode: core::marker::PhantomData,
122        }
123    }
124
125    /// Gets an immutable reference of the offset current of LED3.
126    pub fn led3(&self) -> &ElectricCurrent {
127        &self.ambient2_or_led3
128    }
129
130    /// Gets an immutable reference of the ambient offset current.
131    pub fn ambient(&self) -> &ElectricCurrent {
132        &self.ambient1
133    }
134
135    /// Gets a mutable reference of the offset current of LED3.
136    pub fn led3_mut(&mut self) -> &mut ElectricCurrent {
137        &mut self.ambient2_or_led3
138    }
139
140    /// Gets a mutable reference of the ambient offset current.
141    pub fn ambient_mut(&mut self) -> &mut ElectricCurrent {
142        &mut self.ambient1
143    }
144}
145
146impl OffsetCurrentConfiguration<TwoLedsMode> {
147    /// Creates a new `OffsetCurrentConfiguration` for the two LEDs mode.
148    pub fn new(
149        led1: ElectricCurrent,
150        led2: ElectricCurrent,
151        ambient1: ElectricCurrent,
152        ambient2: ElectricCurrent,
153    ) -> Self {
154        Self {
155            led1,
156            led2,
157            ambient1,
158            ambient2_or_led3: ambient2,
159            mode: core::marker::PhantomData,
160        }
161    }
162
163    /// Gets an immutable reference of the ambient1 offset current.
164    pub fn ambient1(&self) -> &ElectricCurrent {
165        &self.ambient1
166    }
167
168    /// Gets an immutable reference of the ambient2 offset current.
169    pub fn ambient2(&self) -> &ElectricCurrent {
170        &self.ambient2_or_led3
171    }
172
173    /// Gets a mutable reference of the ambient1 offset current.
174    pub fn ambient1_mut(&mut self) -> &mut ElectricCurrent {
175        &mut self.ambient1
176    }
177
178    /// Gets a mutable reference of the ambient2 offset current.
179    pub fn ambient2_mut(&mut self) -> &mut ElectricCurrent {
180        &mut self.ambient2_or_led3
181    }
182}