refactor battery state
This commit is contained in:
@@ -4,6 +4,7 @@ mod initial_hal;
|
||||
mod v3_hal;
|
||||
mod v4_hal;
|
||||
|
||||
use battery::BQ34Z100G1;
|
||||
use bq34z100::Bq34z100g1Driver;
|
||||
|
||||
use crate::log::LogMessage;
|
||||
@@ -35,7 +36,7 @@ use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::config::{BatteryBoardVersion, BoardVersion, PlantControllerConfig};
|
||||
use crate::hal::battery::{print_battery_bq34z100, BatteryInteraction, BatteryMonitor};
|
||||
use crate::hal::battery::{print_battery_bq34z100, BatteryInteraction, NoBatteryMonitor};
|
||||
use crate::hal::esp::ESP;
|
||||
use crate::hal::initial_hal::Initial;
|
||||
use crate::log::log;
|
||||
@@ -280,8 +281,8 @@ impl PlantHal {
|
||||
|
||||
let hal = match config {
|
||||
Result::Ok(config) => {
|
||||
let battery_monitor: BatteryMonitor = match config.hardware.battery {
|
||||
BatteryBoardVersion::Disabled => BatteryMonitor::Disabled {},
|
||||
let battery_interaction: Box<dyn BatteryInteraction + Send> = match config.hardware.battery {
|
||||
BatteryBoardVersion::Disabled => Box::new(NoBatteryMonitor{}),
|
||||
BatteryBoardVersion::BQ34Z100G1 => {
|
||||
let mut battery_driver = Bq34z100g1Driver {
|
||||
i2c: MutexDevice::new(&I2C_DRIVER),
|
||||
@@ -301,12 +302,13 @@ impl PlantHal {
|
||||
);
|
||||
}
|
||||
}
|
||||
BatteryMonitor::BQ34Z100G1 { battery_driver }
|
||||
Box::new(BQ34Z100G1 { battery_driver })
|
||||
}
|
||||
BatteryBoardVersion::WchI2cSlave => BatteryMonitor::WchI2cSlave {},
|
||||
BatteryBoardVersion::WchI2cSlave => {
|
||||
// TODO use correct implementation once availible
|
||||
Box::new(NoBatteryMonitor{})
|
||||
},
|
||||
};
|
||||
let battery_interaction =
|
||||
Box::new(battery_monitor) as Box<dyn BatteryInteraction + Send>;
|
||||
|
||||
let board_hal: Box<dyn BoardInteraction + Send> = match config.hardware.board {
|
||||
BoardVersion::INITIAL => {
|
||||
|
||||
Reference in New Issue
Block a user