66 lines
1.3 KiB
C++
66 lines
1.3 KiB
C++
#include <LiquidCrystal.h>
|
|
#include <PN532.h>
|
|
#include <SPI.h>
|
|
|
|
#include "station.h"
|
|
#include "statemachine.h"
|
|
#include "state.h"
|
|
#include "states.h"
|
|
|
|
#define PN532_CS 10
|
|
|
|
PN532 nfc(PN532_CS);
|
|
|
|
const int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
|
|
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
|
|
|
|
Station stations[4] = { Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"), Station(2174777887, "Blue") };
|
|
|
|
StateMachine stateMachine(new Startup());
|
|
|
|
void setup(void) {
|
|
setupNFC();
|
|
|
|
lcd.begin(16, 2);
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("Test");
|
|
}
|
|
|
|
void loop(void) {
|
|
lcd.clear();
|
|
checkStations();
|
|
delay(1000);
|
|
}
|
|
|
|
void setupNFC() {
|
|
nfc.begin();
|
|
|
|
uint32_t versiondata = nfc.getFirmwareVersion();
|
|
if (!versiondata) {
|
|
while (1)
|
|
; // halt
|
|
}
|
|
// configure board to read RFID tags and cards
|
|
nfc.SAMConfig();
|
|
}
|
|
|
|
void checkStations() {
|
|
Station* station = detectStation();
|
|
lcd.setCursor(0, 0);
|
|
if (station != 0) {
|
|
lcd.print("Station: " + station->getName());
|
|
}
|
|
}
|
|
|
|
Station* detectStation() {
|
|
uint32_t id;
|
|
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
|
|
Station* found = 0;
|
|
for (int i = 0; i < sizeof(stations); i++) {
|
|
Station* currentStation = &stations[i];
|
|
if (currentStation->check(id)) {
|
|
found = currentStation;
|
|
}
|
|
}
|
|
return found;
|
|
}
|