refactor: unify moisture handling, update config structure, and add peer dependencies
This commit is contained in:
@@ -120,8 +120,8 @@ impl PlantState {
|
||||
let raw = moistures.sensor_a_hz[plant_id];
|
||||
match map_range_moisture(
|
||||
raw,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_min_frequency,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_max_frequency,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_min_frequency.map(|a| a as f32),
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_max_frequency.map(|b| b as f32),
|
||||
) {
|
||||
Ok(moisture_percent) => MoistureSensorState::MoistureValue {
|
||||
raw_hz: raw,
|
||||
@@ -137,8 +137,8 @@ impl PlantState {
|
||||
let raw = moistures.sensor_b_hz[plant_id];
|
||||
match map_range_moisture(
|
||||
raw,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_min_frequency,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_max_frequency,
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_min_frequency.map(|a| a as f32),
|
||||
board.board_hal.get_config().plants[plant_id].moisture_sensor_max_frequency.map(|b| b as f32)
|
||||
) {
|
||||
Ok(moisture_percent) => MoistureSensorState::MoistureValue {
|
||||
raw_hz: raw,
|
||||
@@ -186,7 +186,7 @@ impl PlantState {
|
||||
pub fn plant_moisture(
|
||||
&self,
|
||||
) -> (
|
||||
Option<f32>,
|
||||
Option<u8>,
|
||||
(Option<&MoistureSensorError>, Option<&MoistureSensorError>),
|
||||
) {
|
||||
match (
|
||||
@@ -194,10 +194,10 @@ impl PlantState {
|
||||
self.sensor_b.moisture_percent(),
|
||||
) {
|
||||
(Some(moisture_a), Some(moisture_b)) => {
|
||||
(Some((moisture_a + moisture_b) / 2.), (None, None))
|
||||
(Some(((moisture_a + moisture_b) / 2.) as u8), (None, None))
|
||||
}
|
||||
(Some(moisture_percent), _) => (Some(moisture_percent), (None, self.sensor_b.is_err())),
|
||||
(_, Some(moisture_percent)) => (Some(moisture_percent), (self.sensor_a.is_err(), None)),
|
||||
(Some(moisture_percent), _) => (Some(moisture_percent as u8), (None, self.sensor_b.is_err())),
|
||||
(_, Some(moisture_percent)) => (Some(moisture_percent as u8), (self.sensor_a.is_err(), None)),
|
||||
_ => (None, (self.sensor_a.is_err(), self.sensor_b.is_err())),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user