eeprom read write
This commit is contained in:
@@ -136,6 +136,29 @@ fn get_config(
|
||||
anyhow::Ok(Some(json))
|
||||
}
|
||||
|
||||
fn backup_config(
|
||||
request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let all = read_up_to_bytes_from_request(request, Some(3072))?;
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
board.backup_config(&all)?;
|
||||
anyhow::Ok(Some("saved".to_owned()))
|
||||
}
|
||||
|
||||
fn get_backup_config(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
let json = match board.get_backup_config() {
|
||||
Ok(config) => std::str::from_utf8(&config)?.to_owned(),
|
||||
Err(err) => {
|
||||
println!("Error get backup config {:?}", err);
|
||||
err.to_string()
|
||||
}
|
||||
};
|
||||
anyhow::Ok(Some(json))
|
||||
}
|
||||
|
||||
fn set_config(
|
||||
request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
@@ -353,12 +376,22 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
handle_error_to500(request, get_config)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/get_backup_config", Method::Get, move |request| {
|
||||
handle_error_to500(request, get_backup_config)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
server
|
||||
.fn_handler("/set_config", Method::Post, move |request| {
|
||||
handle_error_to500(request, set_config)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/backup_config", Method::Post, move |request| {
|
||||
handle_error_to500(request, backup_config)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/files", Method::Get, move |request| {
|
||||
handle_error_to500(request, list_files)
|
||||
|
Reference in New Issue
Block a user