170 lines
3.3 KiB
C++
170 lines
3.3 KiB
C++
#include <Wire.h>
|
|
#include <Adafruit_NFCShield_I2C.h>
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
#define IRQ (D5)
|
|
#define RESET (D0) // Not connected by default on the NFC Shield
|
|
|
|
Adafruit_NFCShield_I2C nfc(IRQ, RESET);
|
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|
#define showState(v) lcd.home(); lcd.clear(); lcd.print(v);
|
|
|
|
|
|
byte book_left[8] = {
|
|
B01111,
|
|
B10000,
|
|
B10000,
|
|
B10111,
|
|
B10000,
|
|
B10111,
|
|
B10000,
|
|
B01111,
|
|
};
|
|
|
|
|
|
byte book_right[8] = {
|
|
B11110,
|
|
B00001,
|
|
B00001,
|
|
B11101,
|
|
B00001,
|
|
B11101,
|
|
B00001,
|
|
B11110,
|
|
};
|
|
|
|
byte id_left[8] = {
|
|
B11111,
|
|
B10000,
|
|
B10010,
|
|
B10010,
|
|
B10010,
|
|
B10010,
|
|
B10000,
|
|
B11111,
|
|
};
|
|
|
|
byte id_right[8] = {
|
|
B11110,
|
|
B00001,
|
|
B11001,
|
|
B10101,
|
|
B10101,
|
|
B11001,
|
|
B00001,
|
|
B11110,
|
|
};
|
|
|
|
byte icon_up[8] = {
|
|
B01110,
|
|
B11111,
|
|
B11011,
|
|
B10101,
|
|
B01110,
|
|
B11111,
|
|
B11111,
|
|
B11111,
|
|
};
|
|
|
|
|
|
byte icon_down[8] = {
|
|
B11111,
|
|
B11111,
|
|
B11111,
|
|
B01110,
|
|
B10101,
|
|
B11011,
|
|
B11111,
|
|
B01110,
|
|
};
|
|
|
|
void setup(void) {
|
|
Serial.begin(9600);
|
|
Serial.setTimeout(100);
|
|
|
|
Serial.println("Hello!");
|
|
|
|
lcd.begin();
|
|
lcd.backlight();
|
|
|
|
lcd.createChar(1, book_left);
|
|
lcd.createChar(2, book_right);
|
|
lcd.createChar(3, id_left);
|
|
lcd.createChar(4, id_right);
|
|
lcd.createChar(5, icon_up);
|
|
lcd.createChar(6, icon_down);
|
|
|
|
lcd.clear();
|
|
lcd.home();
|
|
|
|
lcd.print("\01\02 Book Name \05");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("\03\04 User ID \06");
|
|
|
|
nfc.begin();
|
|
|
|
uint32_t versiondata = nfc.getFirmwareVersion();
|
|
if (! versiondata) {
|
|
Serial.print("Didn't find PN53x board");
|
|
|
|
showState("Failed");
|
|
while (1); // halt
|
|
}
|
|
|
|
// Got ok data, print it out!
|
|
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
|
|
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
|
|
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
|
|
|
|
// Set the max number of retry attempts to read from a card
|
|
// This prevents us from waiting forever for a card, which is
|
|
// the default behaviour of the PN532.
|
|
nfc.setPassiveActivationRetries(10);
|
|
|
|
// configure board to read RFID tags
|
|
nfc.SAMConfig();
|
|
|
|
Serial.println("Waiting for an ISO14443A card");
|
|
lcd.clear();
|
|
}
|
|
|
|
uint8_t currentUid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
|
|
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
|
|
|
|
char currentBookcode[32] = { 0 };
|
|
|
|
boolean hasUid = false;
|
|
boolean hasBookcode = false;
|
|
|
|
void loop(void) {
|
|
boolean success;
|
|
|
|
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
|
|
// 'uid' will be populated with the UID, and uidLength will indicate
|
|
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
|
|
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, ¤tUid[0], &uidLength);
|
|
|
|
if (success) {
|
|
hasUid = true;
|
|
}
|
|
|
|
if(Serial.readBytesUntil('\r', currentBookcode, 32)) {
|
|
hasBookcode = true;
|
|
Serial.println("got bookcode");
|
|
Serial.println(currentBookcode);
|
|
}
|
|
|
|
/*while(Serial.available()) {
|
|
Serial.print("read: ");
|
|
Serial.println(Serial.read(), DEC);
|
|
}*/
|
|
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("\01\02 ");
|
|
lcd.print(currentBookcode);
|
|
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("\03\04 ");
|
|
for (int i = 0; i < uidLength; i++) lcd.print(currentUid[i], HEX);
|
|
}
|