Merge branch 'main' into 'platformio'
# Conflicts: # .gitignore
This commit is contained in:
commit
2a94417f4d
23 changed files with 621 additions and 0 deletions
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
|
@ -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
|
8
.idea/BuenzliAI.iml
Normal file
8
.idea/BuenzliAI.iml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="CPP_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
105
.idea/editor.xml
Normal file
105
.idea/editor.xml
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/BuenzliAI.iml" filepath="$PROJECT_DIR$/.idea/BuenzliAI.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Bomb? Project
|
||||
|
BIN
libraries/Adafruit-PN532-1.3.3.zip
Normal file
BIN
libraries/Adafruit-PN532-1.3.3.zip
Normal file
Binary file not shown.
BIN
libraries/DFRobotDFPlayerMini-1.0.5.zip
Normal file
BIN
libraries/DFRobotDFPlayerMini-1.0.5.zip
Normal file
Binary file not shown.
BIN
libraries/og_Adafruit-PN532-1.3.3.zip
Normal file
BIN
libraries/og_Adafruit-PN532-1.3.3.zip
Normal file
Binary file not shown.
BIN
libraries/pn532_spi.zip
Normal file
BIN
libraries/pn532_spi.zip
Normal file
Binary file not shown.
BIN
libraries/vma211_spi.zip
Normal file
BIN
libraries/vma211_spi.zip
Normal file
Binary file not shown.
6
main/context.cpp
Normal file
6
main/context.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "Context.h"
|
||||
|
||||
Context::Context(Station* stations, unsigned long delta) {
|
||||
this->stations = stations;
|
||||
this->delta = delta;
|
||||
}
|
11
main/context.h
Normal file
11
main/context.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "station.h"
|
||||
|
||||
class Context {
|
||||
public:
|
||||
Context(Station* stations, unsigned long delta);
|
||||
|
||||
Station* stations;
|
||||
unsigned long delta;
|
||||
};
|
208
main/main.ino
Normal file
208
main/main.ino
Normal file
|
@ -0,0 +1,208 @@
|
|||
#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
|
||||
}
|
18
main/state.h
Normal file
18
main/state.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#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) { }
|
||||
};
|
32
main/statemachine.cpp
Normal file
32
main/statemachine.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#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);
|
||||
}
|
22
main/statemachine.h
Normal file
22
main/statemachine.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#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);
|
||||
};
|
62
main/states.cpp
Normal file
62
main/states.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#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]);
|
||||
}
|
45
main/states.h
Normal file
45
main/states.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#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;
|
||||
};
|
||||
|
17
main/station.cpp
Normal file
17
main/station.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#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;
|
||||
}
|
12
main/station.h
Normal file
12
main/station.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#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();
|
||||
};
|
33
main/timer.cpp
Normal file
33
main/timer.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#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;
|
||||
}
|
18
main/timer.h
Normal file
18
main/timer.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#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();
|
||||
};
|
Loading…
Reference in a new issue