remove: eliminate file management and LittleFS-based filesystem, implement savegame management for JSON config slots with wear-leveling
This commit is contained in:
@@ -114,12 +114,39 @@ pub(crate) async fn get_version_web<T, const N: usize>(
|
||||
Ok(Some(serde_json::to_string(&get_version(&mut board).await)?))
|
||||
}
|
||||
|
||||
/// Return the current in-memory config, or — when `saveidx` is `Some(idx)` —
|
||||
/// the JSON stored in save slot `idx`.
|
||||
pub(crate) async fn get_config<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
saveidx: Option<usize>,
|
||||
) -> FatResult<Option<String>> {
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let json = match saveidx {
|
||||
None => serde_json::to_string(board.board_hal.get_config())?,
|
||||
Some(idx) => {
|
||||
board.board_hal.get_esp().load_config_slot(idx).await?
|
||||
}
|
||||
};
|
||||
Ok(Some(json))
|
||||
}
|
||||
|
||||
/// Return a JSON array describing every valid save slot on flash.
|
||||
pub(crate) async fn list_saves<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
) -> FatResult<Option<String>> {
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let json = serde_json::to_string(&board.board_hal.get_config())?;
|
||||
Ok(Some(json))
|
||||
let saves = board.board_hal.get_esp().list_saves().await?;
|
||||
Ok(Some(serde_json::to_string(&saves)?))
|
||||
}
|
||||
|
||||
/// Erase (delete) a single save slot by index.
|
||||
pub(crate) async fn delete_save<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
idx: usize,
|
||||
) -> FatResult<Option<String>> {
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
board.board_hal.get_esp().delete_save_slot(idx).await?;
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub(crate) async fn get_battery_state<T, const N: usize>(
|
||||
|
||||
Reference in New Issue
Block a user