changes to adafruit library to interface with nfc shield, also fixes an issue in the library (zip)
This commit is contained in:
parent
b0778df859
commit
55dd4311d2
4 changed files with 48 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
#include <LiquidCrystal.h>
|
||||
#include <PN532.h>
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_PN532.h>
|
||||
|
||||
#include "station.h"
|
||||
#include "statemachine.h"
|
||||
|
@ -10,13 +11,15 @@
|
|||
|
||||
#define PN532_CS 10
|
||||
|
||||
PN532 nfc(PN532_CS);
|
||||
Adafruit_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);
|
||||
Station* currentStation;
|
||||
|
||||
Timer stationDetectionTimer(3000, true);
|
||||
|
||||
StateMachine stateMachine(new Startup());
|
||||
|
||||
|
@ -28,8 +31,6 @@ void setup(void) {
|
|||
setupNFC();
|
||||
|
||||
lcd.begin(16, 2);
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Test");
|
||||
stationDetectionTimer.start();
|
||||
}
|
||||
|
||||
|
@ -38,14 +39,20 @@ void loop(void) {
|
|||
deltaTime = currentLoopTime - lastLoopTime;
|
||||
|
||||
bool doCheck = stationDetectionTimer.update(deltaTime);
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(" ");
|
||||
if (doCheck) {
|
||||
lcd.clear();
|
||||
checkStations();
|
||||
lcd.setCursor(7, 1);
|
||||
lcd.print("check");
|
||||
}
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print(String(deltaTime));
|
||||
|
||||
stateMachine.update(Context(stations, deltaTime));
|
||||
|
||||
lastLoopTime = currentLoopTime;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void setupNFC() {
|
||||
|
@ -62,15 +69,45 @@ void setupNFC() {
|
|||
|
||||
void checkStations() {
|
||||
Station* station = detectStation();
|
||||
lcd.setCursor(0, 0);
|
||||
|
||||
if (station != 0) {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Station: " + station->getName());
|
||||
if (currentStation == 0) {
|
||||
currentStation = station;
|
||||
stateMachine.putDown(currentStation);
|
||||
}
|
||||
} else {
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("not docked");
|
||||
if (currentStation != 0) {
|
||||
currentStation = 0;
|
||||
stateMachine.pickedUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Station* detectStation() {
|
||||
uint32_t id;
|
||||
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
|
||||
uint8_t uid[7];
|
||||
uint8_t uidLength;
|
||||
uint16_t timeout = 100;
|
||||
bool success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength, timeout);
|
||||
|
||||
if (!success) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t id = 0;
|
||||
for (uint8_t i = 0; i < uidLength; i++) {
|
||||
id <<= 8;
|
||||
id |= uid[i];
|
||||
}
|
||||
|
||||
|
||||
Station* found = 0;
|
||||
for (int i = 0; i < sizeof(stations); i++) {
|
||||
Station* currentStation = &stations[i];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue