warnings to zero :)
This commit is contained in:
@@ -22,6 +22,7 @@ use esp_idf_sys::{
|
||||
esp_ota_img_states_t_ESP_OTA_IMG_VALID,
|
||||
vTaskDelay
|
||||
};
|
||||
use esp_ota::{mark_app_valid, rollback_and_reboot};
|
||||
use log::log;
|
||||
use once_cell::sync::Lazy;
|
||||
use plant_hal::{PlantCtrlBoard, PlantHal, PLANT_COUNT};
|
||||
@@ -29,12 +30,10 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
config::PlantControllerConfig,
|
||||
espota::{mark_app_valid, rollback_and_reboot},
|
||||
webserver::webserver::httpd,
|
||||
};
|
||||
mod log;
|
||||
mod config;
|
||||
pub mod espota;
|
||||
pub mod plant_hal;
|
||||
|
||||
|
||||
@@ -147,8 +146,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
bail!(
|
||||
"stack too small: {} bail!",
|
||||
esp_idf_sys::CONFIG_MAIN_TASK_STACK_SIZE
|
||||
);
|
||||
return Ok(());
|
||||
)
|
||||
}
|
||||
|
||||
println!("Startup Rust");
|
||||
@@ -186,16 +184,16 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
&format!("unknown {ota_state}")
|
||||
}
|
||||
};
|
||||
log(log::LogMessage::partition_state, 0,0, "", ota_state_string);
|
||||
log(log::LogMessage::PartitionState, 0,0, "", ota_state_string);
|
||||
|
||||
|
||||
let mut board: std::sync::MutexGuard<'_, PlantCtrlBoard<'_>> = BOARD_ACCESS.lock().unwrap();
|
||||
board.general_fault(false);
|
||||
|
||||
log(log::LogMessage::mounting_filesystem, 0,0,"","");
|
||||
log(log::LogMessage::MountingFilesystem, 0,0,"","");
|
||||
board.mount_file_system()?;
|
||||
let free_space = board.file_system_size()?;
|
||||
log(log::LogMessage::filesystem_mount, free_space.free_size as u32,
|
||||
log(log::LogMessage::FilesystemMount, free_space.free_size as u32,
|
||||
free_space.total_size as u32, &free_space.used_size.to_string(), "");
|
||||
|
||||
|
||||
@@ -209,7 +207,6 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
Ok(cur) => cur,
|
||||
Err(err) => {
|
||||
bail!("time error {}", err);
|
||||
DateTime::from_timestamp_millis(0).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,13 +215,13 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
//check if we know the time current > 2020
|
||||
if cur.year() < 2020 {
|
||||
to_config = true;
|
||||
log(log::LogMessage::year_inplausible_force_config, 0,0,"","");
|
||||
log(log::LogMessage::YearInplausibleForceConfig, 0,0,"","");
|
||||
}
|
||||
|
||||
println!("cur is {}", cur);
|
||||
|
||||
if board.get_restart_to_conf() {
|
||||
log(log::LogMessage::config_mode_software_override, 0,0,"","");
|
||||
log(log::LogMessage::ConfigModeSoftwareOverride, 0,0,"","");
|
||||
for _i in 0..2 {
|
||||
board.general_fault(true);
|
||||
Delay::new_default().delay_ms(100);
|
||||
@@ -236,7 +233,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
board.set_restart_to_conf(false);
|
||||
} else if board.is_mode_override() {
|
||||
board.general_fault(true);
|
||||
log(log::LogMessage::config_mode_button_override, 0,0,"","");
|
||||
log(log::LogMessage::ConfigModeButtonOverride, 0,0,"","");
|
||||
for _i in 0..5 {
|
||||
board.general_fault(true);
|
||||
Delay::new_default().delay_ms(100);
|
||||
@@ -258,7 +255,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
config = valid;
|
||||
}
|
||||
Err(err) => {
|
||||
log(log::LogMessage::config_mode_missing_config, 0,0,"",&err.to_string());
|
||||
log(log::LogMessage::ConfigModeMissingConfig, 0,0,"",&err.to_string());
|
||||
//config upload will trigger reboot!
|
||||
let _ = board.wifi_ap(Option::None);
|
||||
drop(board);
|
||||
@@ -362,7 +359,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
publish_battery_state(&mut board, &config);
|
||||
}
|
||||
|
||||
log(log::LogMessage::startup_info, wifi as u32, sntp as u32,&mqtt.to_string(),"");
|
||||
log(log::LogMessage::StartupInfo, wifi as u32, sntp as u32,&mqtt.to_string(),"");
|
||||
|
||||
if to_config {
|
||||
//check if client or ap mode and init wifi
|
||||
@@ -373,7 +370,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
let _webserver = httpd(reboot_now.clone());
|
||||
wait_infinity(WaitType::ConfigButton, reboot_now.clone());
|
||||
} else {
|
||||
log(log::LogMessage::normal_run, 0,0,"","");
|
||||
log(log::LogMessage::NormalRun, 0,0,"","");
|
||||
}
|
||||
|
||||
|
||||
@@ -428,11 +425,10 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
let mut plantstate: [PlantState; PLANT_COUNT] = core::array::from_fn(|_| PlantState {
|
||||
..Default::default()
|
||||
});
|
||||
let plant_to_pump = determine_next_plant(
|
||||
determine_plant_state(
|
||||
&mut plantstate,
|
||||
timezone_time,
|
||||
&tank_state,
|
||||
water_frozen,
|
||||
&config,
|
||||
&mut board,
|
||||
);
|
||||
@@ -440,7 +436,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
|
||||
let pump_required = plantstate.iter().any(|it| it.do_water) && !water_frozen;
|
||||
if pump_required {
|
||||
log(log::LogMessage::enable_main, dry_run as u32,0,"","");
|
||||
log(log::LogMessage::EnableMain, dry_run as u32,0,"","");
|
||||
if !dry_run{
|
||||
board.any_pump(true)?;
|
||||
}
|
||||
@@ -452,11 +448,11 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
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::consecutive_pump_count_limit, state.consecutive_pump_count as u32,plant_config.max_consecutive_pump_count as u32,&plant.to_string(),"");
|
||||
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::pump_plant, (plant + 1) as u32,plant_config.pump_time_s as u32,&dry_run.to_string(),"");
|
||||
log(log::LogMessage::PumpPlant, (plant + 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;
|
||||
@@ -812,11 +808,10 @@ fn determine_state_timer_and_deadzone_for_plant(
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_next_plant(
|
||||
fn determine_plant_state(
|
||||
plantstate: &mut [PlantState; PLANT_COUNT],
|
||||
cur: DateTime<Tz>,
|
||||
tank_state: &TankState,
|
||||
water_frozen: bool,
|
||||
config: &PlantControllerConfig,
|
||||
board: &mut std::sync::MutexGuard<'_, PlantCtrlBoard<'_>>,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user