From 771f81a9f674eda64e3b74f70eb128a404b5ce39 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao Date: Thu, 2 May 2024 20:35:00 +0200 Subject: [PATCH] wip --- growpi.toml | 6 ++++ html/growpi/src/App.vue | 77 ++++++++++++++++++++++++++++++++++------- html/growpi/src/main.js | 7 ++-- src/config.rs | 15 ++++++++ src/control.rs | 25 ++++++++++--- 5 files changed, 111 insertions(+), 19 deletions(-) diff --git a/growpi.toml b/growpi.toml index 676be69..e16cc05 100644 --- a/growpi.toml +++ b/growpi.toml @@ -28,3 +28,9 @@ resistor = "R2" [water_pump_settings] grams_per_millisecond = 0.05280999839305878 + +[controller_settings] +temperature_set_point_upper = 35.0 +temperature_set_point_lower = 28.0 +temperature_loop_mins = 60 +soil_loop_hours = 12 diff --git a/html/growpi/src/App.vue b/html/growpi/src/App.vue index e9a0e84..b784a9e 100644 --- a/html/growpi/src/App.vue +++ b/html/growpi/src/App.vue @@ -1,5 +1,6 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/html/growpi/src/main.js b/html/growpi/src/main.js index 5315290..66ddca2 100644 --- a/html/growpi/src/main.js +++ b/html/growpi/src/main.js @@ -1,9 +1,10 @@ -import 'primevue/resources/themes/aura-light-green/theme.css' +import 'primevue/resources/themes/aura-dark-green/theme.css' import { createApp } from 'vue' import PrimeVue from 'primevue/config' import App from './App.vue' -createApp(App).mount('#app') -App.use(PrimeVue) +const app = createApp(App) +app.use(PrimeVue) +app.mount('#app') diff --git a/src/config.rs b/src/config.rs index ad2a9ea..9cb0ef1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -44,6 +44,14 @@ pub struct BoardSettings { pub logic_level: f32, } +#[derive(Serialize, Deserialize)] +pub struct ControllerSettings { + pub temperature_set_point_upper: f32, + pub temperature_set_point_lower: f32, + pub temperature_loop_mins: u64, + pub soil_loop_hours: u64, +} + #[derive(Serialize, Deserialize)] pub struct Configuration { pub board_settings: BoardSettings, @@ -51,6 +59,7 @@ pub struct Configuration { pub soil_moisture_settings: SoilMoistureSettings, pub thermistor_settings: ThermistorSettings, pub water_pump_settings: WaterPumpSettings, + pub controller_settings: ControllerSettings, } impl Configuration { @@ -93,6 +102,12 @@ impl Default for Configuration { water_pump_settings: WaterPumpSettings { grams_per_millisecond: 0.05281, }, + controller_settings: ControllerSettings { + temperature_set_point_upper: 35., + temperature_set_point_lower: 28., + temperature_loop_mins: 60, + soil_loop_hours: 12, + }, } } } diff --git a/src/control.rs b/src/control.rs index 1143936..196dcb8 100644 --- a/src/control.rs +++ b/src/control.rs @@ -12,24 +12,41 @@ use crate::{ async fn temperature_control(program_state: ProgramStateShared) -> GenericResult<()> { let mut program_state = program_state.lock().map_err(lock_err)?; + let config = &program_state.config.controller_settings; + let current_temperature = sensors::get_temperature(&program_state.config)?; - if current_temperature > 28. { + if current_temperature > config.temperature_set_point_upper { actuators::switch_fan(crate::io::RelaySwitchState::On, &mut program_state)?; - } else { + } else if current_temperature < config.temperature_set_point_lower { actuators::switch_fan(crate::io::RelaySwitchState::Off, &mut program_state)?; } Ok(()) } async fn temperature_control_loop(program_state: ProgramStateShared) { + let loop_duration = program_state + .lock() + .map(|program_state| { + program_state + .config + .controller_settings + .temperature_loop_mins + }) + .unwrap_or(1); + loop { let _ = temperature_control(program_state.clone()).await; - tokio::time::sleep(Duration::from_mins(1)).await; + tokio::time::sleep(Duration::from_mins(loop_duration)).await; } } async fn soil_moisture_control_loop(program_state: ProgramStateShared) { + let loop_duration = program_state + .lock() + .map(|program_state| program_state.config.controller_settings.soil_loop_hours) + .unwrap_or(1); + loop { - tokio::time::sleep(Duration::from_days(1)).await; + tokio::time::sleep(Duration::from_hours(loop_duration)).await; } }