save compiling state during refactor
This commit is contained in:
@@ -7,7 +7,6 @@ use anyhow::{bail, Result};
|
||||
use chrono::{DateTime, Datelike, TimeDelta, Timelike, Utc};
|
||||
use chrono_tz::{Europe::Berlin, Tz};
|
||||
|
||||
use config::PlantWateringMode;
|
||||
use esp_idf_hal::delay::Delay;
|
||||
use esp_idf_sys::{
|
||||
esp_ota_get_app_partition_count, esp_ota_get_running_partition, esp_ota_get_state_partition,
|
||||
@@ -410,50 +409,55 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
let mut plantstate: [PlantState; PLANT_COUNT] =
|
||||
core::array::from_fn(|i| PlantState::read_hardware_state(i, &mut board, &config.plants[i]));
|
||||
|
||||
let pump_required = plantstate.iter().any(|it| it.needs_to_be_watered(&config.plants[i], &timezone_time)) && !water_frozen;
|
||||
let pump_required = plantstate
|
||||
.iter()
|
||||
.zip(&config.plants)
|
||||
.any(|(it, conf)| it.needs_to_be_watered(&conf, &timezone_time))
|
||||
&& !water_frozen;
|
||||
if pump_required {
|
||||
log(log::LogMessage::EnableMain, dry_run as u32, 0, "", "");
|
||||
if !dry_run {
|
||||
board.any_pump(true)?;
|
||||
board.any_pump(true)?; // what does this do? Does it need to be reset?
|
||||
}
|
||||
for plant in 0..PLANT_COUNT {
|
||||
let state = &mut plantstate[plant];
|
||||
if state.do_water {
|
||||
let plant_config = &config.plants[plant];
|
||||
state.consecutive_pump_count = board.consecutive_pump_count(plant) + 1;
|
||||
board.store_consecutive_pump_count(plant, state.consecutive_pump_count);
|
||||
if state.consecutive_pump_count > plant_config.max_consecutive_pump_count as u32 {
|
||||
log(
|
||||
log::LogMessage::ConsecutivePumpCountLimit,
|
||||
state.consecutive_pump_count as u32,
|
||||
plant_config.max_consecutive_pump_count as u32,
|
||||
&plant.to_string(),
|
||||
"",
|
||||
);
|
||||
state.not_effective = true;
|
||||
board.fault(plant, true);
|
||||
}
|
||||
for (plant_id, (state, plant_config)) in plantstate.iter().zip(&config.plants).enumerate() {
|
||||
if state.needs_to_be_watered(&plant_config, &timezone_time) {
|
||||
let pump_count = board.consecutive_pump_count(plant_id) + 1;
|
||||
board.store_consecutive_pump_count(plant_id, pump_count);
|
||||
//TODO(judge) where to put this?
|
||||
//if state.consecutive_pump_count > plant_config.max_consecutive_pump_count as u32 {
|
||||
// log(
|
||||
// log::LogMessage::ConsecutivePumpCountLimit,
|
||||
// state.consecutive_pump_count as u32,
|
||||
// plant_config.max_consecutive_pump_count as u32,
|
||||
// &plant.to_string(),
|
||||
// "",
|
||||
// );
|
||||
// state.not_effective = true;
|
||||
// board.fault(plant, true);
|
||||
//}
|
||||
log(
|
||||
log::LogMessage::PumpPlant,
|
||||
(plant + 1) as u32,
|
||||
(plant_id + 1) as u32,
|
||||
plant_config.pump_time_s as u32,
|
||||
&dry_run.to_string(),
|
||||
"",
|
||||
);
|
||||
board.store_last_pump_time(plant, cur);
|
||||
board.last_pump_time(plant);
|
||||
state.active = true;
|
||||
board.store_last_pump_time(plant_id, cur);
|
||||
board.last_pump_time(plant_id);
|
||||
//state.active = true;
|
||||
if !dry_run {
|
||||
board.pump(plant, true)?;
|
||||
for _ in 0..plant_config.pump_time_s {
|
||||
Delay::new_default().delay_ms(1000);
|
||||
}
|
||||
board.pump(plant, false)?;
|
||||
board.pump(plant_id, true)?;
|
||||
Delay::new_default().delay_ms(1000*plant_config.pump_time_s as u32);
|
||||
board.pump(plant_id, false)?;
|
||||
}
|
||||
} else if !state.pump_in_timeout(&plant_config, &timezone_time){
|
||||
// plant does not need to be watered and is not in timeout
|
||||
// -> reset consecutive pump count
|
||||
board.store_consecutive_pump_count(plant_id, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
update_plant_state(&mut plantstate, &mut board, &config);
|
||||
//update_plant_state(&mut plantstate, &mut board, &config);
|
||||
|
||||
let is_day = board.is_day();
|
||||
let state_of_charge = board.state_charge_percent().unwrap_or(0);
|
||||
|
||||
Reference in New Issue
Block a user