diff --git a/rust/src/plant_state.rs b/rust/src/plant_state.rs index b7c9750..6bae845 100644 --- a/rust/src/plant_state.rs +++ b/rust/src/plant_state.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{config::PlantConfig, in_time_range, plant_hal}; -const MOIST_SENSOR_MAX_FREQUENCY: f32 = 6500.; // 60kHz (500Hz margin) +const MOIST_SENSOR_MAX_FREQUENCY: f32 = 7500.; // 60kHz (500Hz margin) const MOIST_SENSOR_MIN_FREQUENCY: f32 = 150.; // this is really, really dry, think like cactus levels #[derive(Debug, PartialEq, Serialize)] diff --git a/rust/src/webserver/webserver.rs b/rust/src/webserver/webserver.rs index 195b184..39dcce0 100644 --- a/rust/src/webserver/webserver.rs +++ b/rust/src/webserver/webserver.rs @@ -21,6 +21,7 @@ use std::{ use url::Url; use crate::config::PlantControllerConfig; +use crate::plant_state::MoistureSensorState; #[derive(Serialize, Debug)] struct SSIDList<'a> { @@ -35,8 +36,8 @@ struct LoadData<'a> { #[derive(Serialize, Debug)] struct Moistures { - moisture_a: Vec>, - moisture_b: Vec>, + moisture_a: Vec, + moisture_b: Vec, } #[derive(Deserialize, Debug)] @@ -122,12 +123,28 @@ fn get_live_moisture( let a = Vec::from_iter( plant_state .iter() - .map(|s| s.sensor_a.moisture_percent().map(|f| f.to_precision(2))), + .map(|s| { + match &s.sensor_a { + MoistureSensorState::Disabled => "disabled".to_string(), + MoistureSensorState::MoistureValue {raw_hz, moisture_percent } => { + format!("{moisture_percent:.2}% {raw_hz}hz",) + } + MoistureSensorState::SensorError(err) => format!("{err:?}"), + } + }) ); let b = Vec::from_iter( plant_state .iter() - .map(|s| s.sensor_b.moisture_percent().map(|f| f.to_precision(2))), + .map(|s| { + match &s.sensor_b { + MoistureSensorState::Disabled => "disabled".to_string(), + MoistureSensorState::MoistureValue {raw_hz, moisture_percent } => { + format!("{moisture_percent:.2}% {raw_hz}hz",) + } + MoistureSensorState::SensorError(err) => format!("{err:?}"), + } + }) ); let data = Moistures { diff --git a/rust/src_webpack/src/api.ts b/rust/src_webpack/src/api.ts index 4e67279..531be75 100644 --- a/rust/src_webpack/src/api.ts +++ b/rust/src_webpack/src/api.ts @@ -106,8 +106,8 @@ interface GetTime { } interface Moistures { - moisture_a: [number], - moisture_b: [number], + moisture_a: [string], + moisture_b: [string], } interface VersionInfo { diff --git a/rust/src_webpack/src/plant.ts b/rust/src_webpack/src/plant.ts index e042bf5..d71cf89 100644 --- a/rust/src_webpack/src/plant.ts +++ b/rust/src_webpack/src/plant.ts @@ -24,7 +24,7 @@ export class PlantViews { } return rv } - update(moisture_a: [number], moisture_b: [number]) { + update(moisture_a: [string], moisture_b: [string]) { for (let plantId = 0; plantId < PLANT_COUNT; plantId++) { const a = moisture_a[plantId] const b = moisture_b[plantId] @@ -150,18 +150,9 @@ export class PlantView { }; } - update(a: number, b: number) { - if (a == 200){ - this.moistureA.innerText = "error" - } else { - this.moistureA.innerText = String(a) - } - - if (b == 200){ - this.moistureB.innerText = "error" - } else { - this.moistureB.innerText = String(b) - } + update(a: string, b: string) { + this.moistureA.innerText = a + this.moistureB.innerText = b } setConfig(plantConfig: PlantConfig) {