fixed lifetime annotations + thread safty still needs work
This commit is contained in:
@@ -42,10 +42,9 @@ use crate::log::log;
|
||||
use embedded_hal::digital::OutputPin;
|
||||
use esp_idf_hal::delay::Delay;
|
||||
use esp_idf_hal::gpio::{
|
||||
Gpio0, Gpio1, Gpio10, Gpio11, Gpio12, Gpio13, Gpio14, Gpio15, Gpio16, Gpio17,
|
||||
Gpio18, Gpio2, Gpio21, Gpio22, Gpio23, Gpio24, Gpio25, Gpio26, Gpio27, Gpio28,
|
||||
Gpio29, Gpio3, Gpio30, Gpio4, Gpio5, Gpio6, Gpio7, Gpio8, IOPin,
|
||||
PinDriver, Pull,
|
||||
Gpio0, Gpio1, Gpio10, Gpio11, Gpio12, Gpio13, Gpio14, Gpio15, Gpio16, Gpio17, Gpio18, Gpio2,
|
||||
Gpio21, Gpio22, Gpio23, Gpio24, Gpio25, Gpio26, Gpio27, Gpio28, Gpio29, Gpio3, Gpio30, Gpio4,
|
||||
Gpio5, Gpio6, Gpio7, Gpio8, IOPin, PinDriver, Pull,
|
||||
};
|
||||
use esp_idf_hal::pcnt::PCNT0;
|
||||
use esp_idf_hal::prelude::Peripherals;
|
||||
@@ -63,11 +62,7 @@ pub static I2C_DRIVER: Lazy<Mutex<I2cDriver<'static>>> = Lazy::new(PlantHal::cre
|
||||
#[non_exhaustive]
|
||||
struct V3Constants;
|
||||
|
||||
impl V3Constants {
|
||||
|
||||
}
|
||||
|
||||
|
||||
impl V3Constants {}
|
||||
|
||||
const X25: crc::Crc<u16> = crc::Crc::<u16>::new(&crc::CRC_16_IBM_SDLC);
|
||||
|
||||
@@ -98,7 +93,7 @@ pub enum Sensor {
|
||||
pub struct PlantHal {}
|
||||
|
||||
pub struct HAL<'a> {
|
||||
pub board_hal: Box<dyn BoardInteraction<'a>>,
|
||||
pub board_hal: Box<dyn BoardInteraction<'a> + Sync + Send>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
@@ -282,8 +277,6 @@ impl PlantHal {
|
||||
|
||||
let config = esp.load_config();
|
||||
|
||||
|
||||
|
||||
let hal = match config {
|
||||
Result::Ok(config) => {
|
||||
let battery_monitor: BatteryMonitor = match config.hardware.battery {
|
||||
@@ -313,19 +306,19 @@ impl PlantHal {
|
||||
};
|
||||
let battery_interaction = Box::new(battery_monitor) as Box<dyn BatteryInteraction>;
|
||||
|
||||
|
||||
let board_hal: Box<dyn BoardInteraction> = match config.hardware.board {
|
||||
BoardVersion::INITIAL => {
|
||||
Self::create_initial_board(free_pins, fs_mount_error, config, esp)?
|
||||
initial_hal::create_initial_board(free_pins, fs_mount_error, config, esp)?
|
||||
}
|
||||
BoardVersion::V3 => {
|
||||
v3_hal::create_v3(free_pins, esp, config, battery_interaction)?
|
||||
}
|
||||
BoardVersion::V4 => {
|
||||
v4_hal::create_v4(free_pins, esp, config, battery_interaction)?
|
||||
}
|
||||
BoardVersion::V3 => v3_hal::create_v3(free_pins,esp, config, battery_interaction)?,
|
||||
BoardVersion::V4 => v4_hal::create_v4(free_pins,esp,config,battery_interaction)?,
|
||||
};
|
||||
|
||||
|
||||
HAL {
|
||||
board_hal
|
||||
}
|
||||
HAL { board_hal }
|
||||
}
|
||||
Err(err) => {
|
||||
log(
|
||||
@@ -336,30 +329,16 @@ impl PlantHal {
|
||||
&err.to_string(),
|
||||
);
|
||||
HAL {
|
||||
board_hal:Self::create_initial_board(free_pins, fs_mount_error, PlantControllerConfig::default(), esp )?
|
||||
board_hal: initial_hal::create_initial_board(
|
||||
free_pins,
|
||||
fs_mount_error,
|
||||
PlantControllerConfig::default(),
|
||||
esp,
|
||||
)?,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Mutex::new(hal))
|
||||
}
|
||||
|
||||
fn create_initial_board(free_pins: FreePeripherals, fs_mount_error: bool, config: PlantControllerConfig, esp: ESP) -> Result<Box<dyn BoardInteraction<'static>>> {
|
||||
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,
|
||||
config,
|
||||
esp
|
||||
};
|
||||
Ok(Box::new(v))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user