From 1f13ca71f04e48cb75982b17a8d1ea5b8b5aed28 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 16 May 2024 15:19:30 +0200 Subject: [PATCH] implements basic station detection --- main/main.ino | 56 ++++++++++++++++++++++++++++++++---------------- main/state.cpp | 0 main/state.h | 12 +++++++++++ main/station.cpp | 12 +++++++++++ main/station.h | 11 ++++++++++ 5 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 main/state.cpp create mode 100644 main/state.h create mode 100644 main/station.cpp create mode 100644 main/station.h diff --git a/main/main.ino b/main/main.ino index f929cc3..959aeb9 100644 --- a/main/main.ino +++ b/main/main.ino @@ -1,43 +1,61 @@ +#include #include #include +#include "station.h" + #define PN532_CS 10 PN532 nfc(PN532_CS); -const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +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") }; + 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 + if (!versiondata) { + while (1) + ; // halt } // configure board to read RFID tags and cards nfc.SAMConfig(); } -void loop(void) { +void checkStations() { + Station* station = detectStation(); + lcd.setCursor(0, 0); + lcd.print("docked to station "); +} + +Station* detectStation() { uint32_t id; - // look for MiFare type cards id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A); - if (id != 0) - { - - uint8_t keys[]= { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF }; - if(nfc.authenticateBlock(1, id ,0x08,KEY_A,keys)) //authenticate block 0x08 - { - //if authentication successful - - uint8_t block[16]; - //read memory block 0x08 - if(nfc.readMemoryBlock(1,0x08,block)) - { - + Station* found = 0; + for (int i = 0; i < sizeof(stations); i++) { + Station* currentStation = &stations[i]; + if (id != 0) { + if(currentStation->check(id)) { + found = currentStation; } } } - delay(1000); + return found; } diff --git a/main/state.cpp b/main/state.cpp new file mode 100644 index 0000000..e69de29 diff --git a/main/state.h b/main/state.h new file mode 100644 index 0000000..2613517 --- /dev/null +++ b/main/state.h @@ -0,0 +1,12 @@ +#pragma once + +enum class State { + +} + +class GameState { +private: + +public: + +} diff --git a/main/station.cpp b/main/station.cpp new file mode 100644 index 0000000..1b46910 --- /dev/null +++ b/main/station.cpp @@ -0,0 +1,12 @@ +#include "station.h" + +Station::Station(uint32_t nfcTagId, String name) { + { + this->nfcTagId = nfcTagId; + this->name = name; + } +} + +bool Station::check(uint32_t nfcTagId) { + return nfcTagId == this->nfcTagId; +} diff --git a/main/station.h b/main/station.h new file mode 100644 index 0000000..876ffe1 --- /dev/null +++ b/main/station.h @@ -0,0 +1,11 @@ +#pragma once +#include + +class Station { +private: + uint32_t nfcTagId; + String name; +public: + Station(uint32_t nfcTagId, String name); + bool check(uint32_t nfcTagId); +};