Refactor plant state handling and moisture interpretation
- Replaced `read_hardware_state` with `interpret_raw_values` for better abstraction and clarity. - Enhanced error handling by introducing `NoMessage` and `NotExpectedMessage` states. - Updated moisture sensor logic to differentiate expected and unexpected messages. - Renamed and refactored enum fields for consistency (`raw_hz` to `hz`). - Minor imports and formatting optimizations.
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::plant_state::{MoistureSensorState, PlantState};
|
||||
use crate::tank::determine_tank_state;
|
||||
use crate::{get_version, BOARD_ACCESS};
|
||||
use alloc::format;
|
||||
use alloc::string::String;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use chrono_tz::Tz;
|
||||
use core::str::FromStr;
|
||||
@@ -40,25 +40,27 @@ where
|
||||
let moistures = board.board_hal.measure_moisture_hz().await?;
|
||||
let mut plant_state = Vec::new();
|
||||
for i in 0..PLANT_COUNT {
|
||||
plant_state.push(PlantState::read_hardware_state(moistures, i, &mut board).await);
|
||||
plant_state.push(PlantState::interpret_raw_values(moistures, i, &mut board).await);
|
||||
}
|
||||
let a = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_a {
|
||||
MoistureSensorState::MoistureValue {
|
||||
raw_hz,
|
||||
hz: raw_hz,
|
||||
moisture_percent,
|
||||
} => {
|
||||
format!("{moisture_percent:.2}% {raw_hz}hz",)
|
||||
}
|
||||
MoistureSensorState::SensorError(err) => format!("{err:?}"),
|
||||
MoistureSensorState::NoMessage => "No Message".to_string(),
|
||||
}));
|
||||
let b = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_b {
|
||||
MoistureSensorState::MoistureValue {
|
||||
raw_hz,
|
||||
hz: raw_hz,
|
||||
moisture_percent,
|
||||
} => {
|
||||
format!("{moisture_percent:.2}% {raw_hz}hz",)
|
||||
}
|
||||
MoistureSensorState::SensorError(err) => format!("{err:?}"),
|
||||
MoistureSensorState::NoMessage => "No Message".to_string(),
|
||||
}));
|
||||
|
||||
let data = Moistures {
|
||||
|
||||
Reference in New Issue
Block a user