fixed lifetime annotations + thread safty still needs work

This commit is contained in:
2025-06-19 18:17:29 +02:00
parent fc1991523a
commit e2cbf9618e
5 changed files with 110 additions and 83 deletions

View File

@@ -1,5 +1,10 @@
use crate::config::PlantControllerConfig;
use crate::hal::battery::{BatteryInteraction, BatteryMonitor};
use crate::hal::esp::ESP;
use crate::hal::{deep_sleep, BackupHeader, BoardInteraction, FreePeripherals, Sensor, V3Constants, I2C_DRIVER, PLANT_COUNT, REPEAT_MOIST_MEASURE, TANK_MULTI_SAMPLE, X25};
use crate::hal::{
deep_sleep, BackupHeader, BoardInteraction, FreePeripherals, Sensor, V3Constants, I2C_DRIVER,
PLANT_COUNT, REPEAT_MOIST_MEASURE, TANK_MULTI_SAMPLE, X25,
};
use crate::log::{log, LogMessage};
use anyhow::{anyhow, bail, Ok, Result};
use chrono::{DateTime, Utc};
@@ -8,19 +13,20 @@ use ds323x::{DateTimeAccess, Ds323x};
use eeprom24x::{Eeprom24x, Eeprom24xTrait, SlaveAddr};
use embedded_hal::digital::OutputPin;
use embedded_hal_bus::i2c::MutexDevice;
use esp_idf_hal::adc::oneshot::config::AdcChannelConfig;
use esp_idf_hal::adc::oneshot::{AdcChannelDriver, AdcDriver};
use esp_idf_hal::adc::{attenuation, Resolution};
use esp_idf_hal::delay::Delay;
use esp_idf_hal::gpio::{AnyInputPin, Gpio5, IOPin, InputOutput, PinDriver, Pull};
use esp_idf_hal::i2c::I2cDriver;
use esp_idf_hal::pcnt::{PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex};
use esp_idf_hal::pcnt::{
PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex,
};
use esp_idf_sys::{gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError};
use one_wire_bus::OneWire;
use plant_ctrl2::sipo::ShiftRegister40;
use std::result::Result::Ok as OkStd;
use esp_idf_hal::adc::{attenuation, Resolution};
use esp_idf_hal::adc::oneshot::config::AdcChannelConfig;
use crate::config::PlantControllerConfig;
use crate::hal::battery::{BatteryInteraction, BatteryMonitor};
use std::sync::Arc;
const PUMP8_BIT: usize = 0;
const PUMP1_BIT: usize = 1;
@@ -96,7 +102,12 @@ pub struct V3<'a> {
>,
}
pub(crate) fn create_v3(peripherals: FreePeripherals, esp: ESP, config: PlantControllerConfig, battery_monitor: Box<dyn BatteryInteraction>) -> Result<Box<dyn BoardInteraction + '_>> {
pub(crate) fn create_v3(
peripherals: FreePeripherals,
esp: ESP<'static>,
config: PlantControllerConfig,
battery_monitor: Box<dyn BatteryInteraction>,
) -> Result<Box<dyn BoardInteraction + '_ + Send + Sync>> {
let mut clock = PinDriver::input_output(peripherals.gpio15.downgrade())?;
clock.set_pull(Pull::Floating)?;
let mut latch = PinDriver::input_output(peripherals.gpio3.downgrade())?;
@@ -235,8 +246,8 @@ pub(crate) fn create_v3(peripherals: FreePeripherals, esp: ESP, config: PlantCon
}))
}
impl BoardInteraction<'_> for V3<'_> {
fn get_esp(&mut self) -> &mut ESP<'static> {
impl<'a> BoardInteraction<'a> for V3<'a> {
fn get_esp(&mut self) -> &mut ESP<'a> {
&mut self.esp
}
@@ -618,4 +629,4 @@ impl BoardInteraction<'_> for V3<'_> {
self.esp.delay.delay_ms(10);
Ok(())
}
}
}