fixed lifetime annotations + thread safty still needs work
This commit is contained in:
@@ -1,20 +1,44 @@
|
||||
use crate::hal::{deep_sleep, BackupHeader, BoardInteraction, Sensor};
|
||||
use crate::config::{BoardHardware, PlantControllerConfig};
|
||||
use crate::hal::battery::{BatteryInteraction, BatteryMonitor};
|
||||
use crate::hal::esp::ESP;
|
||||
use crate::hal::{deep_sleep, BackupHeader, BoardInteraction, Sensor, FreePeripherals};
|
||||
use esp_idf_hal::gpio::{IOPin, Pull};
|
||||
use anyhow::{bail, Result};
|
||||
use chrono::{DateTime, Utc};
|
||||
use embedded_hal::digital::OutputPin;
|
||||
use esp_idf_hal::gpio::{InputOutput, PinDriver};
|
||||
use crate::config::{BoardHardware, PlantControllerConfig};
|
||||
use crate::hal::battery::{BatteryInteraction, BatteryMonitor};
|
||||
use crate::hal::esp::ESP;
|
||||
|
||||
pub struct Initial<'a> {
|
||||
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>,
|
||||
}
|
||||
|
||||
impl BoardInteraction<'_> for Initial<'_> {
|
||||
fn get_esp<'a>(&mut self) -> &mut ESP<'a> {
|
||||
pub(crate) fn create_initial_board(
|
||||
free_pins: FreePeripherals,
|
||||
fs_mount_error: bool,
|
||||
config: PlantControllerConfig,
|
||||
esp: ESP<'static>,
|
||||
) -> Result<Box<dyn BoardInteraction<'static>> + Send + Sync> {
|
||||
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,
|
||||
battery: Box::new(BatteryMonitor::Disabled {}),
|
||||
};
|
||||
Ok(Box::new(v))
|
||||
}
|
||||
|
||||
impl<'a> BoardInteraction<'a> for Initial<'a> {
|
||||
fn get_esp(&mut self) -> &mut ESP<'a> {
|
||||
&mut self.esp
|
||||
}
|
||||
|
||||
@@ -22,11 +46,8 @@ impl BoardInteraction<'_> for Initial<'_> {
|
||||
&self.config
|
||||
}
|
||||
|
||||
fn get_battery_monitor(&mut self) -> Box<dyn BatteryInteraction> {
|
||||
let v = BatteryMonitor::Disabled {
|
||||
|
||||
};
|
||||
Box::new(v) as Box<dyn BatteryInteraction>
|
||||
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction> {
|
||||
&mut self.battery
|
||||
}
|
||||
|
||||
fn set_charge_indicator(&mut self, charging: bool) -> Result<()> {
|
||||
@@ -96,4 +117,4 @@ impl BoardInteraction<'_> for Initial<'_> {
|
||||
fn test(&mut self) -> Result<()> {
|
||||
bail!("Please configure board revision")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user