1use embedded_hal::digital::v2::{OutputPin, StatefulOutputPin, ToggleableOutputPin};
2
3use crate::{ActiveHigh, ActiveLow, OutputSwitch, Switch, StatefulOutputSwitch, ToggleableOutputSwitch};
4
5impl<T: OutputPin> OutputSwitch for Switch<T, ActiveHigh> {
6 type Error = <T as OutputPin>::Error;
7
8 fn on(&mut self) -> Result<(), Self::Error> {
9 self.pin.set_high()
10 }
11
12 fn off(&mut self) -> Result<(), Self::Error> {
13 self.pin.set_low()
14 }
15}
16
17impl<T: OutputPin> OutputSwitch for Switch<T, ActiveLow> {
18 type Error = <T as OutputPin>::Error;
19
20 fn on(&mut self) -> Result<(), Self::Error> {
21 self.pin.set_low()
22 }
23
24 fn off(&mut self) -> Result<(), Self::Error> {
25 self.pin.set_high()
26 }
27}
28
29impl<T: OutputPin + ToggleableOutputPin, ActiveLevel> ToggleableOutputSwitch
30 for Switch<T, ActiveLevel>
31{
32 type Error = <T as ToggleableOutputPin>::Error;
33
34 fn toggle(&mut self) -> Result<(), Self::Error> {
35 self.pin.toggle()
36 }
37}
38
39impl<T: OutputPin + StatefulOutputPin> StatefulOutputSwitch
40 for Switch<T, ActiveLow>
41{
42 type Error = <T as OutputPin>::Error;
43
44 fn is_on(&mut self) -> Result<bool, Self::Error> {
45 self.pin.is_set_low()
46 }
47
48 fn is_off(&mut self) -> Result<bool, Self::Error> {
49 self.pin.is_set_high()
50 }
51}
52
53impl<T: OutputPin + StatefulOutputPin> StatefulOutputSwitch
54 for Switch<T, ActiveHigh>
55{
56 type Error = <T as OutputPin>::Error;
57
58 fn is_on(&mut self) -> Result<bool, Self::Error> {
59 self.pin.is_set_high()
60 }
61
62 fn is_off(&mut self) -> Result<bool, Self::Error> {
63 self.pin.is_set_low()
64 }
65}