fix tread safty issues by annotating Box Traits correctly
This commit is contained in:
parent
e2cbf9618e
commit
69077239a5
@ -12,7 +12,7 @@ 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) esp: ESP<'a>,
|
||||||
pub(crate) config: PlantControllerConfig,
|
pub(crate) config: PlantControllerConfig,
|
||||||
pub(crate) battery: Box<dyn BatteryInteraction>,
|
pub(crate) battery: Box<dyn BatteryInteraction + Send>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_initial_board(
|
pub(crate) fn create_initial_board(
|
||||||
@ -20,7 +20,7 @@ pub(crate) fn create_initial_board(
|
|||||||
fs_mount_error: bool,
|
fs_mount_error: bool,
|
||||||
config: PlantControllerConfig,
|
config: PlantControllerConfig,
|
||||||
esp: ESP<'static>,
|
esp: ESP<'static>,
|
||||||
) -> Result<Box<dyn BoardInteraction<'static>> + Send + Sync> {
|
) -> Result<Box<dyn BoardInteraction<'static> + Send>> {
|
||||||
let mut general_fault = PinDriver::input_output(free_pins.gpio6.downgrade())?;
|
let mut general_fault = PinDriver::input_output(free_pins.gpio6.downgrade())?;
|
||||||
general_fault.set_pull(Pull::Floating)?;
|
general_fault.set_pull(Pull::Floating)?;
|
||||||
general_fault.set_low()?;
|
general_fault.set_low()?;
|
||||||
@ -46,7 +46,7 @@ impl<'a> BoardInteraction<'a> for Initial<'a> {
|
|||||||
&self.config
|
&self.config
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction> {
|
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction + Send> {
|
||||||
&mut self.battery
|
&mut self.battery
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ pub enum Sensor {
|
|||||||
pub struct PlantHal {}
|
pub struct PlantHal {}
|
||||||
|
|
||||||
pub struct HAL<'a> {
|
pub struct HAL<'a> {
|
||||||
pub board_hal: Box<dyn BoardInteraction<'a> + Sync + Send>,
|
pub board_hal: Box<dyn BoardInteraction<'a> + Send>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
@ -116,7 +116,7 @@ impl Default for BackupHeader {
|
|||||||
pub trait BoardInteraction<'a> {
|
pub trait BoardInteraction<'a> {
|
||||||
fn get_esp(&mut self) -> &mut ESP<'a>;
|
fn get_esp(&mut self) -> &mut ESP<'a>;
|
||||||
fn get_config(&mut self) -> &PlantControllerConfig;
|
fn get_config(&mut self) -> &PlantControllerConfig;
|
||||||
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction>;
|
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction + Send>;
|
||||||
fn set_charge_indicator(&mut self, charging: bool) -> Result<()>;
|
fn set_charge_indicator(&mut self, charging: bool) -> Result<()>;
|
||||||
fn deep_sleep(&mut self, duration_in_ms: u64) -> !;
|
fn deep_sleep(&mut self, duration_in_ms: u64) -> !;
|
||||||
fn get_backup_info(&mut self) -> Result<BackupHeader>;
|
fn get_backup_info(&mut self) -> Result<BackupHeader>;
|
||||||
@ -304,9 +304,9 @@ impl PlantHal {
|
|||||||
}
|
}
|
||||||
BatteryBoardVersion::WchI2cSlave => BatteryMonitor::WchI2cSlave {},
|
BatteryBoardVersion::WchI2cSlave => BatteryMonitor::WchI2cSlave {},
|
||||||
};
|
};
|
||||||
let battery_interaction = Box::new(battery_monitor) as Box<dyn BatteryInteraction>;
|
let battery_interaction = Box::new(battery_monitor) as Box<dyn BatteryInteraction + Send>;
|
||||||
|
|
||||||
let board_hal: Box<dyn BoardInteraction> = match config.hardware.board {
|
let board_hal: Box<dyn BoardInteraction + Send> = match config.hardware.board {
|
||||||
BoardVersion::INITIAL => {
|
BoardVersion::INITIAL => {
|
||||||
initial_hal::create_initial_board(free_pins, fs_mount_error, config, esp)?
|
initial_hal::create_initial_board(free_pins, fs_mount_error, config, esp)?
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ const FAULT_2: usize = 23;
|
|||||||
|
|
||||||
pub struct V3<'a> {
|
pub struct V3<'a> {
|
||||||
config: PlantControllerConfig,
|
config: PlantControllerConfig,
|
||||||
battery_monitor: Box<dyn BatteryInteraction>,
|
battery_monitor: Box<dyn BatteryInteraction + Send>,
|
||||||
esp: ESP<'a>,
|
esp: ESP<'a>,
|
||||||
shift_register: ShiftRegister40<
|
shift_register: ShiftRegister40<
|
||||||
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
|
PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
|
||||||
@ -106,8 +106,8 @@ pub(crate) fn create_v3(
|
|||||||
peripherals: FreePeripherals,
|
peripherals: FreePeripherals,
|
||||||
esp: ESP<'static>,
|
esp: ESP<'static>,
|
||||||
config: PlantControllerConfig,
|
config: PlantControllerConfig,
|
||||||
battery_monitor: Box<dyn BatteryInteraction>,
|
battery_monitor: Box<dyn BatteryInteraction + Send>,
|
||||||
) -> Result<Box<dyn BoardInteraction + '_ + Send + Sync>> {
|
) -> Result<Box<dyn BoardInteraction + 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())?;
|
||||||
@ -255,7 +255,7 @@ impl<'a> BoardInteraction<'a> for V3<'a> {
|
|||||||
&self.config
|
&self.config
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_battery_monitor(&mut self) -> &mut Box<(dyn BatteryInteraction + 'static)> {
|
fn get_battery_monitor(&mut self) -> &mut Box<(dyn BatteryInteraction + Send + 'static)> {
|
||||||
&mut self.battery_monitor
|
&mut self.battery_monitor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ const SENSOR_ON: u8 = 5_u8;
|
|||||||
|
|
||||||
pub struct V4<'a> {
|
pub struct V4<'a> {
|
||||||
esp: ESP<'a>,
|
esp: ESP<'a>,
|
||||||
battery_monitor: Box<dyn BatteryInteraction>,
|
battery_monitor: Box<dyn BatteryInteraction + Send>,
|
||||||
config: PlantControllerConfig,
|
config: PlantControllerConfig,
|
||||||
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>,
|
||||||
@ -63,8 +63,8 @@ pub(crate) fn create_v4(
|
|||||||
peripherals: FreePeripherals,
|
peripherals: FreePeripherals,
|
||||||
esp: ESP<'static>,
|
esp: ESP<'static>,
|
||||||
config: PlantControllerConfig,
|
config: PlantControllerConfig,
|
||||||
battery_monitor: Box<dyn BatteryInteraction>,
|
battery_monitor: Box<dyn BatteryInteraction + Send>,
|
||||||
) -> anyhow::Result<Box<dyn BoardInteraction + '_ + Send + Sync>> {
|
) -> anyhow::Result<Box<dyn BoardInteraction + Send + '_>> {
|
||||||
let mut awake = PinDriver::output(peripherals.gpio15.downgrade())?;
|
let mut awake = PinDriver::output(peripherals.gpio15.downgrade())?;
|
||||||
awake.set_high()?;
|
awake.set_high()?;
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
|||||||
&self.config
|
&self.config
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction> {
|
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction + Send> {
|
||||||
&mut self.battery_monitor
|
&mut self.battery_monitor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ use tank::*;
|
|||||||
use crate::config::BoardVersion::INITIAL;
|
use crate::config::BoardVersion::INITIAL;
|
||||||
use crate::hal::{BoardInteraction, PlantHal, HAL, PLANT_COUNT};
|
use crate::hal::{BoardInteraction, PlantHal, HAL, PLANT_COUNT};
|
||||||
use crate::hal::battery::BatteryInteraction;
|
use crate::hal::battery::BatteryInteraction;
|
||||||
pub static BOARD_ACCESS: Lazy<Arc<Mutex<HAL>>> = Lazy::new(|| Arc::new(PlantHal::create().unwrap()));
|
pub static BOARD_ACCESS: Lazy<Mutex<HAL>> = Lazy::new(|| PlantHal::create().unwrap());
|
||||||
pub static STAY_ALIVE: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
|
pub static STAY_ALIVE: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
|
||||||
|
|
||||||
mod webserver {
|
mod webserver {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user