Format code a bit
This commit is contained in:
parent
c524d089ad
commit
bf3192ec65
7 changed files with 31 additions and 23 deletions
BIN
Cargo.lock
generated
BIN
Cargo.lock
generated
Binary file not shown.
|
@ -2,6 +2,7 @@ pub use gpio::GpioDriver;
|
|||
pub use null::NullDriver;
|
||||
pub use piface::PiFaceDriver;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::errors::EmgauwaControllerError;
|
||||
|
||||
mod gpio;
|
||||
|
|
|
@ -11,7 +11,9 @@ pub struct PiFaceDriver {
|
|||
|
||||
impl PiFaceDriver {
|
||||
pub fn new(pin: u8, pfd: &Option<PiFaceDigital>) -> Result<Self, EmgauwaControllerError> {
|
||||
let pfd = pfd.as_ref().ok_or(EmgauwaControllerError::Hardware(String::from(
|
||||
let pfd = pfd
|
||||
.as_ref()
|
||||
.ok_or(EmgauwaControllerError::Hardware(String::from(
|
||||
"PiFaceDigital not initialized",
|
||||
)))?;
|
||||
let pfd_pin = pfd.get_output_pin(pin)?;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use emgauwa_common::errors::EmgauwaError;
|
||||
use rppal::gpio;
|
||||
use rppal_mcp23s17::Mcp23s17Error;
|
||||
use rppal_pfd::PiFaceDigitalError;
|
||||
|
||||
use emgauwa_common::errors::EmgauwaError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EmgauwaControllerError {
|
||||
Hardware(String),
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -15,11 +15,11 @@ use crate::ws::run_ws_loop;
|
|||
|
||||
mod app_state;
|
||||
mod drivers;
|
||||
mod errors;
|
||||
mod relay_loop;
|
||||
mod settings;
|
||||
mod utils;
|
||||
mod ws;
|
||||
mod errors;
|
||||
|
||||
async fn create_this_controller(
|
||||
conn: &mut PoolConnection<Sqlite>,
|
||||
|
@ -80,11 +80,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
};
|
||||
|
||||
for relay in &settings.relays {
|
||||
if DbRelay::get_by_controller_and_num(
|
||||
&mut conn,
|
||||
&db_controller,
|
||||
relay.number,
|
||||
)
|
||||
if DbRelay::get_by_controller_and_num(&mut conn, &db_controller, relay.number)
|
||||
.await
|
||||
.map_err(EmgauwaError::from)?
|
||||
.is_none()
|
||||
|
@ -103,7 +99,11 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
let this = Controller::from_db_model(&mut conn, db_controller).map_err(EmgauwaError::from)?;
|
||||
|
||||
let now = chrono::Local::now().time();
|
||||
let initial_states: Vec<bool> = this.relays.iter().map(|r| r.active_schedule.is_on(&now)).collect();
|
||||
let initial_states: Vec<bool> = this
|
||||
.relays
|
||||
.iter()
|
||||
.map(|r| r.active_schedule.is_on(&now))
|
||||
.collect();
|
||||
|
||||
let mut pfd: Option<PiFaceDigital> = None;
|
||||
let drivers = settings.relays_make_drivers(&mut pfd, initial_states)?;
|
||||
|
|
|
@ -2,6 +2,7 @@ use emgauwa_common::errors::EmgauwaError;
|
|||
use emgauwa_common::settings;
|
||||
use rppal_pfd::PiFaceDigital;
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
use crate::drivers;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
|
@ -71,7 +72,11 @@ impl Settings {
|
|||
initial_states: Vec<bool>,
|
||||
) -> Result<Vec<Box<dyn drivers::RelayDriver>>, EmgauwaError> {
|
||||
let mut drivers = Vec::new();
|
||||
let result: Result<(), EmgauwaError> = self.relays.iter().zip(initial_states).try_for_each(|(relay, state)| {
|
||||
let result: Result<(), EmgauwaError> =
|
||||
self.relays
|
||||
.iter()
|
||||
.zip(initial_states)
|
||||
.try_for_each(|(relay, state)| {
|
||||
let driver = relay.make_driver(pfd, state)?;
|
||||
drivers.push(driver);
|
||||
Ok(())
|
||||
|
|
|
@ -7,8 +7,8 @@ use emgauwa_common::types::ControllerWsAction;
|
|||
use futures::{future, pin_mut, SinkExt, StreamExt};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use tokio::time;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
use tokio_tungstenite::connect_async;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
|
||||
use crate::app_state::AppState;
|
||||
use crate::utils::{app_state_get_relay_notifier, app_state_get_this};
|
||||
|
|
Loading…
Reference in a new issue