Implemented Scan card menu

This commit was merged in pull request #29.
This commit is contained in:
2026-08-22 13:35:58 +02:00
parent cf6c068394
commit b44ae59c8b
14 changed files with 189 additions and 89 deletions
+30 -6
View File
@@ -8,14 +8,16 @@
#![deny(clippy::large_stack_frames)]
use alloc::boxed::Box;
use creaturedex::card::decoder::split_nfc_hex;
use creaturedex::card::model::Card;
use creaturedex::display::primary_lcd::{PrimaryLcdDisplay, init_primary_lcd};
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
use creaturedex::navigation::inputs::Inputs;
use creaturedex::navigation::navigation;
use creaturedex::navigation::navigation::{self, CARD_DATA};
use creaturedex::network::wifi::setup_wifi;
use embassy_executor::Spawner;
use esp_hal::clock::CpuClock;
use esp_hal::gpio::{Input, InputConfig, Pull};
use esp_hal::time::Duration;
use esp_hal::timer::timg::TimerGroup;
use log::error;
@@ -61,18 +63,16 @@ async fn main(spawner: Spawner) {
peripherals.GPIO12, // shared dc
)));
//setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
let mut nfc_driver =
NfcPn532Driver::new(peripherals.I2C0, peripherals.GPIO17, peripherals.GPIO18);
let timeout = Duration::from_millis(1000);
if nfc_driver.configure_sam(timeout).is_ok() {
if nfc_driver.configure_sam().await.is_ok() {
log::info!("NFC SAM configuration successful");
} else {
log::error!("NFC SAM configuration failed");
}
let button_config = InputConfig::default().with_pull(Pull::Up);
let inputs = Inputs {
up: Input::new(peripherals.GPIO38, button_config.clone()),
@@ -85,4 +85,28 @@ async fn main(spawner: Spawner) {
log::info!("Setup complete, entering main loop");
spawner.spawn(navigation::run(inputs, display).expect("run task failed"));
spawner.spawn(nfc_driver_task(nfc_driver).expect("nfc driver task failed"));
}
#[embassy_executor::task]
async fn nfc_driver_task(mut nfc_driver: NfcPn532Driver<'static>) {
loop {
while CARD_DATA.lock().await.is_none() {
match nfc_driver.read_card_data().await {
Ok(card_data) => {
log::info!("NFC Card Data Read: {:?}", card_data);
let Some(split_data) = split_nfc_hex(&card_data) else {
log::error!("Failed to split NFC card data");
continue;
};
CARD_DATA.lock().await.replace(Card::try_from(split_data).unwrap());
}
Err(_) => {
log::info!("No NFC card found");
}
}
}
embassy_time::Timer::after(embassy_time::Duration::from_millis(1000)).await;
}
}