use embedded_hal::digital::StatefulOutputPin;
pub(crate) struct OutputController<P: StatefulOutputPin> {
pin: P,
low_active: bool,
}
impl<P: StatefulOutputPin> OutputController<P> {
pub fn new(pin: P, low_active: bool) -> Self {
Self { pin, low_active }
}
pub fn activate(&mut self) {
if self.low_active {
self.pin.set_low().ok();
} else {
self.pin.set_high().ok();
}
}
pub fn deactivate(&mut self) {
if self.low_active {
self.pin.set_high().ok();
} else {
self.pin.set_low().ok();
}
}
pub fn toggle(&mut self) {
self.pin.toggle().ok();
}
pub fn is_active(&mut self) -> Result<bool, P::Error> {
if self.low_active {
self.pin.is_set_low()
} else {
self.pin.is_set_high()
}
}
}