|
5 | 5 | */ |
6 | 6 | /* |
7 | 7 | Example using M5UnitUnified for UnitRFID2 |
8 | | - Detect RFID devices |
| 8 | + Detect NFC-A devices |
9 | 9 | */ |
10 | 10 | #include <M5Unified.h> |
11 | 11 | #include <M5UnitUnified.h> |
12 | 12 | #include <M5UnitUnifiedRFID.h> |
| 13 | +#include <M5UnitUnifiedNFC.h> |
13 | 14 | #include <M5Utility.h> |
14 | 15 | #include <vector> |
15 | 16 |
|
16 | 17 | namespace { |
17 | 18 | auto& lcd = M5.Display; |
18 | 19 | m5::unit::UnitUnified Units; |
19 | 20 | m5::unit::UnitRFID2 unit; |
| 21 | +m5::unit::nfc::NFCLayerA nfc_a{unit}; |
20 | 22 |
|
21 | 23 | } // namespace |
22 | 24 |
|
23 | | -using namespace m5::rfid; |
| 25 | +using namespace m5::nfc::a; |
24 | 26 |
|
25 | 27 | void setup() |
26 | 28 | { |
@@ -51,43 +53,29 @@ void setup() |
51 | 53 | } else { |
52 | 54 | lcd.setFont(&fonts::Font2); |
53 | 55 | } |
54 | | - lcd.clear(0); |
55 | | - lcd.setCursor(8, 0); |
56 | | - lcd.printf("Please put the devices..."); |
57 | | - M5.Log.printf("Please put the devices...\n"); |
| 56 | + lcd.fillScreen(0); |
| 57 | + lcd.setCursor(0, 0); |
58 | 58 | } |
59 | 59 |
|
60 | 60 | void loop() |
61 | 61 | { |
62 | 62 | M5.update(); |
| 63 | + auto touch = M5.Touch.getDetail(); |
63 | 64 | Units.update(); |
64 | 65 |
|
65 | 66 | std::vector<UID> devices; |
66 | | - // Detect new devices? |
67 | | - while (unit.detectIdleDevice()) { |
68 | | - // Store UID |
69 | | - UID uid{}; |
70 | | - if (unit.activateDevice(uid)) { |
71 | | - devices.push_back(uid); |
72 | | - unit.deactivateDevice(); |
73 | | - } else { |
74 | | - M5_LOGE("Failed to activate"); |
75 | | - } |
76 | | - } |
77 | | - // display / logging |
78 | | - if (!devices.empty()) { |
79 | | - M5.Log.printf(">>--------------\n"); |
80 | | - M5.Speaker.tone(1000, 20); |
81 | | - lcd.fillRect(0, lcd.fontHeight(), lcd.width(), lcd.height() - lcd.fontHeight(), 0); |
82 | | - |
83 | | - uint32_t idx{1}; |
84 | | - for (auto&& uid : devices) { |
85 | | - M5.Log.printf("UID:%s %s\n", uid.uidAsString().c_str(), uid.typeAsString().c_str()); |
86 | | - lcd.setCursor(8, lcd.fontHeight() * idx); |
87 | | - lcd.printf("%s:%s", uid.uidAsString().c_str(), uid.typeAsString().c_str()); |
| 67 | + if (nfc_a.detect(devices)) { |
| 68 | + M5.Speaker.tone(3000, 10); |
| 69 | + lcd.fillRect(0, 0, lcd.width(), lcd.height()); |
| 70 | + lcd.setCursor(0, 0); |
| 71 | + M5.Log.printf("Devices: %zu\n", devices.size()); |
| 72 | + lcd.printf("Devices: %zu\n", devices.size()); |
| 73 | + uint32_t idx{}; |
| 74 | + for (auto&& u : devices) { |
| 75 | + M5.Log.printf("[%2u]:UID:<%s> %s\n", idx, u.uidAsString().c_str(), u.typeAsString().c_str()); |
| 76 | + lcd.printf("[%2u]:UID:<%s> %s\n", idx, u.uidAsString().c_str(), u.typeAsString().c_str()); |
88 | 77 | ++idx; |
89 | 78 | } |
90 | | - M5.Log.printf("<<--------------\n"); |
| 79 | + nfc_a.deactivate(); |
91 | 80 | } |
92 | | - m5::utility::delay(1); |
93 | 81 | } |
0 commit comments