startup and ota state detection working, now wifi_ap next

This commit is contained in:
2025-09-13 20:56:11 +02:00
parent 4160202cdc
commit be3c4a5095
9 changed files with 294 additions and 225 deletions

View File

@@ -4,8 +4,10 @@ use alloc::vec::Vec;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::lazy_lock::LazyLock;
use embassy_sync::mutex::Mutex;
use embassy_time::Instant;
use log::info;
use serde::Serialize;
use strum_macros::{EnumIter, IntoStaticStr};
use strum_macros::IntoStaticStr;
use ringbuffer::{ConstGenericRingBuffer, RingBuffer};
use unit_enum::UnitEnum;
@@ -19,8 +21,9 @@ const BUFFER_SIZE: usize = 220;
static mut BUFFER: ConstGenericRingBuffer<LogEntry, BUFFER_SIZE> =
ConstGenericRingBuffer::<LogEntry, BUFFER_SIZE>::new();
#[allow(static_mut_refs)]
static BUFFER_ACCESS: LazyLock<Mutex<CriticalSectionRawMutex,&mut ConstGenericRingBuffer<LogEntry, BUFFER_SIZE>>> =
LazyLock::new(|| unsafe { Mutex::new(&mut BUFFER) });
static BUFFER_ACCESS: LazyLock<
Mutex<CriticalSectionRawMutex, &mut ConstGenericRingBuffer<LogEntry, BUFFER_SIZE>>,
> = LazyLock::new(|| unsafe { Mutex::new(&mut BUFFER) });
#[derive(Serialize, Debug, Clone)]
pub struct LogEntry {
@@ -69,7 +72,13 @@ pub async fn get_log() -> Vec<LogEntry> {
read_copy
}
pub async fn log(message_key: LogMessage, number_a: u32, number_b: u32, txt_short: &str, txt_long: &str) {
pub async fn log(
message_key: LogMessage,
number_a: u32,
number_b: u32,
txt_short: &str,
txt_long: &str,
) {
let mut txt_short_stack: heapless::String<TXT_SHORT_LENGTH> = heapless::String::new();
let mut txt_long_stack: heapless::String<TXT_LONG_LENGTH> = heapless::String::new();
@@ -77,27 +86,18 @@ pub async fn log(message_key: LogMessage, number_a: u32, number_b: u32, txt_shor
limit_length(txt_long, &mut txt_long_stack);
//TODO
let time = 0;
let time = Instant::now().as_secs();
// let time = EspSystemTime {}.now().as_millis() as u64;
//
let ordinal = message_key.ordinal() as u16;
// let template_string: &str = message_key.into();
//
// let mut values: HashMap<&str, &str> = HashMap::new();
// let number_a_str = number_a.to_string();
// let number_b_str = number_b.to_string();
//
// values.insert("number_a", &number_a_str);
// values.insert("number_b", &number_b_str);
// values.insert("txt_short", txt_short);
// values.insert("txt_long", txt_long);
//
// let template = Template::from(template_string);
// let serial_entry = template.fill_in(&values);
//
// log::info!("{serial_entry}");
// //TODO push to mqtt?
let template: &str = message_key.into();
let mut template_string = template.to_string();
template_string = template_string.replace("${number_a}", number_a.to_string().as_str());
template_string = template_string.replace("${number_b}", number_b.to_string().as_str());
template_string = template_string.replace("${txt_long}", txt_long);
template_string = template_string.replace("${txt_short}", txt_short);
info!("LOG: {} : {}", time, template_string);
let entry = LogEntry {
timestamp: time,