fiexes merge issues

This commit is contained in:
Marcel 2024-06-05 10:49:49 +02:00
parent 16b14972b4
commit 8e641a76ca
14 changed files with 1 additions and 584 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
.pio
.idea
.idea/

View file

@ -2,104 +2,5 @@
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
<option name="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASPI_002Eh_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FLocal_003FTemp_003F7e10e8c0_002D08d1_002D4626_002D8c7e_002D9a1cd5f4c818_005Fvma211_005Fspi_002Ezip_002E818_003Fvma211_005Fspi_003FSPI_002Eh/@EntryIndexedValue" />
<option name="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASPI_002Eh_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FLocal_003FTemp_003F7e10e8c0_002D08d1_002D4626_002D8c7e_002D9a1cd5f4c818_005Fvma211_005Fspi_002Ezip_002E818_003Fvma211_005Fspi_003FSPI_002Eh/@EntryIndexRemoved" />
</component>
</project>

View file

@ -1,6 +0,0 @@
#include "Context.h"
Context::Context(Station* stations, unsigned long delta) {
this->stations = stations;
this->delta = delta;
}

View file

@ -1,11 +0,0 @@
#pragma once
#include <Arduino.h>
#include "station.h"
class Context {
public:
Context(Station* stations, unsigned long delta);
Station* stations;
unsigned long delta;
};

View file

@ -1,208 +0,0 @@
#include <LiquidCrystal.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include "station.h"
#include "statemachine.h"
#include "state.h"
#include "states.h"
#include "timer.h"
#define PN532_CS 10
// Using this library to set a timeout on readPassiveTagID
// The library in use is slightly modified to fix this issue: https://github.com/adafruit/Adafruit-PN532/issues/117
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);
SoftwareSerial softSerial(6, 7); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
Station stations[4] = { Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"), Station(2174777887, "Blue") };
Station* currentStation;
Timer stationDetectionTimer(500, true);
StateMachine stateMachine(new Startup());
unsigned long lastLoopTime = 0;
unsigned long currentLoopTime = 0;
unsigned long deltaTime = 0;
void setup(void) {
setupNFC();
lcd.begin(16, 2);
stationDetectionTimer.start();
softSerial.begin(9600);
lcd.print("Initializing MP3");
lcd.clear();
if (!myDFPlayer.begin(softSerial, true, true)) {
lcd.print("Failed to init");
lcd.setCursor(0, 1);
lcd.print("DFPlayer!");
while (true) {
delay(100);
printMp3Detail(myDFPlayer.readType(), myDFPlayer.read());
}
}
myDFPlayer.volume(5);
myDFPlayer.play(1);
}
void loop(void) {
currentLoopTime = millis();
deltaTime = currentLoopTime - lastLoopTime;
bool doCheck = stationDetectionTimer.update(deltaTime);
lcd.setCursor(0, 1);
lcd.print(" ");
if (doCheck) {
checkStations();
lcd.setCursor(7, 1);
lcd.print("check");
}
lcd.setCursor(0, 1);
lcd.print(String(deltaTime));
stateMachine.update(Context(stations, deltaTime));
lastLoopTime = currentLoopTime;
delay(10);
}
void setupNFC() {
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (!versiondata) {
while (1)
; // halt
}
// configure board to read RFID tags and cards
nfc.SAMConfig();
}
void checkStations() {
Station* station = detectStation();
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() {
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];
if (currentStation->check(id)) {
found = currentStation;
}
}
return found;
}
void printMp3Detail(uint8_t type, int value) {
lcd.clear();
switch (type) {
case TimeOut:
lcd.print("Time Out!");
break;
case WrongStack:
lcd.print("Stack Wrong!");
break;
case DFPlayerCardInserted:
lcd.print("Card Inserted!");
break;
case DFPlayerCardRemoved:
lcd.print("Card Removed!");
break;
case DFPlayerCardOnline:
lcd.print("Card Online!");
break;
case DFPlayerUSBInserted:
lcd.print("USB Inserted!");
break;
case DFPlayerUSBRemoved:
lcd.print("USB Removed!");
break;
case DFPlayerPlayFinished:
lcd.print("Num:");
lcd.print(value);
lcd.print(" Finished!");
break;
case DFPlayerError:
lcd.print("DFPlayerError:");
switch (value) {
case Busy:
lcd.print("Card not found");
break;
case Sleeping:
lcd.print("Sleeping");
break;
case SerialWrongStack:
lcd.print("Wrong Stack");
break;
case CheckSumNotMatch:
lcd.print("Checksum Error");
break;
case FileIndexOut:
lcd.print("File Index OOB");
break;
case FileMismatch:
lcd.print("File Mismatch");
break;
case Advertise:
lcd.print("In Advertise");
break;
default:
lcd.print("Unknown Error");
break;
}
break;
default:
lcd.print("Unknown Type");
break;
}
delay(2000); // Display the message for 2 seconds
}

View file

@ -1,18 +0,0 @@
#pragma once
#include <Arduino.h>
#include <LiquidCrystal.h>
#include "station.h"
#include "context.h"
class Station;
class State {
public:
virtual ~State() = default;
virtual State* pickedUp() { return this; }
virtual State* putDown(Station* newStation) { return this; }
virtual State* update(Context context) { return this; }
virtual void updateDisplay(LiquidCrystal* lcd) { }
};

View file

@ -1,32 +0,0 @@
#include "statemachine.h"
#include "station.h"
#include "context.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(Context context) {
State* newState = currentState->update(context);
updateState(newState);
}

View file

@ -1,22 +0,0 @@
#pragma once
#include <Arduino.h>
#include <LiquidCrystal.h>
#include "state.h"
#include "station.h"
#include "context.h"
class StateMachine {
private:
State* currentState;
void updateState(State* newState);
public:
StateMachine(State* initialState);
~StateMachine();
void pickedUp();
void putDown(Station* newSation);
void update(Context context);
void updateDisplay(LiquidCrystal* lcd);
};

View file

@ -1,62 +0,0 @@
#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;
}
//-------
// Startup
//-------
State* Startup::putDown(Station* newStation) {
return new NewTargetFinder(newStation);
}
//-------
// NewTargetFinder
//-------
NewTargetFinder::NewTargetFinder(Station* currentStation) {
this->currentStation = currentStation;
}
State* NewTargetFinder::update(Context context) {
return new WaitingForPickup(this->currentStation, (&context.stations)[0]);
}

View file

@ -1,45 +0,0 @@
#pragma once
#include <Arduino.h>
#include "context.h"
#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() override;
};
class Startup : public State {
public:
State* putDown(Station* newSation) override;
};
class NewTargetFinder : public State {
private:
Station* currentStation;
public:
NewTargetFinder(Station* currentStation);
State* update(Context context) override;
};

View file

@ -1,17 +0,0 @@
#include <Arduino.h>
#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;
}
String Station::getName() {
return this->name;
}

View file

@ -1,12 +0,0 @@
#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);
String getName();
};

View file

@ -1,33 +0,0 @@
#include "timer.h"
Timer::Timer(unsigned long duration, bool autoRestart) {
this->autoRestart = autoRestart;
this->duration = duration;
this->endTime = duration;
}
void Timer::start() {
this->running = true;
}
bool Timer::update(unsigned long delta) {
if (!running) {
return false;
}
bool timedOut = false;
this->currentTime += delta;
if (currentTime > this->endTime) {
timedOut = true;
}
if (timedOut && this->autoRestart) {
this->endTime += this->duration;
}
if (timedOut && !this->autoRestart) {
running = false;
}
return timedOut;
}
bool Timer::isRunning() {
return this->running;
}

View file

@ -1,18 +0,0 @@
#pragma once
#include <Arduino.h>
class Timer {
private:
unsigned long duration;
bool autoRestart;
unsigned long currentTime;
unsigned long endTime;
bool running;
public:
Timer(unsigned long duration, bool autoRestart);
void start();
bool update(unsigned long delta);
bool isRunning();
};