feat: update rfid code
This commit is contained in:
Submodule FW/leo_muziekdoos_esp32/lib/rfid_PN532 deleted from 12663d9dc3
@@ -9,4 +9,5 @@
|
||||
#define NFC_SS 25
|
||||
#define NFC_SCK 18
|
||||
#define NFC_MOSI 23
|
||||
#define NFC_MISO 19
|
||||
#define NFC_MISO 19
|
||||
#define NFC_RST 22 //not connectedx
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.begin(115200);
|
||||
delay(2000);
|
||||
|
||||
initStorage();
|
||||
initAudio();
|
||||
|
||||
@@ -1,117 +1,24 @@
|
||||
#include "rfid.h"
|
||||
|
||||
#define RST_PIN 9 // Configurable, see typical pin layout above
|
||||
#define SS_PIN 10 // Configurable, see typical pin layout above
|
||||
|
||||
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
|
||||
PN532_SPI pn532spi(SPI, NFC_SS, NFC_SCK, NFC_MISO, NFC_MOSI);
|
||||
NfcAdapter nfc = NfcAdapter(pn532spi);
|
||||
|
||||
//*****************************************************************************************//
|
||||
void initRfid() {
|
||||
void initRfid()
|
||||
{
|
||||
//int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);
|
||||
SPI.begin(NFC_SCK,NFC_MISO,NFC_MOSI,NFC_SS ); // Init SPI bus
|
||||
mfrc522.PCD_Init(); // Init MFRC522 card
|
||||
Serial.println(F("Read personal data on a MIFARE PICC:")); //shows in serial that it is ready to read
|
||||
nfc.begin(true);
|
||||
Serial.println(F("rfid init done")); //shows in serial that it is ready to read
|
||||
}
|
||||
|
||||
//*****************************************************************************************//
|
||||
void handleRfid() {
|
||||
|
||||
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
|
||||
MFRC522::MIFARE_Key key;
|
||||
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
|
||||
|
||||
//some variables we need
|
||||
byte block;
|
||||
byte len;
|
||||
MFRC522::StatusCode status;
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
|
||||
if ( ! mfrc522.PICC_IsNewCardPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Select one of the cards
|
||||
if ( ! mfrc522.PICC_ReadCardSerial()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println(F("**Card Detected:**"));
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
|
||||
|
||||
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //uncomment this to see all blocks in hex
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
Serial.print(F("Name: "));
|
||||
|
||||
byte buffer1[18];
|
||||
|
||||
block = 4;
|
||||
len = 18;
|
||||
|
||||
//------------------------------------------- GET FIRST NAME
|
||||
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Authentication failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
status = mfrc522.MIFARE_Read(block, buffer1, &len);
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Reading failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
//PRINT FIRST NAME
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
void handleRfid()
|
||||
{
|
||||
if (nfc.tagPresent())
|
||||
{
|
||||
if (buffer1[i] != 32)
|
||||
{
|
||||
Serial.write(buffer1[i]);
|
||||
}
|
||||
NfcTag tag = nfc.read();
|
||||
tag.print();
|
||||
}
|
||||
Serial.print(" ");
|
||||
|
||||
//---------------------------------------- GET LAST NAME
|
||||
|
||||
byte buffer2[18];
|
||||
block = 1;
|
||||
|
||||
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Authentication failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
status = mfrc522.MIFARE_Read(block, buffer2, &len);
|
||||
if (status != MFRC522::STATUS_OK) {
|
||||
Serial.print(F("Reading failed: "));
|
||||
Serial.println(mfrc522.GetStatusCodeName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
//PRINT LAST NAME
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
Serial.write(buffer2[i] );
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
Serial.println(F("\n**End Reading**\n"));
|
||||
|
||||
delay(1000); //change value if you want to read cards faster
|
||||
|
||||
mfrc522.PICC_HaltA();
|
||||
mfrc522.PCD_StopCrypto1();
|
||||
}
|
||||
//*****************************************************************************************//
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "board.h"
|
||||
|
||||
#include <SPI.h>
|
||||
#include <MFRC522.h>
|
||||
#include "PN532_SPI.h"
|
||||
#include "PN532.h"
|
||||
#include "NfcAdapter.h"
|
||||
|
||||
void initRfid(void);
|
||||
void handleRfid(void);
|
||||
Reference in New Issue
Block a user