nfc read: print error instead of panic on invalid data

This commit is contained in:
2026-08-26 20:54:03 +00:00
parent 1f1bdda35b
commit c3fe4759ad
+10 -6
View File
@@ -16,7 +16,7 @@ use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
use creaturedex::navigation::inputs::Inputs;
use creaturedex::navigation::navigation::{self, CARD_DATA};
use creaturedex::network::wifi::setup_wifi;
use creaturedex::storage::cardstore::{CardStore, CardStoreError};
use creaturedex::storage::cardstore::CardStore;
use creaturedex::storage::store::Store;
use embassy_executor::Spawner;
use embassy_time::Instant;
@@ -108,7 +108,7 @@ async fn main(spawner: Spawner) {
let store = Store::new(peripherals.FLASH).expect("Could not initialize Flash Store");
let card_store = CardStore::new(store).expect("Could not initialize Card Store");
let mut rtc = Rtc::new(peripherals.LPWR);
let rtc = Rtc::new(peripherals.LPWR);
//setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
let mut nfc_driver = NfcPn532Driver::new(AtomicDevice::new(shared_i2c));
@@ -150,10 +150,14 @@ async fn nfc_driver_task(
log::error!("Failed to split NFC card data");
continue;
};
CARD_DATA
.lock()
.await
.replace(Card::try_from(split_data).expect("Invalid card data"));
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(()) => {}