logging and pcb adjustment

This commit is contained in:
2025-02-14 23:50:19 +01:00
parent 1741bb0b53
commit aad1dbd458
15 changed files with 389 additions and 119 deletions

View File

@@ -3,7 +3,7 @@ use std::{
sync::{atomic::AtomicBool, Arc, Mutex},
};
use anyhow::Result;
use anyhow::{bail, Result};
use chrono::{DateTime, Datelike, TimeDelta, Timelike, Utc};
use chrono_tz::{Europe::Berlin, Tz};
@@ -22,7 +22,6 @@ use esp_idf_sys::{
esp_ota_img_states_t_ESP_OTA_IMG_VALID,
vTaskDelay
};
use log::error;
use once_cell::sync::Lazy;
use plant_hal::{PlantCtrlBoard, PlantHal, PLANT_COUNT};
use serde::{Deserialize, Serialize};
@@ -32,10 +31,12 @@ use crate::{
espota::{mark_app_valid, rollback_and_reboot},
webserver::webserver::httpd,
};
mod log;
mod config;
pub mod espota;
pub mod plant_hal;
const TIME_ZONE: Tz = Berlin;
const MOIST_SENSOR_MAX_FREQUENCY: u32 = 250000; // 60kHz (500Hz margin)
@@ -72,9 +73,9 @@ struct LightState {
#[derive(Debug, PartialEq, Default)]
struct PlantState {
a: Option<u8>,
a_raw: Option<i32>,
a_raw: Option<u32>,
b: Option<u8>,
b_raw: Option<i32>,
b_raw: Option<u32>,
consecutive_pump_count: u32,
after_p: Option<u8>,
do_water: bool,
@@ -142,14 +143,14 @@ fn safe_main() -> anyhow::Result<()> {
esp_idf_svc::log::EspLogger::initialize_default();
if esp_idf_sys::CONFIG_MAIN_TASK_STACK_SIZE < 25000 {
error!(
bail!(
"stack too small: {} bail!",
esp_idf_sys::CONFIG_MAIN_TASK_STACK_SIZE
);
return Ok(());
}
log::info!("Startup Rust");
println!("Startup Rust");
let mut to_config = false;
@@ -186,6 +187,7 @@ fn safe_main() -> anyhow::Result<()> {
};
println!("{}", ota_state_string);
println!("Board hal init");
let mut board: std::sync::MutexGuard<'_, PlantCtrlBoard<'_>> = BOARD_ACCESS.lock().unwrap();
board.general_fault(false);
@@ -207,7 +209,7 @@ fn safe_main() -> anyhow::Result<()> {
match time {
Ok(cur) => cur,
Err(err) => {
log::error!("time error {}", err);
bail!("time error {}", err);
DateTime::from_timestamp_millis(0).unwrap()
}
}
@@ -284,7 +286,7 @@ fn safe_main() -> anyhow::Result<()> {
ip_address = Some(ip_info.ip.to_string());
wifi = true;
match board.sntp(1000 * 5) {
match board.sntp(1000 * 10) {
Ok(new_time) => {
println!("Using time from sntp");
let _ = board.set_rtc_time(&new_time);