refactor: move storage initialization to the start_config function
This commit is contained in:
+15
-16
@@ -6,7 +6,7 @@ use esp_hal::peripherals::FLASH;
|
|||||||
use esp_storage::FlashStorage;
|
use esp_storage::FlashStorage;
|
||||||
use int_enum::IntEnum;
|
use int_enum::IntEnum;
|
||||||
use sequential_storage::{
|
use sequential_storage::{
|
||||||
cache::Cache,
|
cache::{Cache, Uncached},
|
||||||
map::{Key, MapConfig, MapStorage, SerializationError},
|
map::{Key, MapConfig, MapStorage, SerializationError},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -21,18 +21,18 @@ impl ConfigCommand {
|
|||||||
pub static CONFIG_SERVICE: RpcService<CriticalSectionRawMutex, ConfigCommand, ()> =
|
pub static CONFIG_SERVICE: RpcService<CriticalSectionRawMutex, ConfigCommand, ()> =
|
||||||
RpcService::new();
|
RpcService::new();
|
||||||
|
|
||||||
pub fn start_config(spawner: Spawner, flash: FLASH<'static>) {
|
pub async fn start_config(spawner: Spawner, flash: FLASH<'static>) {
|
||||||
spawner.spawn(config_handler(flash).unwrap());
|
let storage = MapStorage::<ConfigKey, _, _>::new(
|
||||||
}
|
|
||||||
|
|
||||||
#[embassy_executor::task]
|
|
||||||
async fn config_handler(flash: FLASH<'static>) {
|
|
||||||
let mut storage = MapStorage::<ConfigKey, _, _>::new(
|
|
||||||
BlockingAsync::new(FlashStorage::new(flash)),
|
BlockingAsync::new(FlashStorage::new(flash)),
|
||||||
const { MapConfig::new(0x3F_0000..0x40_0000) },
|
const { MapConfig::new(0x3F_0000..0x40_0000) },
|
||||||
Cache::new_uncached(),
|
Cache::new_uncached(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
spawner.spawn(config_handler(storage).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn config_handler(mut storage: MapStorage<ConfigKey, BlockingAsync<FlashStorage<'static>>, Cache<Uncached, Uncached, Uncached, ConfigKey>>) {
|
||||||
let mut data_buffer = [0u8; 256];
|
let mut data_buffer = [0u8; 256];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@@ -40,14 +40,13 @@ async fn config_handler(flash: FLASH<'static>) {
|
|||||||
|
|
||||||
match req {
|
match req {
|
||||||
ConfigCommand::SetStationCreds() => {
|
ConfigCommand::SetStationCreds() => {
|
||||||
todo!()
|
if storage
|
||||||
// if storage
|
.store_item(&mut data_buffer, &ConfigKey::Wifi, &256)
|
||||||
// .store_item(&mut data_buffer, &ConfigKey::Wifi, )
|
.await
|
||||||
// .await
|
.is_ok()
|
||||||
// .is_ok()
|
{
|
||||||
// {
|
served.respond(());
|
||||||
// served.respond(());
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user