use core::convert::Infallible;
use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct LastStateDummyPin {
is_high: bool,
}
impl LastStateDummyPin {
pub fn new(is_high: bool) -> Self {
LastStateDummyPin { is_high }
}
pub fn new_low() -> Self {
LastStateDummyPin { is_high: false }
}
pub fn new_high() -> Self {
LastStateDummyPin { is_high: true }
}
}
impl ErrorType for LastStateDummyPin {
type Error = Infallible;
}
impl OutputPin for LastStateDummyPin {
fn set_high(&mut self) -> Result<(), Self::Error> {
self.is_high = true;
Ok(())
}
fn set_low(&mut self) -> Result<(), Self::Error> {
self.is_high = false;
Ok(())
}
}
impl InputPin for LastStateDummyPin {
fn is_high(&mut self) -> Result<bool, Self::Error> {
Ok(self.is_high)
}
fn is_low(&mut self) -> Result<bool, Self::Error> {
Ok(!self.is_high)
}
}
impl StatefulOutputPin for LastStateDummyPin {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok(self.is_high)
}
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok(!self.is_high)
}
}