#include #include #include #include "station.h" #include "statemachine.h" #include "state.h" #include "states.h" #include "timer.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") }; Timer stationDetectionTimer(1000, true); StateMachine stateMachine(new Startup()); unsigned long lastLoopTime = 0; unsigned long currentLoopTime = 0; unsigned long deltaTime = 0; void setup(void) { setupNFC(); lcd.begin(16, 2); lcd.setCursor(0, 0); lcd.print("Test"); stationDetectionTimer.start(); } void loop(void) { currentLoopTime = millis(); deltaTime = currentLoopTime - lastLoopTime; bool doCheck = stationDetectionTimer.update(deltaTime); if (doCheck) { lcd.clear(); checkStations(); } stateMachine.update(Context(stations, deltaTime)); lastLoopTime = currentLoopTime; } 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; }