rework card storage to use nvs
This commit was merged in pull request #60.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use base64::prelude::*;
|
||||
use core::fmt::Display;
|
||||
use esp_nvs::Key;
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use num_enum::FromPrimitive;
|
||||
@@ -22,6 +24,38 @@ pub struct RawCard {
|
||||
pub _padding: [u8; 2],
|
||||
}
|
||||
|
||||
impl Default for RawCard {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
event_encoding: Default::default(),
|
||||
card_type: Default::default(),
|
||||
card_uuid: Default::default(),
|
||||
_reserved: Default::default(),
|
||||
sprite: [0; 722],
|
||||
packed_card_text: [0; 54],
|
||||
secret: Default::default(),
|
||||
_opaque_trailer: [0; 49],
|
||||
_padding: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RawCard {
|
||||
pub fn get_uuid(&self) -> u32 {
|
||||
((u16::from_ne_bytes(self.event_encoding) as u32) << 16)
|
||||
| (u16::from_ne_bytes(self.card_uuid) as u32)
|
||||
}
|
||||
|
||||
pub fn get_nvs_key(&self) -> Key {
|
||||
let uuid = self.get_uuid();
|
||||
Self::nvs_key_from_uuid(uuid)
|
||||
}
|
||||
|
||||
pub fn nvs_key_from_uuid(uuid: u32) -> Key {
|
||||
let base64 = BASE64_STANDARD.encode(uuid.to_ne_bytes());
|
||||
Key::from_str(&base64)
|
||||
}
|
||||
}
|
||||
static_assertions::const_assert!(RawCard::SERIALIZED_SIZE.is_multiple_of(4));
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, FromPrimitive)]
|
||||
|
||||
Reference in New Issue
Block a user