diff --git a/.idea/editor.xml b/.idea/editor.xml
index 855412d..551ce98 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -99,5 +99,7 @@
+
+
\ No newline at end of file
diff --git a/libraries/Adafruit-PN532-1.3.3.zip b/libraries/Adafruit-PN532-1.3.3.zip
new file mode 100644
index 0000000..fd06bc4
Binary files /dev/null and b/libraries/Adafruit-PN532-1.3.3.zip differ
diff --git a/libraries/og_Adafruit-PN532-1.3.3.zip b/libraries/og_Adafruit-PN532-1.3.3.zip
new file mode 100644
index 0000000..bb5c1bc
Binary files /dev/null and b/libraries/og_Adafruit-PN532-1.3.3.zip differ
diff --git a/main/main.ino b/main/main.ino
index f92ce37..e795a2c 100644
--- a/main/main.ino
+++ b/main/main.ino
@@ -1,6 +1,7 @@
#include
-#include
+#include
#include
+#include
#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];