ft_hal_generic/ft_output.rs
1/// The PWM intensity percentage for the high voltage level (Vcc).
2const HIGH_INTENSITY: u8 = 100;
3/// The PWM intensity percentage for the low voltage level (GND).
4const LOW_INTENSITY: u8 = 0;
5
6pub enum FtOutputCommand {
7 /// Turn the output on with a specific PWM intensity (in percent).
8 On(u8),
9 /// Turn the output off by opening the circuit.
10 Off,
11 /// Connect the output to the high voltage level (Vcc). This is equivalent to `On(HIGH_INTENSITY)`.
12 High,
13 /// Connect the output to the low voltage level (GND).
14 ///
15 /// Note: This is different from `Off`, where the circuit is open.
16 Low,
17}
18
19pub trait FtOutput<E> {
20 fn turn_on(&mut self, intensity: u8) -> Result<(), E>;
21
22 fn turn_off(&mut self) -> Result<(), E>;
23
24 fn set_output(&mut self, cmd: FtOutputCommand) -> Result<(), E> {
25 match cmd {
26 FtOutputCommand::On(intensity) => self.turn_on(intensity),
27 FtOutputCommand::Off => self.turn_off(),
28 FtOutputCommand::High => self.turn_on(HIGH_INTENSITY),
29 FtOutputCommand::Low => self.turn_on(LOW_INTENSITY),
30 }
31 }
32}