wip: add flash info view
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use crate::storage::cardstore::CardStore;
|
||||
use embedded_hal_bus::i2c::AtomicDevice;
|
||||
use esp_hal::rtc_cntl::Rtc;
|
||||
use esp_hal::{Blocking, i2c::master::I2c, time::Instant};
|
||||
|
||||
use crate::{
|
||||
@@ -14,6 +16,8 @@ use crate::{
|
||||
)]
|
||||
pub async fn nfc_scanner(
|
||||
mut nfc_driver: NfcPn532Driver<AtomicDevice<'static, I2c<'static, Blocking>>>,
|
||||
mut card_store: CardStore,
|
||||
rtc: Rtc<'static>,
|
||||
) {
|
||||
loop {
|
||||
while CARD_DATA.lock().await.is_none() {
|
||||
@@ -24,10 +28,22 @@ pub async fn nfc_scanner(
|
||||
log::error!("Failed to split NFC card data");
|
||||
continue;
|
||||
};
|
||||
CARD_DATA
|
||||
.lock()
|
||||
.await
|
||||
.replace(Card::try_from(split_data).unwrap());
|
||||
let card = match Card::try_from(split_data) {
|
||||
Ok(card) => card,
|
||||
Err(err) => {
|
||||
log::error!("Invalid card data: {err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
CARD_DATA.lock().await.replace(card);
|
||||
|
||||
match card_store.save_raw_card(split_data, rtc.current_time_us()) {
|
||||
Ok(()) => {}
|
||||
Err(error) => {
|
||||
log::error!("Error storing card in flash: {:?}", error)
|
||||
}
|
||||
}
|
||||
|
||||
let elapsed_ms = start.elapsed().as_millis();
|
||||
log::info!(
|
||||
"NFC read duration: {} ms, card data length: {}",
|
||||
@@ -35,8 +51,8 @@ pub async fn nfc_scanner(
|
||||
card_data.len()
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("NFC read failed: {e}");
|
||||
Err(_) => {
|
||||
log::info!("No NFC card found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user