extract rtc module, extract tank module, fix backupview refresh, switch to embedded storage for eeprom
This commit is contained in:
@@ -4,8 +4,10 @@ mod initial_hal;
|
||||
mod rtc;
|
||||
mod v3_hal;
|
||||
mod v4_hal;
|
||||
mod water;
|
||||
|
||||
use crate::hal::rtc::{DS3231Module, RTCModuleInteraction};
|
||||
use crate::hal::water::TankSensor;
|
||||
use crate::{
|
||||
config::{BatteryBoardVersion, BoardVersion, PlantControllerConfig},
|
||||
hal::{
|
||||
@@ -18,7 +20,7 @@ use anyhow::{Ok, Result};
|
||||
use battery::BQ34Z100G1;
|
||||
use bq34z100::Bq34z100g1Driver;
|
||||
use ds323x::{DateTimeAccess, Ds323x};
|
||||
use eeprom24x::{Eeprom24x, SlaveAddr};
|
||||
use eeprom24x::{Eeprom24x, SlaveAddr, Storage};
|
||||
use embedded_hal_bus::i2c::MutexDevice;
|
||||
use esp_idf_hal::{
|
||||
adc::ADC1,
|
||||
@@ -85,6 +87,7 @@ pub struct HAL<'a> {
|
||||
}
|
||||
|
||||
pub trait BoardInteraction<'a> {
|
||||
fn get_tank_sensor(&mut self) -> Option<&mut TankSensor<'a>>;
|
||||
fn get_esp(&mut self) -> &mut Esp<'a>;
|
||||
fn get_config(&mut self) -> &PlantControllerConfig;
|
||||
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction + Send>;
|
||||
@@ -94,9 +97,6 @@ pub trait BoardInteraction<'a> {
|
||||
|
||||
fn is_day(&self) -> bool;
|
||||
//should be multsampled
|
||||
fn water_temperature_c(&mut self) -> Result<f32>;
|
||||
/// return median tank sensor value in milli volt
|
||||
fn tank_sensor_voltage(&mut self) -> Result<f32>;
|
||||
fn light(&mut self, enable: bool) -> Result<()>;
|
||||
fn pump(&mut self, plant: usize, enable: bool) -> Result<()>;
|
||||
fn fault(&mut self, plant: usize, enable: bool) -> Result<()>;
|
||||
@@ -265,7 +265,7 @@ impl PlantHal {
|
||||
let mut rtc = Ds323x::new_ds3231(MutexDevice::new(&I2C_DRIVER));
|
||||
|
||||
println!("Init rtc eeprom driver");
|
||||
let mut eeprom = {
|
||||
let eeprom = {
|
||||
Eeprom24x::new_24x32(
|
||||
MutexDevice::new(&I2C_DRIVER),
|
||||
SlaveAddr::Alternative(true, true, true),
|
||||
@@ -280,17 +280,10 @@ impl PlantHal {
|
||||
println!("Rtc Module could not be read {:?}", err);
|
||||
}
|
||||
}
|
||||
match eeprom.read_byte(0) {
|
||||
OkStd(byte) => {
|
||||
println!("Read first byte with status {}", byte);
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Eeprom could not read first byte {:?}", err);
|
||||
}
|
||||
}
|
||||
|
||||
let storage = Storage::new(eeprom, Delay::new(1000));
|
||||
let rtc_module: Box<dyn RTCModuleInteraction + Send> =
|
||||
Box::new(DS3231Module { rtc, eeprom }) as Box<dyn RTCModuleInteraction + Send>;
|
||||
Box::new(DS3231Module { rtc, storage }) as Box<dyn RTCModuleInteraction + Send>;
|
||||
|
||||
let hal = match config {
|
||||
Result::Ok(config) => {
|
||||
|
||||
Reference in New Issue
Block a user