it's alive

This commit is contained in:
2025-09-13 01:39:47 +02:00
parent 79087c9353
commit 9de85b6e37
19 changed files with 1567 additions and 1488 deletions

View File

@@ -1,19 +1,21 @@
use alloc::vec::Vec;
use crate::hal::esp::Esp;
use crate::hal::rtc::{BackupHeader, RTCModuleInteraction};
use crate::hal::water::TankSensor;
//use crate::hal::water::TankSensor;
use crate::hal::{deep_sleep, BoardInteraction, FreePeripherals, Sensor};
use crate::{
config::PlantControllerConfig,
hal::battery::{BatteryInteraction, NoBatteryMonitor},
};
use anyhow::{bail, Result};
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use embedded_hal::digital::OutputPin;
use measurements::{Current, Voltage};
use crate::alloc::boxed::Box;
pub struct Initial<'a> {
pub(crate) general_fault: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
//pub(crate) general_fault: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
pub(crate) esp: Esp<'a>,
pub(crate) config: PlantControllerConfig,
pub(crate) battery: Box<dyn BatteryInteraction + Send>,
@@ -22,44 +24,45 @@ pub struct Initial<'a> {
struct NoRTC {}
#[async_trait]
impl RTCModuleInteraction for NoRTC {
fn get_backup_info(&mut self) -> Result<BackupHeader> {
async fn get_backup_info(&mut self) -> Result<BackupHeader> {
bail!("Please configure board revision")
}
fn get_backup_config(&mut self) -> Result<Vec<u8>> {
async fn get_backup_config(&mut self) -> Result<Vec<u8>> {
bail!("Please configure board revision")
}
fn backup_config(&mut self, _bytes: &[u8]) -> Result<()> {
async fn backup_config(&mut self, _bytes: &[u8]) -> Result<()> {
bail!("Please configure board revision")
}
fn get_rtc_time(&mut self) -> Result<DateTime<Utc>> {
async fn get_rtc_time(&mut self) -> Result<DateTime<Utc>> {
bail!("Please configure board revision")
}
fn set_rtc_time(&mut self, _time: &DateTime<Utc>) -> Result<()> {
async fn set_rtc_time(&mut self, _time: &DateTime<Utc>) -> Result<()> {
bail!("Please configure board revision")
}
}
pub(crate) fn create_initial_board(
free_pins: FreePeripherals,
//free_pins: FreePeripherals,
fs_mount_error: bool,
config: PlantControllerConfig,
esp: Esp<'static>,
) -> Result<Box<dyn BoardInteraction<'static> + Send>> {
log::info!("Start initial");
let mut general_fault = PinDriver::input_output(free_pins.gpio6.downgrade())?;
general_fault.set_pull(Pull::Floating)?;
general_fault.set_low()?;
if fs_mount_error {
general_fault.set_high()?
}
// let mut general_fault = PinDriver::input_output(free_pins.gpio6.downgrade())?;
// general_fault.set_pull(Pull::Floating)?;
// general_fault.set_low()?;
//
// if fs_mount_error {
// general_fault.set_high()?
// }
let v = Initial {
general_fault,
//general_fault,
config,
esp,
battery: Box::new(NoBatteryMonitor {}),
@@ -68,10 +71,11 @@ pub(crate) fn create_initial_board(
Ok(Box::new(v))
}
#[async_trait]
impl<'a> BoardInteraction<'a> for Initial<'a> {
fn get_tank_sensor(&mut self) -> Option<&mut TankSensor<'a>> {
None
}
// fn get_tank_sensor(&mut self) -> Option<&mut TankSensor<'a>> {
// None
// }
fn get_esp(&mut self) -> &mut Esp<'a> {
&mut self.esp
@@ -103,41 +107,42 @@ impl<'a> BoardInteraction<'a> for Initial<'a> {
bail!("Please configure board revision")
}
fn pump(&mut self, _plant: usize, _enable: bool) -> Result<()> {
async fn pump(&mut self, _plant: usize, _enable: bool) -> Result<()> {
bail!("Please configure board revision")
}
fn pump_current(&mut self, _plant: usize) -> Result<Current> {
async fn pump_current(&mut self, _plant: usize) -> Result<Current> {
bail!("Please configure board revision")
}
fn fault(&mut self, _plant: usize, _enable: bool) -> Result<()> {
async fn fault(&mut self, _plant: usize, _enable: bool) -> Result<()> {
bail!("Please configure board revision")
}
fn measure_moisture_hz(&mut self, _plant: usize, _sensor: Sensor) -> Result<f32> {
async fn measure_moisture_hz(&mut self, _plant: usize, _sensor: Sensor) -> Result<f32> {
bail!("Please configure board revision")
}
fn general_fault(&mut self, enable: bool) {
let _ = self.general_fault.set_state(enable.into());
async fn general_fault(&mut self, enable: bool) {
//let _ = self.general_fault.set_state(enable.into());
}
fn test(&mut self) -> Result<()> {
async fn test(&mut self) -> Result<()> {
bail!("Please configure board revision")
}
fn set_config(&mut self, config: PlantControllerConfig) -> anyhow::Result<()> {
async fn set_config(&mut self, config: PlantControllerConfig) -> anyhow::Result<()> {
self.config = config;
self.esp.save_config(&self.config)?;
//TODO
// self.esp.save_config(&self.config)?;
anyhow::Ok(())
}
fn get_mptt_voltage(&mut self) -> Result<Voltage> {
async fn get_mptt_voltage(&mut self) -> Result<Voltage> {
bail!("Please configure board revision")
}
fn get_mptt_current(&mut self) -> Result<Current> {
async fn get_mptt_current(&mut self) -> Result<Current> {
bail!("Please configure board revision")
}
}