cpp-mfrc522/src/main.cpp

81 lines
1.7 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <unistd.h>
#include <cstring>
#include <signal.h>
#include "spi.h"
#include "mfrc522.h"
int reading = 0;
void sig_handler(int signo)
{
if (signo == SIGINT)
{
reading = 0;
}
}
int main(int argc, char **argv)
{
SPI spi(0);
MFRC522 MIFAREReader(&spi);
int status;
if (signal(SIGINT, sig_handler) == SIG_ERR)
{
perror("Unable to bind sigint\n");
return EXIT_FAILURE;
}
while (reading)
{
/*
// Scan for cards
status = MIFAREReader.MFRC522_Request(MFRC522::PICC_REQIDL);
// If a card is found
if (status == MFRC522::MI_OK)
{
printf("Card detected\n");
}
unsigned char uid[4];
// This is the default key for authentication
unsigned char key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
// Get the UID of the card
status = MIFAREReader.MFRC522_Anticoll(&uid);
// If we have the UID, continue
if (status == MFRC522::MI_OK)
{
// Print UID
printf("Card read UID: %02x:%02x:%02x:%02x", uid[0], uid[1], uid[2], uid[3]);
// Select the scanned tag
MIFAREReader.MFRC522_SelectTag(&uid);
// Authenticate
status = MIFAREReader.MFRC522_Auth(MFRC522::PICC_AUTHENT1A, 8, key, &uid);
// Check if authenticated
if (status == MFRC522::MI_OK)
{
MIFAREReader.MFRC522_Read(8);
MIFAREReader.MFRC522_StopCrypto1();
}
else
{
printf("Authentication error");
}
}
*/
}
}