Add null driver

This commit is contained in:
Tobias Reisinger 2024-04-28 01:38:57 +02:00
parent 4ed1cd3182
commit 07d3322c5a
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
7 changed files with 58 additions and 28 deletions
emgauwa-lib/src/drivers

View file

@ -1,8 +1,10 @@
mod gpio;
mod null;
mod piface;
pub use gpio::GpioDriver;
pub use piface::PifaceDriver;
pub use null::NullDriver;
pub use piface::PiFaceDriver;
use crate::errors::EmgauwaError;

View file

@ -0,0 +1,26 @@
use crate::drivers::RelayDriver;
use crate::errors::EmgauwaError;
pub struct NullDriver {
pub pin: u8,
}
impl NullDriver {
pub fn new(pin: u8) -> Self {
Self { pin }
}
}
impl RelayDriver for NullDriver {
fn set(&mut self, _value: bool) -> Result<(), EmgauwaError> {
Ok(())
}
fn get_pin(&self) -> u8 {
self.pin
}
fn get_inverted(&self) -> bool {
false
}
}

View file

@ -5,11 +5,11 @@ use rppal_pfd::{
use crate::drivers::RelayDriver;
use crate::errors::EmgauwaError;
pub struct PifaceDriver {
pub struct PiFaceDriver {
pub pfd_pin: OutputPin,
}
impl PifaceDriver {
impl PiFaceDriver {
pub fn new(pin: u8, pfd: &Option<PiFaceDigital>) -> Result<Self, EmgauwaError> {
let pfd = pfd.as_ref().ok_or(EmgauwaError::Hardware(String::from(
"PiFaceDigital not initialized",
@ -32,7 +32,7 @@ impl PifaceDriver {
}
}
impl RelayDriver for PifaceDriver {
impl RelayDriver for PiFaceDriver {
fn set(&mut self, value: bool) -> Result<(), EmgauwaError> {
if self.get_high(value) {
self.pfd_pin.set_high().map_err(PiFaceDigitalError::from)?;