Add relay pulse functionality

This commit is contained in:
Tobias Reisinger 2024-04-26 16:15:24 +02:00
parent e2f3d7b82a
commit 61a3c6093b
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
14 changed files with 201 additions and 13 deletions
emgauwa-controller/src

View file

@ -13,6 +13,7 @@ pub struct Relay {
pub number: Option<i64>,
pub pin: u8,
pub inverted: bool,
pub pulse: Option<u64>,
}
#[derive(Clone, Debug, Deserialize)]
@ -50,6 +51,7 @@ impl Default for Relay {
name: String::from("Relay"),
pin: 0,
inverted: false,
pulse: None,
}
}
}
@ -65,3 +67,9 @@ pub fn init() -> Result<Settings, EmgauwaError> {
Ok(settings)
}
impl Settings {
pub fn get_relay(&self, number: i64) -> Option<&Relay> {
self.relays.iter().find(|r| r.number == Some(number))
}
}