try to implement rfid
This commit is contained in:
1755
project/rfid/MFRC522.cpp
Normal file
1755
project/rfid/MFRC522.cpp
Normal file
File diff suppressed because it is too large
Load Diff
45
project/rfid/rfid.cpp
Normal file
45
project/rfid/rfid.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user