forked from ahmadfathan/flipper-lite
-
Notifications
You must be signed in to change notification settings - Fork 3
/
read_tag_uid.ino
49 lines (37 loc) · 1.11 KB
/
read_tag_uid.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
void read_tag_uid() {
u8g2.clearBuffer();
u8g2.drawStr(0, 10, "Reading TAG...");
u8g2.sendBuffer();
String uid_str = "";
uint64_t now = millis();
bool found = false;
while (true) {
if (millis() - now > READ_TAG_UID_TIMEOUT) break;
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
delay(50);
continue;
}
// RFID Tag found
uint16_t addr_rfid_tag_uid_len = ADDR_RFID_TAG_UID;
EEPROM.writeByte(addr_rfid_tag_uid_len, mfrc522.uid.size);
uint16_t addr_rfid_tag_uid = addr_rfid_tag_uid_len + 1;
// Dump UID
for (uint8_t i = 0; i < mfrc522.uid.size; i++, addr_rfid_tag_uid++) {
EEPROM.writeByte(addr_rfid_tag_uid, mfrc522.uid.uidByte[i]);
uid_str += String(mfrc522.uid.uidByte[i], 16) + "";
}
EEPROM.commit();
Serial.print("Received UID: ");
Serial.println(uid_str);
found = true;
break;
}
uint8_t selection = u8g2.userInterfaceMessage(
found ? "Saved!" : "Timeout!",
found ? &uid_str[0] : "",
"",
found ? " OK " : " OK \n Retry ");
if (selection == 2) { // retry
read_tag_uid();
}
}