NFC: Adding NFC Reader
This commit is contained in:
35
lib/NFC/src/NfcReader.cpp
Normal file
35
lib/NFC/src/NfcReader.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2024
|
||||
** T-IOT-901_convoyor
|
||||
** File description:
|
||||
** NfcReader
|
||||
*/
|
||||
|
||||
#include "NfcReader.hpp"
|
||||
|
||||
NfcReader::NfcReader(int i2c_adress)
|
||||
{
|
||||
this->mfrc522 = new MFRC522(i2c_adress);
|
||||
this->mfrc522->PCD_Init();
|
||||
}
|
||||
|
||||
NfcReader::~NfcReader() {}
|
||||
|
||||
String NfcReader::ReadNfc()
|
||||
{
|
||||
this->uid.clear();
|
||||
if (!this->mfrc522->PICC_IsNewCardPresent() ||
|
||||
!this->mfrc522->PICC_ReadCardSerial()) {
|
||||
delay(200);
|
||||
return "0";
|
||||
}
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user