Merge branch 'fix/reenable-plant-watering-wtf-empire-this-should-never-have-happend' into legacy/v3-support
This commit is contained in:
159
rust/src/main.rs
159
rust/src/main.rs
@@ -26,7 +26,7 @@ use crate::{
|
|||||||
config::BoardVersion::INITIAL,
|
config::BoardVersion::INITIAL,
|
||||||
hal::{PlantHal, HAL, PLANT_COUNT},
|
hal::{PlantHal, HAL, PLANT_COUNT},
|
||||||
};
|
};
|
||||||
use ::log::{info, warn, error};
|
use ::log::{error, info, warn};
|
||||||
use alloc::borrow::ToOwned;
|
use alloc::borrow::ToOwned;
|
||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
@@ -122,8 +122,6 @@ pub struct PumpResult {
|
|||||||
pump_time_s: u16,
|
pump_time_s: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||||
info!("Startup Rust");
|
info!("Startup Rust");
|
||||||
|
|
||||||
@@ -197,10 +195,15 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
info!("No wifi configured, starting initial config mode");
|
info!("No wifi configured, starting initial config mode");
|
||||||
|
|
||||||
let esp = board.board_hal.get_esp();
|
let esp = board.board_hal.get_esp();
|
||||||
let ssid = esp.load_config().await
|
let ssid = esp
|
||||||
|
.load_config()
|
||||||
|
.await
|
||||||
.map(|config| config.network.ap_ssid.to_string())
|
.map(|config| config.network.ap_ssid.to_string())
|
||||||
.unwrap_or_else(|_| String::from("PlantCtrl Emergency Mode"));
|
.unwrap_or_else(|_| String::from("PlantCtrl Emergency Mode"));
|
||||||
let device = esp.interface_ap.take().context("AP interface already taken")?;
|
let device = esp
|
||||||
|
.interface_ap
|
||||||
|
.take()
|
||||||
|
.context("AP interface already taken")?;
|
||||||
let stack = network::wifi_ap(ssid, device, &esp.controller, &mut esp.rng, spawner).await?;
|
let stack = network::wifi_ap(ssid, device, &esp.controller, &mut esp.rng, spawner).await?;
|
||||||
|
|
||||||
let reboot_now = Arc::new(AtomicBool::new(false));
|
let reboot_now = Arc::new(AtomicBool::new(false));
|
||||||
@@ -225,14 +228,18 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
|
|
||||||
let res = {
|
let res = {
|
||||||
let esp = board.board_hal.get_esp();
|
let esp = board.board_hal.get_esp();
|
||||||
let ssid = esp.load_config().await
|
let ssid = esp
|
||||||
|
.load_config()
|
||||||
|
.await
|
||||||
.map(|config| config.network.ap_ssid.to_string())
|
.map(|config| config.network.ap_ssid.to_string())
|
||||||
.unwrap_or_else(|_| String::from("PlantCtrl Emergency Mode"));
|
.unwrap_or_else(|_| String::from("PlantCtrl Emergency Mode"));
|
||||||
let device = match esp.interface_ap.take() {
|
let device = match esp.interface_ap.take() {
|
||||||
Some(d) => d,
|
Some(d) => d,
|
||||||
None => {
|
None => {
|
||||||
use crate::fat_error::FatError;
|
use crate::fat_error::FatError;
|
||||||
return Err(FatError::String { error: "AP interface already taken".to_string() });
|
return Err(FatError::String {
|
||||||
|
error: "AP interface already taken".to_string(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
network::wifi_ap(ssid, device, &esp.controller, &mut esp.rng, spawner).await
|
network::wifi_ap(ssid, device, &esp.controller, &mut esp.rng, spawner).await
|
||||||
@@ -302,7 +309,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
log(LogMessage::NormalRun, 0, 0, "", "");
|
log(LogMessage::NormalRun, 0, 0, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
let _dry_run = false;
|
let dry_run = false;
|
||||||
|
|
||||||
let tank_state = determine_tank_state(&mut board).await;
|
let tank_state = determine_tank_state(&mut board).await;
|
||||||
|
|
||||||
@@ -339,7 +346,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut _water_frozen = false;
|
let mut water_frozen = false;
|
||||||
let water_temp: FatResult<f32> = match board.board_hal.get_tank_sensor() {
|
let water_temp: FatResult<f32> = match board.board_hal.get_tank_sensor() {
|
||||||
Ok(sensor) => sensor.water_temperature_c().await,
|
Ok(sensor) => sensor.water_temperature_c().await,
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
@@ -347,7 +354,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
|
|
||||||
if let Ok(res) = water_temp {
|
if let Ok(res) = water_temp {
|
||||||
if res < WATER_FROZEN_THRESH {
|
if res < WATER_FROZEN_THRESH {
|
||||||
_water_frozen = true;
|
water_frozen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info!("Water temp is {}", water_temp.as_ref().unwrap_or(&0.));
|
info!("Water temp is {}", water_temp.as_ref().unwrap_or(&0.));
|
||||||
@@ -367,74 +374,70 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
|
|
||||||
publish_plant_states(&mut board, &timezone_time.clone(), &plantstate).await;
|
publish_plant_states(&mut board, &timezone_time.clone(), &plantstate).await;
|
||||||
|
|
||||||
// let pump_required = plantstate
|
let pump_required = plantstate
|
||||||
// .iter()
|
.iter()
|
||||||
// .zip(&board.board_hal.get_config().plants)
|
.zip(&board.board_hal.get_config().plants)
|
||||||
// .any(|(it, conf)| it.needs_to_be_watered(conf, &timezone_time))
|
.any(|(it, conf)| it.needs_to_be_watered(conf, &timezone_time))
|
||||||
// && !water_frozen;
|
&& !water_frozen;
|
||||||
// if pump_required {
|
if pump_required {
|
||||||
// log(LogMessage::EnableMain, dry_run as u32, 0, "", "");
|
log(LogMessage::EnableMain, dry_run as u32, 0, "", "");
|
||||||
// for (plant_id, (state, plant_config)) in plantstate
|
for (plant_id, (state, plant_config)) in plantstate
|
||||||
// .iter()
|
.iter()
|
||||||
// .zip(&board.board_hal.get_config().plants.clone())
|
.zip(&board.board_hal.get_config().plants.clone())
|
||||||
// .enumerate()
|
.enumerate()
|
||||||
// {
|
{
|
||||||
// if state.needs_to_be_watered(plant_config, &timezone_time) {
|
if state.needs_to_be_watered(plant_config, &timezone_time) {
|
||||||
// let pump_count = board.board_hal.get_esp().consecutive_pump_count(plant_id) + 1;
|
let pump_count = board.board_hal.get_esp().consecutive_pump_count(plant_id) + 1;
|
||||||
// board
|
board
|
||||||
// .board_hal
|
.board_hal
|
||||||
// .get_esp()
|
.get_esp()
|
||||||
// .store_consecutive_pump_count(plant_id, pump_count);
|
.store_consecutive_pump_count(plant_id, pump_count);
|
||||||
//
|
let pump_ineffective = pump_count > plant_config.max_consecutive_pump_count as u32;
|
||||||
// let pump_ineffective = pump_count > plant_config.max_consecutive_pump_count as u32;
|
if pump_ineffective {
|
||||||
// if pump_ineffective {
|
log(
|
||||||
// log(
|
LogMessage::ConsecutivePumpCountLimit,
|
||||||
// LogMessage::ConsecutivePumpCountLimit,
|
pump_count,
|
||||||
// pump_count,
|
plant_config.max_consecutive_pump_count as u32,
|
||||||
// plant_config.max_consecutive_pump_count as u32,
|
&(plant_id + 1).to_string(),
|
||||||
// &(plant_id + 1).to_string(),
|
"",
|
||||||
// "",
|
);
|
||||||
// );
|
board.board_hal.fault(plant_id, true).await?;
|
||||||
// board.board_hal.fault(plant_id, true).await?;
|
}
|
||||||
// }
|
log(
|
||||||
// log(
|
LogMessage::PumpPlant,
|
||||||
// LogMessage::PumpPlant,
|
(plant_id + 1) as u32,
|
||||||
// (plant_id + 1) as u32,
|
plant_config.pump_time_s as u32,
|
||||||
// plant_config.pump_time_s as u32,
|
&dry_run.to_string(),
|
||||||
// &dry_run.to_string(),
|
"",
|
||||||
// "",
|
);
|
||||||
// );
|
board
|
||||||
// board
|
.board_hal
|
||||||
// .board_hal
|
.get_esp()
|
||||||
// .get_esp()
|
.store_last_pump_time(plant_id, cur);
|
||||||
// .store_last_pump_time(plant_id, cur);
|
board.board_hal.get_esp().last_pump_time(plant_id);
|
||||||
// board.board_hal.get_esp().last_pump_time(plant_id);
|
pump_info(plant_id, true, pump_ineffective, 0, 0, 0, false).await;
|
||||||
// //state.active = true;
|
let result = do_secure_pump(&mut board, plant_id, plant_config, dry_run).await?;
|
||||||
//
|
board.board_hal.pump(plant_id, false).await?;
|
||||||
// pump_info(plant_id, true, pump_ineffective, 0, 0, 0, false).await;
|
pump_info(
|
||||||
//
|
plant_id,
|
||||||
// let result = do_secure_pump(plant_id, plant_config, dry_run).await?;
|
false,
|
||||||
// board.board_hal.pump(plant_id, false).await?;
|
pump_ineffective,
|
||||||
// pump_info(
|
result.median_current_ma,
|
||||||
// plant_id,
|
result.max_current_ma,
|
||||||
// false,
|
result.min_current_ma,
|
||||||
// pump_ineffective,
|
result.error,
|
||||||
// result.median_current_ma,
|
)
|
||||||
// result.max_current_ma,
|
.await;
|
||||||
// result.min_current_ma,
|
} else if !state.pump_in_timeout(plant_config, &timezone_time) {
|
||||||
// result.error,
|
// plant does not need to be watered and is not in timeout
|
||||||
// )
|
// -> reset consecutive pump count
|
||||||
// .await;
|
board
|
||||||
// } else if !state.pump_in_timeout(plant_config, &timezone_time) {
|
.board_hal
|
||||||
// // plant does not need to be watered and is not in timeout
|
.get_esp()
|
||||||
// // -> reset consecutive pump count
|
.store_consecutive_pump_count(plant_id, 0);
|
||||||
// board
|
}
|
||||||
// .board_hal
|
}
|
||||||
// .get_esp()
|
}
|
||||||
// .store_consecutive_pump_count(plant_id, 0);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
info!("state of charg");
|
info!("state of charg");
|
||||||
let is_day = board.board_hal.is_day();
|
let is_day = board.board_hal.is_day();
|
||||||
|
|||||||
Reference in New Issue
Block a user