11/*
2- * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
2+ * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
33 *
44 * SPDX-License-Identifier: MIT
55 */
66/*
77 Example using M5UnitUnified for UnitRFID2
8- Dump NFC device
8+ Dump NFC-A PICC
99*/
1010#include < M5Unified.h>
1111#include < M5UnitUnified.h>
@@ -23,6 +23,7 @@ auto& lcd = M5.Display;
2323m5::unit::UnitUnified Units;
2424m5::unit::UnitRFID2 unit;
2525m5::unit::nfc::NFCLayerA nfc_a{unit};
26+
2627// KeyA that can authenticate all blocks
2728// If it's a different key value, change it
2829constexpr Key keyA = DEFAULT_KEY ; // Default as 0xFFFFFFFFFFFF
@@ -59,8 +60,8 @@ void setup()
5960 }
6061 lcd.fillScreen (0 );
6162 lcd.setCursor (0 , 0 );
62- lcd.printf (" Please put the device and click A" );
63- M5 .Log .printf (" Please put the device and click A\n " );
63+ lcd.printf (" Please put the PICC and click A" );
64+ M5 .Log .printf (" Please put the PICC and click A\n " );
6465}
6566
6667void loop ()
@@ -71,20 +72,23 @@ void loop()
7172
7273 if (M5 .BtnA .wasClicked () || touch.wasClicked ()) {
7374 lcd.fillRect (0 , lcd.fontHeight (), lcd.width (), lcd.height () - lcd.fontHeight ());
74- std::vector<UID > devices ;
75- if (nfc_a.detect (devices )) {
75+ std::vector<UID > uids ;
76+ if (nfc_a.detect (uids )) {
7677 // If multiple occurrences are detected, only the first one detected
77- auto & uid = devices.front ();
78- if (nfc_a.activate (uid)) {
78+ auto & uid = uids.front ();
79+ if (nfc_a.reactivate (uid)) {
80+ M5 .Speaker .tone (2000 , 30 );
7981 M5 .Log .printf (" ==== Dump %s %s %u/%u====\n " , uid.uidAsString ().c_str (), uid.typeAsString ().c_str (),
8082 uid.userAreaSize (), uid.totalSize ());
8183 nfc_a.dump (keyA); // Need key if MIFARE classic, Ignore key if not MIFARE classic
84+
8285 nfc_a.deactivate ();
86+ M5 .Log .printf (" Please remove the PICC from the reader\n " );
8387 } else {
8488 M5_LOGE (" Failed to activate %s" , uid.uidAsString ().c_str ());
8589 }
8690 } else {
87- M5 .Log .printf (" No devices \n " );
91+ M5 .Log .printf (" PICC NOT exists \n " );
8892 }
8993 }
9094}
0 commit comments