get log to work, make time accessible
This commit is contained in:
@@ -18,13 +18,15 @@ use crate::{
|
||||
battery::{BatteryInteraction, NoBatteryMonitor},
|
||||
esp::Esp,
|
||||
},
|
||||
log::{log, LogMessage},
|
||||
log::{LogMessage},
|
||||
};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::format;
|
||||
use alloc::sync::Arc;
|
||||
use core::cell::OnceCell;
|
||||
use anyhow::{bail, Ok, Result};
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, FixedOffset, Utc};
|
||||
use embassy_executor::Spawner;
|
||||
//use battery::BQ34Z100G1;
|
||||
//use bq34z100::Bq34z100g1Driver;
|
||||
@@ -38,16 +40,22 @@ use measurements::{Current, Voltage};
|
||||
|
||||
use crate::hal::little_fs2storage_adapter::LittleFs2Filesystem;
|
||||
use embassy_sync::mutex::Mutex;
|
||||
use embassy_sync::once_lock::OnceLock;
|
||||
use esp_alloc as _;
|
||||
use esp_backtrace as _;
|
||||
use esp_bootloader_esp_idf::ota::Slot;
|
||||
use esp_hal::rng::Rng;
|
||||
use esp_hal::rtc_cntl::{Rtc, SocResetReason};
|
||||
use esp_hal::system::reset_reason;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use esp_storage::FlashStorage;
|
||||
use esp_wifi::{init, EspWifiController};
|
||||
use littlefs2::fs::{Allocation, Filesystem as lfs2Filesystem};
|
||||
use littlefs2::object_safe::DynStorage;
|
||||
use log::{info, warn};
|
||||
use crate::log::{LogArray, LOG_ACCESS};
|
||||
|
||||
pub static TIME_ACCESS: OnceLock<Rtc> = OnceLock::new();
|
||||
|
||||
//Only support for 8 right now!
|
||||
pub const PLANT_COUNT: usize = 8;
|
||||
@@ -181,6 +189,13 @@ impl PlantHal {
|
||||
|
||||
esp_alloc::heap_allocator!(size: 64 * 1024);
|
||||
esp_alloc::heap_allocator!(#[link_section = ".dram2_uninit"] size: 64000);
|
||||
|
||||
let rtc: Rtc = Rtc::new(peripherals.LPWR);
|
||||
match(TIME_ACCESS.init(rtc)){
|
||||
Result::Ok(_) => {}
|
||||
Err(_) => {}
|
||||
}
|
||||
|
||||
let systimer = SystemTimer::new(peripherals.SYSTIMER);
|
||||
|
||||
let boot_button = Input::new(
|
||||
@@ -335,36 +350,78 @@ impl PlantHal {
|
||||
//init,reset rtc memory depending on cause
|
||||
let mut init_rtc_store: bool = false;
|
||||
let mut to_config_mode: bool = false;
|
||||
let reasons = "";
|
||||
// let reasons = ResetReason::get();
|
||||
// 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,
|
||||
// };
|
||||
log(
|
||||
let reasons = match reset_reason() {
|
||||
None => {
|
||||
"unknown"
|
||||
}
|
||||
Some(reason) => {
|
||||
match reason {
|
||||
SocResetReason::ChipPowerOn => {
|
||||
"power on"
|
||||
}
|
||||
SocResetReason::CoreSw => {
|
||||
"software reset"
|
||||
}
|
||||
SocResetReason::CoreDeepSleep => {
|
||||
"deep sleep"
|
||||
}
|
||||
SocResetReason::CoreSDIO => {
|
||||
"sdio reset"
|
||||
}
|
||||
SocResetReason::CoreMwdt0 => {
|
||||
"Watchdog Main"
|
||||
}
|
||||
SocResetReason::CoreMwdt1 => {
|
||||
"Watchdog 1"
|
||||
}
|
||||
SocResetReason::CoreRtcWdt => {
|
||||
"Watchdog RTC"
|
||||
}
|
||||
SocResetReason::Cpu0Mwdt0 => {
|
||||
"Watchdog MCpu0"
|
||||
}
|
||||
SocResetReason::Cpu0Sw => {
|
||||
"software reset cpu0"
|
||||
}
|
||||
SocResetReason::Cpu0RtcWdt => {
|
||||
init_rtc_store = true;
|
||||
"Watchdog RTC cpu0"
|
||||
}
|
||||
SocResetReason::SysBrownOut => {
|
||||
"sys brown out"
|
||||
}
|
||||
SocResetReason::SysRtcWdt => {
|
||||
"Watchdog Sys rtc"
|
||||
}
|
||||
SocResetReason::Cpu0Mwdt1 => {
|
||||
"cpu0 mwdt1"
|
||||
}
|
||||
SocResetReason::SysSuperWdt => {
|
||||
"Watchdog Super"
|
||||
}
|
||||
SocResetReason::CoreEfuseCrc => {
|
||||
"core efuse crc"
|
||||
}
|
||||
SocResetReason::CoreUsbUart => {
|
||||
to_config_mode = true;
|
||||
"core usb uart"
|
||||
}
|
||||
SocResetReason::CoreUsbJtag => {
|
||||
"core usb jtag"
|
||||
}
|
||||
SocResetReason::Cpu0JtagCpu => {
|
||||
"cpu0 jtag cpu"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
LOG_ACCESS.lock().await.log(
|
||||
LogMessage::ResetReason,
|
||||
init_rtc_store as u32,
|
||||
to_config_mode as u32,
|
||||
"",
|
||||
&format!("{reasons:?}"),
|
||||
)
|
||||
.await;
|
||||
).await;
|
||||
|
||||
esp.init_rtc_deepsleep_memory(init_rtc_store, to_config_mode)
|
||||
.await;
|
||||
@@ -430,32 +487,32 @@ impl PlantHal {
|
||||
}
|
||||
};
|
||||
|
||||
let board_hal: Box<dyn BoardInteraction + Send> = match config.hardware.board {
|
||||
BoardVersion::INITIAL => {
|
||||
let board_hal: Box<dyn BoardInteraction + Send> = //match config.hardware.board {
|
||||
//BoardVersion::INITIAL => {
|
||||
initial_hal::create_initial_board(free_pins, config, esp)?
|
||||
}
|
||||
;
|
||||
//}
|
||||
// BoardVersion::V3 => {
|
||||
// v3_hal::create_v3(free_pins, esp, config, battery_interaction, rtc_module)?
|
||||
// }
|
||||
// BoardVersion::V4 => {
|
||||
// v4_hal::create_v4(free_pins, esp, config, battery_interaction, rtc_module)?
|
||||
// }
|
||||
_ => {
|
||||
todo!()
|
||||
}
|
||||
};
|
||||
//BoardVersion::V4 => {
|
||||
// v4_hal::create_v4(free_pins, esp, config, battery_interaction, rtc_module)?
|
||||
//}
|
||||
//_ => {
|
||||
// todo!()
|
||||
//}
|
||||
//};
|
||||
|
||||
HAL { board_hal }
|
||||
}
|
||||
Err(err) => {
|
||||
log(
|
||||
LOG_ACCESS.lock().await.log(
|
||||
LogMessage::ConfigModeMissingConfig,
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
&err.to_string(),
|
||||
)
|
||||
.await;
|
||||
).await;
|
||||
HAL {
|
||||
board_hal: initial_hal::create_initial_board(
|
||||
free_pins,
|
||||
@@ -469,3 +526,12 @@ impl PlantHal {
|
||||
Ok(Mutex::new(hal))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub async fn esp_time() -> DateTime<Utc> {
|
||||
DateTime::from_timestamp_micros(TIME_ACCESS.get().await.current_time_us() as i64).unwrap()
|
||||
}
|
||||
|
||||
pub async fn esp_set_time(time: DateTime<FixedOffset>) {
|
||||
TIME_ACCESS.get().await.set_current_time_us(time.timestamp_micros() as u64);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user