add initial flashing of batery and 3.1 adjustments

This commit is contained in:
2024-07-31 20:45:06 +02:00
parent f0e0781100
commit 3ece894592
14 changed files with 12337 additions and 11019 deletions

View File

@@ -1,13 +1,13 @@
//offer ota and config mode
use std::{
str::from_utf8,
sync::{atomic::AtomicBool, Arc},
io::BufRead, str::from_utf8, sync::{atomic::AtomicBool, Arc}
};
use crate::{espota::OtaUpdate, BOARD_ACCESS};
use core::result::Result::Ok;
use embedded_svc::http::Method;
use esp_idf_hal::{delay::Delay, io::Write};
use esp_idf_svc::http::server::{Configuration, EspHttpServer};
use heapless::String;
use serde::{Deserialize, Serialize};
@@ -289,4 +289,46 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
})
.unwrap();
server
.fn_handler("/flashbattery", Method::Post, move |request| {
let mut board = BOARD_ACCESS.lock().unwrap();
let mut response = request.into_ok_response().unwrap();
let delay = Delay::new(0);
let firmware = include_bytes!("0100_2_02-bq34z100.df.fs");
response.write("Checking pass: \n".as_bytes()).unwrap();
for iter in firmware.lines() {
delay.delay_us(1);
let line = iter?;
let msg = format!("{line}<br>");
println!("{line}");
response.write(msg.as_bytes()).unwrap();
let validate = board.flash_bq34_z100(&line, true);
if validate.is_err() {
response.write(validate.unwrap_err().to_string().as_bytes()).unwrap();
}
}
response.write("Executing flashing: \n".as_bytes()).unwrap();
let mut toggle = true;
for iter in firmware.lines() {
delay.delay_us(1);
let line = iter?;
let msg = format!("{line}<br>");
println!("{line}");
response.write(msg.as_bytes()).unwrap();
board.general_fault(toggle);
toggle = !toggle;
let write = board.flash_bq34_z100(&line, false);
if write.is_err() {
response.write(write.unwrap_err().to_string().as_bytes()).unwrap();
}
}
board.general_fault(false);
anyhow::Ok(())
})
.unwrap();
server
}