Merge pull request #164 from Rotzbua/master

fix compile error #163
You are the one, thank you again @Rotzbua
This commit is contained in:
Miki Balboa
2016-01-05 09:11:28 -08:00

View File

@@ -42,67 +42,67 @@ MFRC522::MIFARE_Key key;
byte nuidPICC[3]; byte nuidPICC[3];
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
SPI.begin(); // Init SPI bus SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522 rfid.PCD_Init(); // Init MFRC522
for (byte i = 0; i < 6; i++) { for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF; key.keyByte[i] = 0xFF;
} }
Serial.println(F("This code scan the MIFARE Classsic NUID.")); Serial.println(F("This code scan the MIFARE Classsic NUID."));
Serial.print(F("Using the following key:")); Serial.print(F("Using the following key:"));
printHex(key.keyByte, MFRC522::MF_KEY_SIZE); printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
} }
void loop() { void loop() {
// Look for new cards // Look for new cards
if ( ! rfid.PICC_IsNewCardPresent()) if ( ! rfid.PICC_IsNewCardPresent())
return; return;
// Verify if the NUID has been readed // Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial()) if ( ! rfid.PICC_ReadCardSerial())
return; return;
Serial.print(F("PICC type: ")); Serial.print(F("PICC type: "));
byte piccType = rfid.PICC_GetType(rfid.uid.sak); MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.println(rfid.PICC_GetTypeName(piccType)); Serial.println(rfid.PICC_GetTypeName(piccType));
// Check is the PICC of Classic MIFARE type // Check is the PICC of Classic MIFARE type
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI && if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
piccType != MFRC522::PICC_TYPE_MIFARE_4K) { piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F("Your tag is not of type MIFARE Classic.")); Serial.println(F("Your tag is not of type MIFARE Classic."));
return; return;
}
if (rfid.uid.uidByte[0] != nuidPICC[0] ||
rfid.uid.uidByte[1] != nuidPICC[1] ||
rfid.uid.uidByte[2] != nuidPICC[2] ||
rfid.uid.uidByte[3] != nuidPICC[3] ) {
Serial.println(F("A new card has been detected."));
// Store NUID into nuidPICC array
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
} }
if (rfid.uid.uidByte[0] != nuidPICC[0] || Serial.println(F("The NUID tag is:"));
rfid.uid.uidByte[1] != nuidPICC[1] || Serial.print(F("In hex: "));
rfid.uid.uidByte[2] != nuidPICC[2] || printHex(rfid.uid.uidByte, rfid.uid.size);
rfid.uid.uidByte[3] != nuidPICC[3] ) { Serial.println();
Serial.println(F("A new card has been detected.")); Serial.print(F("In dec: "));
printDec(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
}
else Serial.println(F("Card read previously."));
// Store NUID into nuidPICC array // Halt PICC
for (byte i = 0; i < 4; i++) { rfid.PICC_HaltA();
nuidPICC[i] = rfid.uid.uidByte[i];
}
Serial.println(F("The NUID tag is:")); // Stop encryption on PCD
Serial.print(F("In hex: ")); rfid.PCD_StopCrypto1();
printHex(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
Serial.print(F("In dec: "));
printDec(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
}
else Serial.println("Card read previously.");
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
} }
@@ -110,18 +110,18 @@ void loop() {
* Helper routine to dump a byte array as hex values to Serial. * Helper routine to dump a byte array as hex values to Serial.
*/ */
void printHex(byte *buffer, byte bufferSize) { void printHex(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) { for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX); Serial.print(buffer[i], HEX);
} }
} }
/** /**
* Helper routine to dump a byte array as dec values to Serial. * Helper routine to dump a byte array as dec values to Serial.
*/ */
void printDec(byte *buffer, byte bufferSize) { void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) { for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC); Serial.print(buffer[i], DEC);
} }
} }