working nfc reading, but finnicky
This commit is contained in:
+36
-14
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
use core::convert::Infallible;
|
use core::convert::Infallible;
|
||||||
|
|
||||||
|
use alloc::vec::Vec;
|
||||||
use display_interface_spi::SPIInterface;
|
use display_interface_spi::SPIInterface;
|
||||||
use embedded_graphics::Drawable;
|
use embedded_graphics::Drawable;
|
||||||
use embedded_graphics::mono_font::MonoTextStyle;
|
use embedded_graphics::mono_font::MonoTextStyle;
|
||||||
@@ -112,7 +113,7 @@ fn main() -> ! {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
display.clear(Rgb565::BLACK).unwrap();
|
// display.clear(Rgb565::BLACK).unwrap();
|
||||||
|
|
||||||
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
||||||
Text::new("Hello, ESP32!", Point::new(20, 100), style)
|
Text::new("Hello, ESP32!", Point::new(20, 100), style)
|
||||||
@@ -129,7 +130,7 @@ fn main() -> ! {
|
|||||||
time::Rate,
|
time::Rate,
|
||||||
};
|
};
|
||||||
|
|
||||||
let config = I2cConfig::default().with_frequency(Rate::from_khz(100));
|
let config = I2cConfig::default().with_frequency(Rate::from_khz(20));
|
||||||
let i2c = I2c::new(peripherals.I2C0, config)
|
let i2c = I2c::new(peripherals.I2C0, config)
|
||||||
.expect("Failed to init I2C")
|
.expect("Failed to init I2C")
|
||||||
.with_sda(sda)
|
.with_sda(sda)
|
||||||
@@ -139,27 +140,48 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let ms_50 = Duration::from_millis(50);
|
let ms_50 = Duration::from_millis(50);
|
||||||
let ms_1000 = Duration::from_millis(1000);
|
let ms_1000 = Duration::from_millis(1000);
|
||||||
loop {
|
|
||||||
info!("Hello world!");
|
let delay_start = Instant::now();
|
||||||
|
while delay_start.elapsed() < Duration::from_millis(500) {}
|
||||||
|
|
||||||
|
let mut data: Vec<u8> = Vec::with_capacity(858);
|
||||||
|
|
||||||
if let Err(e) = pn532.process(
|
if let Err(e) = pn532.process(
|
||||||
&Request::sam_configuration(SAMMode::Normal, false),
|
&Request::sam_configuration(SAMMode::Normal, false),
|
||||||
0,
|
0,
|
||||||
ms_1000,
|
Duration::from_millis(5000),
|
||||||
) {
|
) {
|
||||||
error!("Could not initialize PN532: {e:?}")
|
error!("Could not initialize PN532: {e:?}")
|
||||||
} else {
|
} else {
|
||||||
info!("Successfully init'ed PN532");
|
info!("Successfully init'ed PN532");
|
||||||
}
|
}
|
||||||
if let Ok(uid) = pn532.process(&Request::INLIST_ONE_ISO_A_TARGET, 7, ms_1000) {
|
|
||||||
|
loop {
|
||||||
|
info!("Hello world!");
|
||||||
|
|
||||||
|
match pn532.process(
|
||||||
|
&Request::INLIST_ONE_ISO_A_TARGET,
|
||||||
|
23,
|
||||||
|
Duration::from_secs(10),
|
||||||
|
) {
|
||||||
|
Ok(uid) => {
|
||||||
info!("uid = {uid:?}");
|
info!("uid = {uid:?}");
|
||||||
let result = pn532.process(&Request::ntag_read(10), 17, ms_1000).unwrap();
|
for i in (4..=231) {
|
||||||
// if result[0] == 0x00 {
|
let result = pn532.process(&Request::ntag_read(i), 17, ms_1000).unwrap();
|
||||||
info!("page 10: {:?}", &result[1..5]);
|
let success = result.first().is_some_and(|x| *x == 0);
|
||||||
// }
|
if success {
|
||||||
|
// info!("page {i}: {:02x?}", result);
|
||||||
|
data.extend(&result[1..5]);
|
||||||
|
} else {
|
||||||
|
info!("err {i}: {:02x?}", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info!("Full data: {data:02x?}");
|
||||||
|
data.clear();
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
info!("No NFC card found: {e:?}");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
info!("No NFC card found.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let delay_start = Instant::now();
|
let delay_start = Instant::now();
|
||||||
@@ -194,7 +216,7 @@ impl pn532::CountDown for TimerWrapper {
|
|||||||
T: Into<Self::Time>,
|
T: Into<Self::Time>,
|
||||||
{
|
{
|
||||||
// without this debug log, it works worse: stuck in NFC card search without ever returning.
|
// without this debug log, it works worse: stuck in NFC card search without ever returning.
|
||||||
self.start = dbg!(Instant::now());
|
self.start = Instant::now();
|
||||||
self.duration = timeout.into();
|
self.duration = timeout.into();
|
||||||
self.counter = 0;
|
self.counter = 0;
|
||||||
}
|
}
|
||||||
@@ -203,7 +225,7 @@ impl pn532::CountDown for TimerWrapper {
|
|||||||
let elapsed = self.start.elapsed();
|
let elapsed = self.start.elapsed();
|
||||||
self.counter += 1;
|
self.counter += 1;
|
||||||
if self.counter.is_multiple_of(1) {
|
if self.counter.is_multiple_of(1) {
|
||||||
info!("Elapsed: {elapsed}");
|
// info!("Elapsed: {elapsed}");
|
||||||
}
|
}
|
||||||
if elapsed >= self.duration {
|
if elapsed >= self.duration {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user