46 lines
731 B
C++
46 lines
731 B
C++
#include <unistd.h>
|
|
#include <iostream>
|
|
#include <ctime>
|
|
#include <cstdint>
|
|
|
|
#include "MFRC522.h"
|
|
|
|
MFRC522 mfrc;
|
|
|
|
uint32_t getUID()
|
|
{
|
|
uint32_t uid = int((unsigned char)(mfrc.uid.uidByte[0]) << 24 |
|
|
(unsigned char)(mfrc.uid.uidByte[1]) << 16 |
|
|
(unsigned char)(mfrc.uid.uidByte[2]) << 8 |
|
|
(unsigned char)(mfrc.uid.uidByte[3]));
|
|
return uid;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
mfrc.PCD_Init();
|
|
|
|
while(true)
|
|
{
|
|
if(!mfrc.PICC_IsNewCardPresent())
|
|
{
|
|
continue;
|
|
}
|
|
if(!mfrc.PICC_ReadCardSerial())
|
|
{
|
|
continue;
|
|
}
|
|
printf("\n");
|
|
std::time_t result = std::time(nullptr);
|
|
std::cout << std::asctime(std::localtime(&result));
|
|
|
|
printf("%X\n", getUID());
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
usleep(1000*1000);
|
|
return 0;
|
|
}
|
|
|