diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/BuenzliAI.iml b/.idea/BuenzliAI.iml
new file mode 100644
index 0000000..bc2cd87
--- /dev/null
+++ b/.idea/BuenzliAI.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
new file mode 100644
index 0000000..855412d
--- /dev/null
+++ b/.idea/editor.xml
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e637d2e
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/main.ino b/main/main.ino
index 959aeb9..36a3570 100644
--- a/main/main.ino
+++ b/main/main.ino
@@ -3,6 +3,8 @@
#include
#include "station.h"
+#include "statemachine.h"
+#include "state.h"
#define PN532_CS 10
@@ -13,6 +15,8 @@ LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Station stations[4] = { Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"), Station(2174777887, "Blue") };
+StateMachine stateMachine();
+
void setup(void) {
setupNFC();
@@ -42,7 +46,9 @@ void setupNFC() {
void checkStations() {
Station* station = detectStation();
lcd.setCursor(0, 0);
- lcd.print("docked to station ");
+ if (station != 0) {
+ lcd.print("Station: " + station->getName());
+ }
}
Station* detectStation() {
@@ -51,10 +57,8 @@ Station* detectStation() {
Station* found = 0;
for (int i = 0; i < sizeof(stations); i++) {
Station* currentStation = &stations[i];
- if (id != 0) {
- if(currentStation->check(id)) {
- found = currentStation;
- }
+ if (currentStation->check(id)) {
+ found = currentStation;
}
}
return found;
diff --git a/main/state.cpp b/main/state.cpp
deleted file mode 100644
index e69de29..0000000
diff --git a/main/state.h b/main/state.h
index 2613517..6e03ecd 100644
--- a/main/state.h
+++ b/main/state.h
@@ -1,12 +1,16 @@
#pragma once
+#include
+#include "station.h"
-enum class State {
-
-}
-
-class GameState {
-private:
+class Station;
+class State {
public:
+ virtual ~State() = default;
-}
+ virtual State* pickedUp() { return this; }
+ virtual State* putDown(Station* newStation) { return this; }
+ virtual State* update() { return this; }
+
+ virtual void updateDisplay(LiquidCrystal* lcd) { }
+};
diff --git a/main/statemachine.cpp b/main/statemachine.cpp
new file mode 100644
index 0000000..d890679
--- /dev/null
+++ b/main/statemachine.cpp
@@ -0,0 +1,31 @@
+#include "statemachine.h"
+#include "station.h"
+
+StateMachine::StateMachine(State* initialState)
+ : currentState(initialState) {}
+
+StateMachine::~StateMachine() {
+ delete currentState;
+}
+
+void StateMachine::updateState(State* newState) {
+ if (newState != currentState) {
+ delete currentState;
+ currentState = newState;
+ }
+}
+
+void StateMachine::pickedUp() {
+ State* newState = currentState->pickedUp();
+ updateState(newState);
+}
+
+void StateMachine::putDown(Station* newStation) {
+ State* newState = currentState->putDown(newStation);
+ updateState(newState);
+}
+
+void StateMachine::update() {
+ State* newState = currentState->update();
+ updateState(newState);
+}
\ No newline at end of file
diff --git a/main/statemachine.h b/main/statemachine.h
new file mode 100644
index 0000000..4a6aaef
--- /dev/null
+++ b/main/statemachine.h
@@ -0,0 +1,20 @@
+#pragma once
+#include
+#include "state.h"
+#include "station.h"
+
+class StateMachine {
+private:
+ State* currentState;
+ void updateState(State* newState);
+
+public:
+ StateMachine(State* initialState);
+ ~StateMachine();
+
+ void pickedUp();
+ void putDown(Station* newSation);
+ void update();
+
+ void updateDisplay(LiquidCrystal* lcd);
+};
diff --git a/main/states.cpp b/main/states.cpp
new file mode 100644
index 0000000..a861ba2
--- /dev/null
+++ b/main/states.cpp
@@ -0,0 +1,42 @@
+#include "states.h"
+#include "state.h"
+#include "station.h"
+
+//-------
+// On the Move
+//-------
+
+
+OnTheMove::OnTheMove(Station* targetStation) {
+ this->targetStation = targetStation;
+}
+
+State* OnTheMove::putDown(Station* newStation) {
+ return new Hacking(newStation);
+}
+
+
+//-------
+// Hacking
+//-------
+
+Hacking::Hacking(Station* currentStation) {
+ this->currentStation = currentStation;
+}
+
+State* Hacking::pickedUp() {
+ return this;
+}
+
+//-------
+// Waiting F orPickup
+//-------
+
+WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStation) {
+ this->currentStation = currentStation;
+ this->targetStation = targetStation;
+}
+
+State* WaitingForPickup::pickedUp() {
+ return this;
+}
diff --git a/main/states.h b/main/states.h
new file mode 100644
index 0000000..8969b23
--- /dev/null
+++ b/main/states.h
@@ -0,0 +1,30 @@
+#pragma once
+#include
+#include "state.h"
+#include "states.h"
+#include "station.h"
+
+class OnTheMove : public State {
+private:
+ Station* targetStation;
+public:
+ OnTheMove(Station* targetStation);
+ State* putDown(Station* newSation) override;
+};
+
+class Hacking : public State {
+private:
+ Station* currentStation;
+public:
+ Hacking(Station* currentStation);
+ State* pickedUp() override;
+};
+
+class WaitingForPickup : public State {
+private:
+ Station* currentStation;
+ Station* targetStation;
+public:
+ WaitingForPickup(Station* currentStation, Station* targetStation);
+ State* pickedUp();
+};
\ No newline at end of file
diff --git a/main/station.cpp b/main/station.cpp
index 1b46910..68927c7 100644
--- a/main/station.cpp
+++ b/main/station.cpp
@@ -1,3 +1,4 @@
+#include
#include "station.h"
Station::Station(uint32_t nfcTagId, String name) {
@@ -10,3 +11,7 @@ Station::Station(uint32_t nfcTagId, String name) {
bool Station::check(uint32_t nfcTagId) {
return nfcTagId == this->nfcTagId;
}
+
+String Station::getName() {
+ return this->name;
+}
diff --git a/main/station.h b/main/station.h
index 876ffe1..c8468bc 100644
--- a/main/station.h
+++ b/main/station.h
@@ -8,4 +8,5 @@ private:
public:
Station(uint32_t nfcTagId, String name);
bool check(uint32_t nfcTagId);
+ String getName();
};