adust pcb to new 3.3 software improvements
This commit is contained in:
@@ -53,7 +53,7 @@ use esp_idf_sys::{esp, esp_spiffs_check, gpio_hold_dis, gpio_hold_en, vTaskDelay
|
||||
use one_wire_bus::OneWire;
|
||||
|
||||
use crate::config::{self, PlantControllerConfig};
|
||||
use crate::{plant_hal, STAY_ALIVE};
|
||||
use crate::{plant_hal, to_string, STAY_ALIVE};
|
||||
|
||||
//Only support for 8 right now!
|
||||
pub const PLANT_COUNT: usize = 8;
|
||||
@@ -117,6 +117,9 @@ static mut CONSECUTIVE_WATERING_PLANT: [u32; PLANT_COUNT] = [0; PLANT_COUNT];
|
||||
#[link_section = ".rtc.data"]
|
||||
static mut LOW_VOLTAGE_DETECTED: bool = false;
|
||||
|
||||
#[link_section = ".rtc.data"]
|
||||
static mut RESTART_TO_CONF: bool = false;
|
||||
|
||||
pub struct FileSystemSizeInfo {
|
||||
pub total_size: usize,
|
||||
pub used_size: usize,
|
||||
@@ -180,7 +183,33 @@ pub struct FileList {
|
||||
iter_error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct BatteryState {
|
||||
voltage_milli_volt: String,
|
||||
current_milli_ampere: String,
|
||||
cycle_count: String,
|
||||
design_milli_ampere: String,
|
||||
remaining_milli_ampere: String,
|
||||
state_of_charge: String,
|
||||
state_of_health: String,
|
||||
temperature: String,
|
||||
}
|
||||
|
||||
impl PlantCtrlBoard<'_> {
|
||||
pub fn get_battery_state(&mut self) -> BatteryState {
|
||||
let bat = BatteryState {
|
||||
voltage_milli_volt: to_string(self.voltage_milli_volt()),
|
||||
current_milli_ampere: to_string(self.average_current_milli_ampere()),
|
||||
cycle_count: to_string(self.cycle_count()),
|
||||
design_milli_ampere: to_string(self.design_milli_ampere_hour()),
|
||||
remaining_milli_ampere: to_string(self.remaining_milli_ampere_hour()),
|
||||
state_of_charge: to_string(self.state_charge_percent()),
|
||||
state_of_health: to_string(self.state_health_percent()),
|
||||
temperature: to_string(self.bat_temperature()),
|
||||
};
|
||||
return bat;
|
||||
}
|
||||
|
||||
pub fn list_files(&self, filename: &str) -> FileList {
|
||||
let storage = CString::new(SPIFFS_PARTITION_NAME).unwrap();
|
||||
let error = unsafe {
|
||||
@@ -956,6 +985,16 @@ impl PlantCtrlBoard<'_> {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn get_restart_to_conf(&mut self) -> bool {
|
||||
return unsafe { RESTART_TO_CONF };
|
||||
}
|
||||
|
||||
pub fn set_restart_to_conf(&mut self, to_conf: bool) {
|
||||
unsafe {
|
||||
RESTART_TO_CONF = to_conf;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn state_charge_percent(&mut self) -> Result<u8> {
|
||||
match self.battery_driver.state_of_charge() {
|
||||
OkStd(r) => Ok(r),
|
||||
@@ -1012,6 +1051,13 @@ impl PlantCtrlBoard<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bat_temperature(&mut self) -> Result<u16> {
|
||||
match self.battery_driver.temperature() {
|
||||
OkStd(r) => Ok(r as u16),
|
||||
Err(err) => bail!("Error reading Temperature {:?}", err),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flash_bq34_z100(&mut self, line: &str, dryrun: bool) -> Result<()> {
|
||||
match self.battery_driver.write_flash_stream_i2c(line, dryrun) {
|
||||
OkStd(r) => Ok(r),
|
||||
@@ -1193,32 +1239,60 @@ impl PlantHal {
|
||||
ms4.set_high()?;
|
||||
|
||||
//init,reset rtc memory depending on cause
|
||||
let mut init_rtc_store: bool = false;
|
||||
let mut to_config_mode: bool = false;
|
||||
let reasons = ResetReason::get();
|
||||
let reset_store = match reasons {
|
||||
ResetReason::Software => false,
|
||||
ResetReason::ExternalPin => false,
|
||||
ResetReason::Watchdog => true,
|
||||
ResetReason::Sdio => true,
|
||||
ResetReason::Panic => true,
|
||||
ResetReason::InterruptWatchdog => true,
|
||||
ResetReason::PowerOn => true,
|
||||
ResetReason::Unknown => true,
|
||||
ResetReason::Brownout => true,
|
||||
ResetReason::TaskWatchdog => true,
|
||||
ResetReason::DeepSleep => false,
|
||||
ResetReason::USBPeripheral => true,
|
||||
ResetReason::JTAG => true,
|
||||
match reasons {
|
||||
ResetReason::Software => {},
|
||||
ResetReason::ExternalPin => {},
|
||||
ResetReason::Watchdog => {
|
||||
init_rtc_store = true;
|
||||
},
|
||||
ResetReason::Sdio => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
ResetReason::Panic => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
ResetReason::InterruptWatchdog => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
ResetReason::PowerOn => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
ResetReason::Unknown => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
ResetReason::Brownout => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
ResetReason::TaskWatchdog => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
ResetReason::DeepSleep => {},
|
||||
ResetReason::USBPeripheral => {
|
||||
init_rtc_store = true;
|
||||
to_config_mode = true;
|
||||
},
|
||||
ResetReason::JTAG => {
|
||||
init_rtc_store = true
|
||||
},
|
||||
};
|
||||
if reset_store {
|
||||
println!("Clear and reinit RTC store");
|
||||
println!("Reset due to {:?} requires rtc clear {} and force config mode {}", reasons, init_rtc_store, to_config_mode);
|
||||
if init_rtc_store {
|
||||
unsafe {
|
||||
LAST_WATERING_TIMESTAMP = [0; PLANT_COUNT];
|
||||
CONSECUTIVE_WATERING_PLANT = [0; PLANT_COUNT];
|
||||
LOW_VOLTAGE_DETECTED = false;
|
||||
RESTART_TO_CONF = to_config_mode;
|
||||
};
|
||||
} else {
|
||||
println!("Keeping RTC store");
|
||||
unsafe {
|
||||
if to_config_mode{
|
||||
RESTART_TO_CONF = true;
|
||||
}
|
||||
println!("Current restart to conf mode{:?}", RESTART_TO_CONF);
|
||||
|
||||
println!(
|
||||
"Current low voltage detection is {:?}",
|
||||
LOW_VOLTAGE_DETECTED
|
||||
|
||||
Reference in New Issue
Block a user