diff --git a/Cargo.lock b/Cargo.lock index 97554c4..18d357b 100644 Binary files a/Cargo.lock and b/Cargo.lock differ diff --git a/Cargo.toml b/Cargo.toml index d8778b5..30ed02a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,8 +25,4 @@ sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio", "macros"] } libsqlite3-sys = { version = "*", features = ["bundled"] } uuid = { version = "1.8", features = ["v4"] } futures = "0.3" -libc = "0.2" - -rppal = "0.17" -rppal-pfd = "0.0.5" -rppal-mcp23s17 = "0.0.3" +libc = "0.2" \ No newline at end of file diff --git a/src/drivers/gpio.rs b/src/drivers/gpio.rs deleted file mode 100644 index 7847d43..0000000 --- a/src/drivers/gpio.rs +++ /dev/null @@ -1,35 +0,0 @@ -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 { - 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 - } -} diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs deleted file mode 100644 index abae75a..0000000 --- a/src/drivers/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod gpio; -mod null; -mod piface; - -pub use gpio::GpioDriver; -pub use null::NullDriver; -pub use piface::PiFaceDriver; - -use crate::errors::EmgauwaError; - -pub trait RelayDriver { - fn get_high(&self, value: bool) -> bool { - value ^ self.get_inverted() - } - - fn set(&mut self, value: bool) -> Result<(), EmgauwaError>; - fn get_pin(&self) -> u8; - fn get_inverted(&self) -> bool; -} diff --git a/src/drivers/null.rs b/src/drivers/null.rs deleted file mode 100644 index be4e8b9..0000000 --- a/src/drivers/null.rs +++ /dev/null @@ -1,26 +0,0 @@ -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 - } -} diff --git a/src/drivers/piface.rs b/src/drivers/piface.rs deleted file mode 100644 index 7bc20da..0000000 --- a/src/drivers/piface.rs +++ /dev/null @@ -1,52 +0,0 @@ -use rppal_pfd::{ - ChipSelect, HardwareAddress, OutputPin, PiFaceDigital, PiFaceDigitalError, SpiBus, SpiMode, -}; - -use crate::drivers::RelayDriver; -use crate::errors::EmgauwaError; - -pub struct PiFaceDriver { - pub pfd_pin: OutputPin, -} - -impl PiFaceDriver { - pub fn new(pin: u8, pfd: &Option) -> Result { - let pfd = pfd.as_ref().ok_or(EmgauwaError::Hardware(String::from( - "PiFaceDigital not initialized", - )))?; - let pfd_pin = pfd.get_output_pin(pin)?; - Ok(Self { pfd_pin }) - } - - pub fn init_piface() -> Result { - let mut pfd = PiFaceDigital::new( - HardwareAddress::new(0)?, - SpiBus::Spi0, - ChipSelect::Cs0, - 100_000, - SpiMode::Mode0, - )?; - pfd.init()?; - - Ok(pfd) - } -} - -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)?; - } else { - self.pfd_pin.set_low().map_err(PiFaceDigitalError::from)?; - } - Ok(()) - } - - fn get_pin(&self) -> u8 { - self.pfd_pin.get_pin_number() - } - - fn get_inverted(&self) -> bool { - false - } -} diff --git a/src/errors/emgauwa_error.rs b/src/errors/emgauwa_error.rs index ba7825a..bd7f04e 100644 --- a/src/errors/emgauwa_error.rs +++ b/src/errors/emgauwa_error.rs @@ -6,9 +6,6 @@ use actix::MailboxError; use actix_web::http::StatusCode; use actix_web::HttpResponse; use config::ConfigError; -use rppal::gpio; -use rppal_mcp23s17::Mcp23s17Error; -use rppal_pfd::PiFaceDigitalError; use serde::ser::SerializeStruct; use serde::{Serialize, Serializer}; @@ -99,25 +96,6 @@ impl From for EmgauwaError { } } -impl From for EmgauwaError { - fn from(value: gpio::Error) -> Self { - Self::Hardware(value.to_string()) - } -} - -impl From for EmgauwaError { - fn from(value: PiFaceDigitalError) -> Self { - match value { - PiFaceDigitalError::Mcp23s17Error { source } => match source { - Mcp23s17Error::SpiError { source } => Self::Hardware(source.to_string()), - _ => Self::Hardware(source.to_string()), - }, - PiFaceDigitalError::GpioError { source } => Self::Hardware(source.to_string()), - _ => Self::Hardware(value.to_string()), - } - } -} - impl From<&EmgauwaError> for HttpResponse { fn from(err: &EmgauwaError) -> Self { HttpResponse::build(err.get_code()).json(err) diff --git a/src/lib.rs b/src/lib.rs index 14609b9..f939d0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ pub mod constants; pub mod db; -pub mod drivers; pub mod errors; pub mod models; pub mod settings;