Housekeeping #18

Merged
EmpirePhoenix merged 8 commits from housekeeping into develop 2025-06-23 22:15:51 +02:00
7 changed files with 16 additions and 28 deletions
Showing only changes of commit 5621f17e61 - Show all commits

View File

@ -97,6 +97,7 @@ impl BatteryInteraction for NoBatteryMonitor {
} }
//TODO implement this battery monitor kind once controller is complete //TODO implement this battery monitor kind once controller is complete
#[allow(dead_code)]
pub struct WchI2cSlave {} pub struct WchI2cSlave {}
pub struct BQ34Z100G1<'a> { pub struct BQ34Z100G1<'a> {

View File

@ -51,11 +51,6 @@ const TANK_MULTI_SAMPLE: usize = 11;
pub static I2C_DRIVER: Lazy<Mutex<I2cDriver<'static>>> = Lazy::new(PlantHal::create_i2c); pub static I2C_DRIVER: Lazy<Mutex<I2cDriver<'static>>> = Lazy::new(PlantHal::create_i2c);
#[non_exhaustive]
struct V3Constants;
impl V3Constants {}
const X25: crc::Crc<u16> = crc::Crc::<u16>::new(&crc::CRC_16_IBM_SDLC); const X25: crc::Crc<u16> = crc::Crc::<u16>::new(&crc::CRC_16_IBM_SDLC);
fn deep_sleep(duration_in_ms: u64) -> ! { fn deep_sleep(duration_in_ms: u64) -> ! {
@ -132,6 +127,7 @@ pub trait BoardInteraction<'a> {
fn set_config(&mut self, config: PlantControllerConfig) -> Result<()>; fn set_config(&mut self, config: PlantControllerConfig) -> Result<()>;
} }
#[allow(dead_code)]
pub struct FreePeripherals { pub struct FreePeripherals {
pub gpio0: Gpio0, pub gpio0: Gpio0,
pub gpio1: Gpio1, pub gpio1: Gpio1,

View File

@ -84,7 +84,7 @@ pub struct V3<'a> {
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>, PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>, PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
>, >,
shift_register_enable_invert: _shift_register_enable_invert:
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Output>, PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Output>,
tank_channel: AdcChannelDriver<'a, Gpio5, AdcDriver<'a, esp_idf_hal::adc::ADC1>>, tank_channel: AdcChannelDriver<'a, Gpio5, AdcDriver<'a, esp_idf_hal::adc::ADC1>>,
solar_is_day: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Input>, solar_is_day: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Input>,
@ -109,7 +109,7 @@ pub(crate) fn create_v3(
esp: ESP<'static>, esp: ESP<'static>,
config: PlantControllerConfig, config: PlantControllerConfig,
battery_monitor: Box<dyn BatteryInteraction + Send>, battery_monitor: Box<dyn BatteryInteraction + Send>,
) -> Result<Box<dyn BoardInteraction + Send + '_>> { ) -> Result<Box<dyn BoardInteraction<'static> + Send>> {
let mut clock = PinDriver::input_output(peripherals.gpio15.downgrade())?; let mut clock = PinDriver::input_output(peripherals.gpio15.downgrade())?;
clock.set_pull(Pull::Floating)?; clock.set_pull(Pull::Floating)?;
let mut latch = PinDriver::input_output(peripherals.gpio3.downgrade())?; let mut latch = PinDriver::input_output(peripherals.gpio3.downgrade())?;
@ -234,7 +234,7 @@ pub(crate) fn create_v3(
battery_monitor, battery_monitor,
esp, esp,
shift_register, shift_register,
shift_register_enable_invert, _shift_register_enable_invert: shift_register_enable_invert,
tank_channel, tank_channel,
solar_is_day, solar_is_day,
light, light,

View File

@ -38,7 +38,7 @@ const MS4: u8 = 2_u8;
const SENSOR_ON: u8 = 5_u8; const SENSOR_ON: u8 = 5_u8;
pub struct V4<'a> { pub struct V4<'a> {
mppt_ina: SyncIna219<MutexDevice<'a, I2cDriver<'a>>, UnCalibrated>, _mppt_ina: SyncIna219<MutexDevice<'a, I2cDriver<'a>>, UnCalibrated>,
esp: ESP<'a>, esp: ESP<'a>,
battery_monitor: Box<dyn BatteryInteraction + Send>, battery_monitor: Box<dyn BatteryInteraction + Send>,
config: PlantControllerConfig, config: PlantControllerConfig,
@ -63,12 +63,12 @@ pub struct V4<'a> {
sensor_expander: Pca9535Immediate<MutexDevice<'a, I2cDriver<'a>>>, sensor_expander: Pca9535Immediate<MutexDevice<'a, I2cDriver<'a>>>,
} }
pub(crate) fn create_v4( pub(crate) fn create_v4<'a>(
peripherals: FreePeripherals, peripherals: FreePeripherals,
esp: ESP<'static>, esp: ESP<'static>,
config: PlantControllerConfig, config: PlantControllerConfig,
battery_monitor: Box<dyn BatteryInteraction + Send>, battery_monitor: Box<dyn BatteryInteraction + Send>,
) -> anyhow::Result<Box<dyn BoardInteraction + Send + '_>> { ) -> anyhow::Result<Box<dyn BoardInteraction<'static> + Send>> {
let mut awake = PinDriver::output(peripherals.gpio15.downgrade())?; let mut awake = PinDriver::output(peripherals.gpio15.downgrade())?;
awake.set_high()?; awake.set_high()?;
@ -188,7 +188,7 @@ pub(crate) fn create_v4(
println!("Shunt Current: {}", current); println!("Shunt Current: {}", current);
let v = V4 { let v = V4 {
mppt_ina, _mppt_ina: mppt_ina,
esp, esp,
awake, awake,
tank_channel, tank_channel,

View File

@ -20,11 +20,7 @@ use log::{log, LogMessage};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use plant_state::PlantState; use plant_state::PlantState;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::MutexGuard; use std::sync::{atomic::AtomicBool, Arc, Mutex, MutexGuard};
use std::{
fmt::Display,
sync::{atomic::AtomicBool, Arc, Mutex},
};
use tank::*; use tank::*;
mod config; mod config;
@ -841,15 +837,6 @@ fn main() {
} }
} }
fn to_string<T: Display>(value: anyhow::Result<T>) -> String {
match value {
Ok(v) => v.to_string(),
Err(err) => {
format!("{:?}", err)
}
}
}
pub fn in_time_range(cur: &DateTime<Tz>, start: u8, end: u8) -> bool { pub fn in_time_range(cur: &DateTime<Tz>, start: u8, end: u8) -> bool {
let curhour = cur.hour() as u8; let curhour = cur.hour() as u8;
//eg 10-14 //eg 10-14

View File

@ -239,7 +239,11 @@ impl PlantState {
} }
} }
pub fn to_mqtt_info(&self, plant_conf: &PlantConfig, current_time: &DateTime<Tz>) -> PlantInfo { pub fn to_mqtt_info(
&self,
plant_conf: &PlantConfig,
current_time: &DateTime<Tz>,
) -> PlantInfo<'_> {
PlantInfo { PlantInfo {
sensor_a: &self.sensor_a, sensor_a: &self.sensor_a,
sensor_b: &self.sensor_b, sensor_b: &self.sensor_b,

View File

@ -214,7 +214,7 @@ fn set_config(
let config: PlantControllerConfig = serde_json::from_slice(&all)?; let config: PlantControllerConfig = serde_json::from_slice(&all)?;
let mut board = BOARD_ACCESS.lock().expect("board access"); let mut board = BOARD_ACCESS.lock().expect("board access");
board.board_hal.set_config(config); let _ = board.board_hal.set_config(config);
anyhow::Ok(Some("saved".to_owned())) anyhow::Ok(Some("saved".to_owned()))
} }