From 3ebf62341f0783f586e3f68f1c726941fd4f7371 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Fri, 2 Sep 2022 21:08:03 -0400 Subject: [PATCH] Fix some state bugs which caused fan pulsing --- backend/Cargo.lock | 2 +- backend/src/control.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 06fdeac..055301a 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -106,7 +106,7 @@ dependencies = [ [[package]] name = "fantastic-rs" -version = "0.3.1" +version = "0.3.3" dependencies = [ "log", "serde", diff --git a/backend/src/control.rs b/backend/src/control.rs index 7cfda0c..a269784 100644 --- a/backend/src/control.rs +++ b/backend/src/control.rs @@ -56,7 +56,9 @@ impl ControlRuntime { continue; } }; - Self::on_set_enable(&settings, &state); + if settings.enable { + Self::on_set_enable(&settings, &state); + } } } start_time = Instant::now(); @@ -82,6 +84,15 @@ impl ControlRuntime { log::error!("SettingsJson.save({}) error: {}", settings_path(&state.home).display(), e); } Self::on_set_enable(&settings, &state); + drop(state); + let mut state = match runtime_state.write() { + Ok(x) => x, + Err(e) => { + log::error!("runtime failed to acquire state write lock: {}", e); + continue; + } + }; + state.dirty = false; } } { // fan control @@ -200,6 +211,7 @@ impl ControlRuntime { else: return 0.5 */ + // step fan, what are you doing? if let Some(index) = index { settings.curve[index].y } else {