1 Commits
Author SHA1 Message Date
ede1998 82f81d1cd0 move nfc to background tasks 2026-08-24 20:57:55 +02:00
4 changed files with 38 additions and 37 deletions
+1
View File
@@ -0,0 +1 @@
pub mod nfc;
+36
View File
@@ -0,0 +1,36 @@
#[embassy_executor::task]
#[allow(
clippy::large_stack_frames,
reason = "ignoring this for now because it still works"
)]
async fn nfc_driver_task(
mut nfc_driver: NfcPn532Driver<AtomicDevice<'static, I2c<'static, Blocking>>>,
) {
loop {
while CARD_DATA.lock().await.is_none() {
let start = Instant::now();
match nfc_driver.read_card_data().await {
Ok(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());
let elapsed_ms = start.elapsed().as_millis();
log::info!(
"NFC read duration: {} ms, card data length: {}",
elapsed_ms,
card_data.len()
);
}
Err(e) => {
log::error!("NFC read failed: {e}");
}
}
}
embassy_time::Timer::after(embassy_time::Duration::from_millis(1000)).await;
}
}
-37
View File
@@ -138,43 +138,6 @@ async fn main(spawner: Spawner) {
spawner.spawn(nfc_driver_task(nfc_driver).expect("nfc driver task failed"));
}
#[embassy_executor::task]
#[allow(
clippy::large_stack_frames,
reason = "ignoring this for now because it still works"
)]
async fn nfc_driver_task(
mut nfc_driver: NfcPn532Driver<AtomicDevice<'static, I2c<'static, Blocking>>>,
) {
loop {
while CARD_DATA.lock().await.is_none() {
let start = Instant::now();
match nfc_driver.read_card_data().await {
Ok(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());
let elapsed_ms = start.elapsed().as_millis();
log::info!(
"NFC read duration: {} ms, card data length: {}",
elapsed_ms,
card_data.len()
);
}
Err(e) => {
log::error!("NFC read failed: {e}");
}
}
}
embassy_time::Timer::after(embassy_time::Duration::from_millis(1000)).await;
}
}
fn display_shit(oled: &mut SecondaryDisplay<'static>, text: &str) {
oled.clear().unwrap();
+1
View File
@@ -2,6 +2,7 @@
extern crate alloc;
pub mod background_tasks;
pub mod card;
pub mod display;
pub mod drivers;