Add drivers for gpio and piface

This commit is contained in:
Tobias Reisinger 2024-04-28 01:13:22 +02:00
parent 61a3c6093b
commit 4ed1cd3182
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
14 changed files with 259 additions and 17 deletions
emgauwa-lib/src/drivers

View file

@ -0,0 +1,35 @@
use rppal::gpio::{Gpio, OutputPin};
use crate::drivers::RelayDriver;
use crate::errors::EmgauwaError;
pub struct GpioDriver {
pub gpio: OutputPin,
pub inverted: bool,
}
impl GpioDriver {
pub fn new(pin: u8, inverted: bool) -> Result<Self, EmgauwaError> {
let gpio = Gpio::new()?.get(pin)?.into_output();
Ok(Self { gpio, inverted })
}
}
impl RelayDriver for GpioDriver {
fn set(&mut self, value: bool) -> Result<(), EmgauwaError> {
if self.get_high(value) {
self.gpio.set_high();
} else {
self.gpio.set_low();
}
Ok(())
}
fn get_pin(&self) -> u8 {
self.gpio.pin()
}
fn get_inverted(&self) -> bool {
self.inverted
}
}