Add drivers for gpio and piface
This commit is contained in:
parent
61a3c6093b
commit
4ed1cd3182
14 changed files with 259 additions and 17 deletions
emgauwa-lib/src/errors
|
@ -6,6 +6,9 @@ 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};
|
||||
|
||||
|
@ -21,6 +24,7 @@ pub enum EmgauwaError {
|
|||
Other(String),
|
||||
Internal(String),
|
||||
Connection(ControllerUid),
|
||||
Hardware(String),
|
||||
}
|
||||
|
||||
impl EmgauwaError {
|
||||
|
@ -33,6 +37,7 @@ impl EmgauwaError {
|
|||
EmgauwaError::Internal(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
EmgauwaError::Connection(_) => StatusCode::GATEWAY_TIMEOUT,
|
||||
EmgauwaError::Other(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
EmgauwaError::Hardware(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +52,7 @@ impl From<&EmgauwaError> for String {
|
|||
EmgauwaError::Internal(_) => String::from("internal error"),
|
||||
EmgauwaError::Connection(_) => String::from("the target controller is not connected"),
|
||||
EmgauwaError::Other(err) => format!("other error: {}", err),
|
||||
EmgauwaError::Hardware(err) => format!("hardware error: {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +99,25 @@ impl From<ConfigError> for EmgauwaError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<gpio::Error> for EmgauwaError {
|
||||
fn from(value: gpio::Error) -> Self {
|
||||
Self::Hardware(value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PiFaceDigitalError> 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue