updates audio files

This commit is contained in:
Marcel 2024-05-31 15:55:14 +02:00
parent 27fc0535b3
commit 0ba199a777
27 changed files with 138 additions and 157 deletions

BIN
assets/0001Idle.mp3 (Stored with Git LFS)

Binary file not shown.

BIN
assets/0001WaitingForGameStart.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0002Falsche Nebenstation.mp3 (Stored with Git LFS)

Binary file not shown.

BIN
assets/0002OnTheMoveMainStation.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0003StationOneCorrect.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0003Timer abgelaufen.mp3 (Stored with Git LFS)

Binary file not shown.

BIN
assets/0004Spiel gewonnen.mp3 (Stored with Git LFS)

Binary file not shown.

BIN
assets/0004StationTwoCorrekt.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
assets/0005StationTreeCorrekt.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
assets/0006StationFourCorrekt.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0007Objekt auf Hauptstation.mp3 (Stored with Git LFS)

Binary file not shown.

BIN
assets/0007WrongStation.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0008Ende.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
assets/0009Stress.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0010StationTwoPickUp-240528_1353.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0011StationTreePickup-240528_1354.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/0012StationFourPickUp-240528_1357.mp3 (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -19,15 +19,14 @@
// The library in use is slightly modified to fix this issue: https://github.com/adafruit/Adafruit-PN532/issues/117
Adafruit_PN532 nfc(PN532_CS);
constexpr int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
SoftwareSerial softSerial(6, 7); // RX, TX
DFRobotDFPlayerMini dfPlayer;
Station stations[5] = {
Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"),
Station(2174777887, "Blue"), Station(102951984, "Weird")
Station(1680767519, "Main"), Station(102951984, "Muhvella"), Station(3346823711, "Magie"),
Station(2174777887, "Bicola"), Station(3569318175, "Tobione")
};
Station* currentStation;
int currentStationIndex = -1;
@ -158,13 +157,13 @@ void loop(void)
void setup(void)
{
initSequences();
setupNFC();
Serial.begin(9600);
// Serial.println(ON_MAIN_STATION.getEntryAtIndex(0)->isAudio);
setupNFC();
lcd.begin(16, 2);
stationDetectionTimer.start();
softSerial.begin(9600);
@ -183,5 +182,5 @@ void setup(void)
}
}
dfPlayer.volume(7);
dfPlayer.volume(18);
}

View file

@ -2,20 +2,3 @@
#include "sequence.h"
#include "sounds.h"
// Define global sequences
Sequence ON_MAIN_STATION(0);
Sequence AFTER_MAIN_STATION(0);
Sequence HACKING_STATION_MUHVELLA(0);
Sequence AFTER_MUHVELLA(0);
Sequence HACKING_STATION_MAGIE(0);
Sequence AFTER_MAGIE(0);
Sequence HACKING_STATION_BICOLA(0);
Sequence AFTER_BICOLA(0);
Sequence HACKING_STATION_TOBIONE(0);
Sequence AFTER_TOBIONE(0);
void initSequences() {
ON_MAIN_STATION.addEntry(SequenceEntry(true, 1000, IDLE));
ON_MAIN_STATION.addEntry(SequenceEntry(false, 3000, 0));
ON_MAIN_STATION.addEntry(SequenceEntry(true, 1000, IDLE));
}

View file

@ -1,16 +1,3 @@
#pragma once
#include "sequences.h"
#include "sequence.h"
extern Sequence ON_MAIN_STATION;
extern Sequence AFTER_MAIN_STATION;
extern Sequence HACKING_STATION_MUHVELLA;
extern Sequence AFTER_MUHVELLA;
extern Sequence HACKING_STATION_MAGIE;
extern Sequence AFTER_MAGIE;
extern Sequence HACKING_STATION_BICOLA;
extern Sequence AFTER_BICOLA;
extern Sequence HACKING_STATION_TOBIONE;
extern Sequence AFTER_TOBIONE;
void initSequences();

View file

@ -1,11 +1,26 @@
#include <Arduino.h>
#define NONE 0
#define IDLE 1
#define WRONG_SIDE_STATION 2
#define TIMER_DOWN 3
#define GAME_WON 4
#define REMOVED_FROM_SIDE_STATION 5
#define REMOVED_FROM_MAIN_STATION 6
#define OBJECT_PLACED_ON_MAIN_STATION 7
#define OBJECT_PLACED_ON_SIDE_STATION 8
#define WAITING_FOR_GAME_START 1
#define AFTER_MAIN_STATION 2
#define HACKING_STATION_MUHVELLA 3
#define PICKUP_STATION_MUHVELLA 10
#define AFTER_MUHVELLA 10 // incorrect
#define HACKING_STATION_MAGIE 4
#define PICKUP_STATION_MAGIE 11
#define AFTER_MAGIE 11 // incorrect
#define HACKING_STATION_BICOLA 5
#define PICKUP_STATION_BICOLA 12
#define AFTER_BICOLA 12 // incorrect
#define HACKING_STATION_TOBIONE 6
#define PICKUP_STATION_TOBIONE 13
#define AFTER_TOBIONE 13 // incorrect
#define END 8
#define WRONG_STATION 7
#define STRESS 9

View file

@ -10,23 +10,9 @@ class Station;
class State
{
private:
Timer sequenceTimer;
bool currentEntryHandled;
protected:
Sequence* sequence;
int sequencePointer;
bool sequenceDone;
public:
virtual ~State() = default;
explicit State(Sequence* sequence): sequenceTimer(Timer(0, false)), currentEntryHandled(false), sequence(sequence),
sequencePointer(0), sequenceDone(false)
{
}
virtual State* pickedUp(Context context) { return this; }
virtual State* putDown(Context context, Station* newStation) { return this; }
virtual State* update(Context context) { return this; }
@ -37,37 +23,4 @@ public:
virtual String updateDisplay() { return ""; }
void updateSeqence(const Context& context)
{
if (sequence == nullptr || sequence->getLength() == 0)
{
return;
}
if (!currentEntryHandled)
{
const auto currentEntry = sequence->getEntryAtIndex(sequencePointer);
const auto addressInt = reinterpret_cast<uintptr_t>(currentEntry);
this->sequenceTimer = Timer(currentEntry->duration, false);
this->sequenceTimer.start();
if (currentEntry->isAudio)
{
// printMp3Detail(context.dfPlayer->readType(), context.dfPlayer->read());
context.dfPlayer->play(currentEntry->audioId);
}
currentEntryHandled = true;
}
const bool timeOut = this->sequenceTimer.update(context.delta);
if (timeOut)
{
if (this->sequencePointer + 2 >= this->sequence->getLength())
{
sequencePointer = sequence->getRepeatIndex();
sequenceDone = true;
currentEntryHandled = false;
return;
}
this->sequencePointer += 1;
currentEntryHandled = false;
}
}
};

View file

@ -6,9 +6,7 @@
#include "station.h"
#include "sounds.h"
Startup::Startup(): State(nullptr)
{
}
Startup::Startup() = default;
State* Startup::putDown(const Context context, Station* newStation)
{
@ -23,7 +21,6 @@ State* Startup::putDown(const Context context, Station* newStation)
State* Startup::update(const Context context)
{
updateSeqence(context);
return this;
}
@ -41,20 +38,15 @@ void Startup::activated(Context context)
//------------------------------------
WaitingForGameStart::WaitingForGameStart() : State(&ON_MAIN_STATION)
{
}
WaitingForGameStart::WaitingForGameStart() = default;
State* WaitingForGameStart::pickedUp(const Context context)
{
return new OnTheMove(context.stations + 1, &AFTER_MAIN_STATION); // first element of the array
return new OnTheMove(context.stations + 1); // first element of the array
}
State* WaitingForGameStart::update(const Context context)
{
// Serial.println("update wait");
updateSeqence(context);
// Serial.println("after");
return this;
}
@ -66,14 +58,14 @@ String WaitingForGameStart::updateDisplay()
void WaitingForGameStart::activated(const Context context)
{
context.dfPlayer->play(IDLE);
context.dfPlayer->loop(WAITING_FOR_GAME_START);
}
//------------------------------------
OnTheMove::OnTheMove(Station* targetStation, Sequence* sequence): State(sequence)
OnTheMove::OnTheMove(Station* targetStation)
{
this->targetStation = targetStation;
}
@ -86,7 +78,7 @@ State* OnTheMove::putDown(const Context context, Station* newStation)
{
return new End();
}
return new Hacking(this->targetStation, nullptr);
return new Hacking(this->targetStation);
}
return new IncorrectStation(targetStation);
@ -94,7 +86,6 @@ State* OnTheMove::putDown(const Context context, Station* newStation)
State* OnTheMove::update(const Context context)
{
updateSeqence(context);
return this;
}
@ -108,11 +99,19 @@ void OnTheMove::activated(const Context context)
const int index = context.getStationIndex(this->targetStation);
if (index == 1)
{
context.dfPlayer->play(REMOVED_FROM_MAIN_STATION);
context.dfPlayer->play(AFTER_MAIN_STATION);
}
else
else if (index == 2)
{
context.dfPlayer->play(REMOVED_FROM_SIDE_STATION);
context.dfPlayer->play(AFTER_MUHVELLA);
}
else if (index == 3)
{
context.dfPlayer->play(AFTER_MAGIE);
}
else if (index == 4)
{
context.dfPlayer->play(AFTER_BICOLA);
}
}
@ -120,19 +119,18 @@ void OnTheMove::activated(const Context context)
//------------------------------------
IncorrectStation::IncorrectStation(Station* targetStation): State(nullptr) // todo remove nullptr
IncorrectStation::IncorrectStation(Station* targetStation)
{
this->targetStation = targetStation;
}
State* IncorrectStation::pickedUp(const Context context)
{
return new OnTheMove(this->targetStation, nullptr); // todo fix nullptr
return new OnTheMove(this->targetStation); // todo fix nullptr
}
State* IncorrectStation::update(const Context context)
{
updateSeqence(context);
return this;
}
@ -141,15 +139,16 @@ String IncorrectStation::updateDisplay()
return "Wrong Station! ";
}
void IncorrectStation::activated(Context context)
void IncorrectStation::activated(const Context context)
{
context.dfPlayer->play(WRONG_STATION);
}
//------------------------------------
Hacking::Hacking(Station* currentStation, Sequence* sequence): State(sequence), timer(5000, false)
Hacking::Hacking(Station* currentStation): timer(5000, false)
{
this->currentStation = currentStation;
this->timer.start();
@ -162,7 +161,6 @@ State* Hacking::pickedUp(const Context context)
State* Hacking::update(const Context context)
{
updateSeqence(context);
Serial.println(String(context.delta));
const bool done = timer.update(context.delta);
@ -171,7 +169,7 @@ State* Hacking::update(const Context context)
const int currentStationIndex = context.getStationIndex(currentStation);
const int nextStationIndex = (currentStationIndex + 1) % context.stationCount;
Station* nextStation = context.stations + nextStationIndex;
return new WaitingForPickup(currentStation, nextStation, nullptr);
return new WaitingForPickup(currentStation, nextStation);
}
return this;
}
@ -183,14 +181,35 @@ String Hacking::updateDisplay()
void Hacking::activated(const Context context)
{
context.dfPlayer->play(OBJECT_PLACED_ON_MAIN_STATION);
auto currentStationIndex = context.getStationIndex(this->currentStation);
if (currentStationIndex == 1)
{
timer = Timer(31000, false);
context.dfPlayer->play(HACKING_STATION_MUHVELLA);
}
if (currentStationIndex == 2)
{
timer = Timer(33000, false);
context.dfPlayer->play(HACKING_STATION_MAGIE);
}
if (currentStationIndex == 3)
{
timer = Timer(36000, false);
context.dfPlayer->play(HACKING_STATION_BICOLA);
}
if (currentStationIndex == 4)
{
timer = Timer(35000, false);
context.dfPlayer->play(HACKING_STATION_TOBIONE);
}
timer.start();
}
//------------------------------------
Complain::Complain(Station* currentStation): State(nullptr)
Complain::Complain(Station* currentStation)
{
this->currentStation = currentStation;
}
@ -199,7 +218,7 @@ State* Complain::putDown(const Context context, Station* newStation)
{
if (this->currentStation == newStation) // was put back on correct station
{
return new Hacking(this->currentStation, nullptr);
return new Hacking(this->currentStation);
}
return this; // was not put back on correct station (just keeps complaining)
}
@ -222,7 +241,7 @@ void Complain::activated(Context context)
//------------------------------------
WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStation, Sequence* sequence): State(sequence)
WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStation)
{
this->currentStation = currentStation;
this->targetStation = targetStation;
@ -230,7 +249,7 @@ WaitingForPickup::WaitingForPickup(Station* currentStation, Station* targetStati
State* WaitingForPickup::pickedUp(Context context)
{
return new OnTheMove(targetStation, nullptr);
return new OnTheMove(targetStation);
}
State* WaitingForPickup::update(Context context)
@ -245,17 +264,30 @@ String WaitingForPickup::updateDisplay()
void WaitingForPickup::activated(Context context)
{
auto currentStationIndex = context.getStationIndex(this->currentStation);
if (currentStationIndex == 1)
{
context.dfPlayer->loop(PICKUP_STATION_MUHVELLA);
}
if (currentStationIndex == 2)
{
context.dfPlayer->loop(PICKUP_STATION_MAGIE);
}
if (currentStationIndex == 3)
{
context.dfPlayer->loop(PICKUP_STATION_BICOLA);
}
if (currentStationIndex == 4)
{
context.dfPlayer->loop(PICKUP_STATION_TOBIONE);
}
}
//------------------------------------
End::End():State(nullptr)
{
}
End::End() = default;
State* End::pickedUp(const Context context)
{
@ -276,5 +308,5 @@ String End::updateDisplay()
void End::activated(const Context context)
{
context.dfPlayer->play(GAME_WON);
context.dfPlayer->play(END);
}

View file

@ -33,7 +33,7 @@ private:
Station* targetStation;
public:
explicit OnTheMove(Station* targetStation, Sequence* sequence);
explicit OnTheMove(Station* targetStation);
State* putDown(Context context, Station* newStation) override;
State* update(Context context) override;
String updateDisplay() override;
@ -61,7 +61,7 @@ private:
Station* currentStation;
public:
explicit Hacking(Station* currentStation, Sequence* sequence);
explicit Hacking(Station* currentStation);
State* pickedUp(Context context) override;
State* update(Context context) override;
String updateDisplay() override;
@ -88,7 +88,7 @@ private:
Station* targetStation;
public:
WaitingForPickup(Station* currentStation, Station* targetStation, Sequence* sequence);
WaitingForPickup(Station* currentStation, Station* targetStation);
State* pickedUp(Context context) override;
State* update(Context context) override;
String updateDisplay() override;