T-IOT-901_convoyor/lib/NFC/src/NfcReader.cpp

25 lines
666 B
C++
Raw Normal View History

2024-01-19 11:35:21 +01:00
#include "NfcReader.h"
2024-01-18 16:57:26 +01:00
NfcReader::NfcReader(int i2c_adress)
{
this->mfrc522 = new MFRC522(i2c_adress);
this->mfrc522->PCD_Init();
}
String NfcReader::ReadNfc()
{
this->uid.clear();
if (!this->mfrc522->PICC_IsNewCardPresent() ||
!this->mfrc522->PICC_ReadCardSerial()) {
2024-01-19 11:58:13 +01:00
return ("0");
2024-01-18 16:57:26 +01:00
}
for (unsigned int i = 0; i < this->mfrc522->uid.size; i++) {
if (this->mfrc522->uid.uidByte[i] < 0xF) {
this->uid += '0';
this->uid += String(this->mfrc522->uid.uidByte[i], HEX);
} else {
this->uid += String(this->mfrc522->uid.uidByte[i], HEX);
}
}
return (this->uid);
}