implements basic station detection
This commit is contained in:
parent
6541848330
commit
1f13ca71f0
5 changed files with 72 additions and 19 deletions
|
@ -1,43 +1,61 @@
|
|||
#include <LiquidCrystal.h>
|
||||
#include <PN532.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#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
|
||||
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;
|
||||
}
|
||||
|
|
0
main/state.cpp
Normal file
0
main/state.cpp
Normal file
12
main/state.h
Normal file
12
main/state.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
enum class State {
|
||||
|
||||
}
|
||||
|
||||
class GameState {
|
||||
private:
|
||||
|
||||
public:
|
||||
|
||||
}
|
12
main/station.cpp
Normal file
12
main/station.cpp
Normal file
|
@ -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;
|
||||
}
|
11
main/station.h
Normal file
11
main/station.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
class Station {
|
||||
private:
|
||||
uint32_t nfcTagId;
|
||||
String name;
|
||||
public:
|
||||
Station(uint32_t nfcTagId, String name);
|
||||
bool check(uint32_t nfcTagId);
|
||||
};
|
Loading…
Reference in a new issue