probalby found most of the import related stuff, now the real refactor begins

This commit is contained in:
ju6ge 2025-09-12 00:05:52 +02:00
parent 242e748ca0
commit 0d495d0f56
Signed by: judge
GPG Key ID: 6512C30DD8E017B5
8 changed files with 24 additions and 24 deletions

View File

@ -6,7 +6,7 @@ use anyhow::{anyhow, bail, Context};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::Serialize; use serde::Serialize;
use alloc::{vec::Vec, string::String}; use alloc::{vec::Vec, string::{String, ToString}};
#[link_section = ".rtc.data"] #[link_section = ".rtc.data"]
static mut LAST_WATERING_TIMESTAMP: [i64; PLANT_COUNT] = [0; PLANT_COUNT]; static mut LAST_WATERING_TIMESTAMP: [i64; PLANT_COUNT] = [0; PLANT_COUNT];

View File

@ -17,6 +17,7 @@ use crate::{
}, },
log::{log, LogMessage}, log::{log, LogMessage},
}; };
use alloc::boxed::Box;
use anyhow::{Ok, Result}; use anyhow::{Ok, Result};
use battery::BQ34Z100G1; use battery::BQ34Z100G1;
use bq34z100::Bq34z100g1Driver; use bq34z100::Bq34z100g1Driver;
@ -45,18 +46,16 @@ use esp_idf_sys::{
}; };
use esp_ota::mark_app_valid; use esp_ota::mark_app_valid;
use measurements::{Current, Voltage}; use measurements::{Current, Voltage};
use once_cell::sync::Lazy; use embassy_sync::{Mutex, LazyLock};
use std::result::Result::Ok as OkStd;
use std::sync::Mutex;
use std::time::Duration;
use esp_idf_hal::can::CAN; use esp_idf_hal::can::CAN;
use crate::alloc::string::ToString;
//Only support for 8 right now! //Only support for 8 right now!
pub const PLANT_COUNT: usize = 8; pub const PLANT_COUNT: usize = 8;
const TANK_MULTI_SAMPLE: usize = 11; const TANK_MULTI_SAMPLE: usize = 11;
pub static I2C_DRIVER: Lazy<Mutex<I2cDriver<'static>>> = Lazy::new(PlantHal::create_i2c); pub static I2C_DRIVER: LazyLock<Mutex<I2cDriver<'static>>> = LazyLock::new(PlantHal::create_i2c);
fn deep_sleep(duration_in_ms: u64) -> ! { fn deep_sleep(duration_in_ms: u64) -> ! {
unsafe { unsafe {

View File

@ -10,14 +10,12 @@ use crate::{
}; };
use anyhow::{bail, Ok, Result}; use anyhow::{bail, Ok, Result};
use embedded_hal::digital::OutputPin; use embedded_hal::digital::OutputPin;
use esp_idf_hal::{
gpio::{AnyInputPin, IOPin, InputOutput, PinDriver, Pull},
pcnt::{PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex},
};
use esp_idf_sys::{gpio_hold_dis, gpio_hold_en};
use measurements::{Current, Voltage}; use measurements::{Current, Voltage};
use plant_ctrl2::sipo::ShiftRegister40; use plant_ctrl2::sipo::ShiftRegister40;
use std::result::Result::Ok as OkStd; use core::result::Result::Ok as OkStd;
use alloc::string::ToString;
use alloc::boxed::Box;
use esp_hall::gpio::Pull;
const PUMP8_BIT: usize = 0; const PUMP8_BIT: usize = 0;
const PUMP1_BIT: usize = 1; const PUMP1_BIT: usize = 1;

View File

@ -12,12 +12,6 @@ use crate::log::{log, LogMessage};
use anyhow::bail; use anyhow::bail;
use embedded_hal::digital::OutputPin; use embedded_hal::digital::OutputPin;
use embedded_hal_bus::i2c::MutexDevice; use embedded_hal_bus::i2c::MutexDevice;
use esp_idf_hal::gpio::{AnyInputPin, IOPin, InputOutput, Output, PinDriver, Pull};
use esp_idf_hal::i2c::I2cDriver;
use esp_idf_hal::pcnt::{
PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex,
};
use esp_idf_sys::{gpio_hold_dis, gpio_hold_en};
use ina219::address::{Address, Pin}; use ina219::address::{Address, Pin};
use ina219::calibration::UnCalibrated; use ina219::calibration::UnCalibrated;
use ina219::configuration::{Configuration, OperatingMode}; use ina219::configuration::{Configuration, OperatingMode};
@ -27,7 +21,9 @@ use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface};
use std::result::Result::Ok as OkStd; use std::result::Result::Ok as OkStd;
use embedded_can::Frame; use embedded_can::Frame;
use embedded_can::StandardId; use embedded_can::StandardId;
use esp_idf_hal::can; use alloc::string::ToString;
use alloc::boxed::Box;
use esp_hal::gpio::Pull;
pub enum Charger<'a> { pub enum Charger<'a> {
SolarMpptV1 { SolarMpptV1 {

View File

@ -1,3 +1,4 @@
use alloc::string::ToString;
use embedded_hal_bus::i2c::MutexDevice; use embedded_hal_bus::i2c::MutexDevice;
use esp_idf_hal::can::CanDriver; use esp_idf_hal::can::CanDriver;
use esp_idf_hal::delay::Delay; use esp_idf_hal::delay::Delay;

View File

@ -1,4 +1,5 @@
use alloc::string::ToString; use alloc::string::ToString;
use alloc::vec::Vec;
use serde::Serialize; use serde::Serialize;
use std::{collections::HashMap, sync::Mutex}; use std::{collections::HashMap, sync::Mutex};
use strum::EnumIter; use strum::EnumIter;

View File

@ -11,7 +11,9 @@ use crate::{
hal::{PlantHal, HAL, PLANT_COUNT}, hal::{PlantHal, HAL, PLANT_COUNT},
//webserver::httpd, //webserver::httpd,
}; };
use core::sync::atomic::Ordering;
use alloc::borrow::ToOwned; use alloc::borrow::ToOwned;
use alloc::sync::Arc;
use alloc::fmt::format; use alloc::fmt::format;
use alloc::string::{String, ToString}; use alloc::string::{String, ToString};
use anyhow::{bail, Context}; use anyhow::{bail, Context};
@ -19,10 +21,12 @@ use chrono::{DateTime, Datelike, Timelike, Utc};
use chrono_tz::Tz::{self, UTC}; use chrono_tz::Tz::{self, UTC};
use embassy_executor::Spawner; use embassy_executor::Spawner;
use hal::battery::BatteryState; use hal::battery::BatteryState;
use esp_hal::{timer::systimer::SystemTimer, clock::CpuClock, delay::Delay};
use esp_println::logger;
use log::{log, LogMessage}; use log::{log, LogMessage};
use plant_state::PlantState; use plant_state::PlantState;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use embassy_sync::{Mutex, LazyLock}; use embassy_sync::{Mutex, LazyLock, mutex::MutexGuard};
use portable_atomic::AtomicBool; use portable_atomic::AtomicBool;
use tank::*; use tank::*;
mod config; mod config;
@ -549,7 +553,7 @@ fn safe_main() -> anyhow::Result<()> {
//TODO //TODO
//mark_app_valid(); //mark_app_valid();
let stay_alive_mqtt = STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed); let stay_alive_mqtt = STAY_ALIVE.load(Ordering::Relaxed);
let stay_alive = stay_alive_mqtt; let stay_alive = stay_alive_mqtt;
log::info!("Check stay alive, current state is {}", stay_alive); log::info!("Check stay alive, current state is {}", stay_alive);
@ -961,11 +965,11 @@ fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
delay_handle.delay_ms(delay); delay_handle.delay_ms(delay);
if wait_type == WaitType::MqttConfig if wait_type == WaitType::MqttConfig
&& !STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed) && !STAY_ALIVE.load(Ordering::Relaxed)
{ {
reboot_now.store(true, std::sync::atomic::Ordering::Relaxed); reboot_now.store(true, Ordering::Relaxed);
} }
if reboot_now.load(std::sync::atomic::Ordering::Relaxed) { if reboot_now.load(Ordering::Relaxed) {
//ensure clean http answer //ensure clean http answer
Delay::new_default().delay_ms(500); Delay::new_default().delay_ms(500);
BOARD_ACCESS.lock().unwrap().board_hal.deep_sleep(1); BOARD_ACCESS.lock().unwrap().board_hal.deep_sleep(1);

View File

@ -3,6 +3,7 @@ use crate::{
hal::{Sensor, HAL}, hal::{Sensor, HAL},
in_time_range, in_time_range,
}; };
use alloc::string::String;
use chrono::{DateTime, TimeDelta, Utc}; use chrono::{DateTime, TimeDelta, Utc};
use chrono_tz::Tz; use chrono_tz::Tz;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};