logging and pcb adjustment

This commit is contained in:
2025-02-14 23:50:19 +01:00
parent 1741bb0b53
commit aad1dbd458
15 changed files with 389 additions and 119 deletions

View File

@@ -9,6 +9,7 @@ use crate::{
};
use anyhow::bail;
use chrono::DateTime;
use esp_idf_sys::{esp_set_time_from_rtc, settimeofday, timeval, vTaskDelay};
use core::result::Result::Ok;
use embedded_svc::http::Method;
use esp_idf_hal::delay::Delay;
@@ -24,11 +25,6 @@ struct SSIDList<'a> {
ssids: Vec<&'a String<32>>,
}
#[derive(Serialize, Debug)]
struct FileList {
file: Vec<FileInfo>,
}
#[derive(Serialize, Debug)]
struct LoadData<'a> {
rtc: &'a str,
@@ -64,6 +60,12 @@ fn write_time(
let time: SetTime = serde_json::from_slice(&actual_data)?;
let parsed = DateTime::parse_from_rfc3339(time.time).map_err(|err| anyhow::anyhow!(err))?;
let mut board = BOARD_ACCESS.lock().unwrap();
let now = timeval {
tv_sec: parsed.to_utc().timestamp(),
tv_usec: 0
};
unsafe { settimeofday(&now, core::ptr::null_mut()) };
board.set_rtc_time(&parsed.to_utc())?;
anyhow::Ok(None)
}
@@ -440,6 +442,8 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
})
.unwrap();
unsafe { vTaskDelay(1) };
let reboot_now_for_exit = reboot_now.clone();
server
.fn_handler("/exit", Method::Post, move |_| {
@@ -462,19 +466,16 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
let mut buffer: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
let mut total_read: usize = 0;
loop {
unsafe { vTaskDelay(1) };
let read = std::io::Read::read(&mut file_handle, &mut buffer)?;
total_read += read;
println!(
"sending {read} bytes of {total_read} for file {}",
&filename
);
let to_write = &buffer[0..read];
response.write(to_write)?;
println!("wrote {read} bytes of {total_read} for file {filename}");
if read == 0 {
break;
}
}
println!("wrote {total_read} for file {filename}");
drop(file_handle);
response.flush()?;
}
@@ -588,6 +589,7 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
anyhow::Ok(())
})
.unwrap();
unsafe { vTaskDelay(1) };
server
.fn_handler("/", Method::Get, move |request| {
let mut response = request.into_ok_response()?;