1
0
Fork 0

Added dead man handle, added logger, bump crate versions

This commit is contained in:
Alexander Böhm 2024-01-02 02:34:06 +01:00
parent 29b2014c80
commit 251e167922
3 changed files with 637 additions and 567 deletions

1178
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,8 @@ edition = "2021"
[dependencies]
dotenv = "0.15.0"
env_logger = "0.10.1"
futures = "0.3.28"
log = "0.4.20"
rppal = "0.14.1"
spaceapi-dezentrale-client = { git = "https://github.com/dezentrale/spaceapi-rs.git", package = "spaceapi-dezentrale-client", branch = "main" }

View File

@ -29,28 +29,27 @@ fn main() {
loop {
// maybe not the best solution but the pi isn't doing anything else
println!("Waiting {} secs to read the door status", RECHECK_DELAY);
log::debug!("Waiting {} secs to read the door status", RECHECK_DELAY);
sleep(Duration::from_secs(RECHECK_DELAY));
// read new status
let door_status_new = check_door(&pin);
println!("Read {}", door_status_new);
log::debug!("Read {}", door_status_new);
// if the new status isn't the old one
if door_status_old != door_status_new {
// wait for the switch to stop bouncing around
println!("Waiting {} secs for recheck", ANTI_BOUNCE_DELAY);
log::debug!("Waiting {} secs for recheck", ANTI_BOUNCE_DELAY);
sleep(Duration::from_secs(ANTI_BOUNCE_DELAY));
// the new read status is still the same after a minute then push it to the api
if door_status_new == check_door(&pin)
{
println!("Check passed, applying new status");
println!("Pushing space status: Open = {}", door_status_new);
if door_status_new == check_door(&pin) {
log::debug!("Check passed, applying new status");
log::debug!("Pushing space status: Open = {}", door_status_new);
block_on(push_door_status(&spaceapi_client, door_status_new));
println!("Saving space status: {}", door_status_new);
log::debug!("Saving space status: {}", door_status_new);
door_status_old = door_status_new;
} else {
println!("Check wasn't successfully")
log::debug!("Check wasn't successful")
}
}
}
@ -62,5 +61,10 @@ fn check_door(pin: &InputPin) -> bool {
}
async fn push_door_status(spaceapi: &Client, open: bool) {
if open { spaceapi.open().await.unwrap() } else { spaceapi.close().await.unwrap() }
if open {
let _ = spaceapi
.keep_open()
.await
.map_err(|err| log::error!("SpaceAPI call failed: {err}"));
}
}