diff --git a/platformio.ini b/platformio.ini index 89e16ed..7b4935c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,3 +16,4 @@ lib_deps = adafruit/Adafruit BusIO@^1.16.1 dfrobot/DFRobotDFPlayerMini@^1.0.6 fmalpartida/LiquidCrystal@^1.5.0 + powerbroker2/DFPlayerMini_Fast@^1.2.4 diff --git a/src/audioState.h b/src/audioState.h index bc75ac7..e853445 100644 --- a/src/audioState.h +++ b/src/audioState.h @@ -1,73 +1,3 @@ #pragma once #include -#include #include - -void printMp3Detail(LiquidCrystal* lcd, 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 -} - diff --git a/src/context.cpp b/src/context.cpp index b9a6081..d4da98f 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -1,17 +1,22 @@ #include "Context.h" -Context::Context(Station* stations, const int stationCount, const unsigned long delta, DFRobotDFPlayerMini* dfPlayer) { - this->stations = stations; - this->stationCount = stationCount; - this->delta = delta; - this->dfPlayer = dfPlayer; +Context::Context(Station* stations, const int stationCount, const unsigned long delta, DFPlayerMini_Fast* dfPlayer) +{ + this->stations = stations; + this->stationCount = stationCount; + this->delta = delta; + this->dfPlayer = dfPlayer; } + int Context::getStationIndex(const Station* station) const { - for (int i = 0; i < stationCount; ++i) { - if (&stations[i] == station) { - return i; + for (int i = 0; i < stationCount; ++i) + { + if (&stations[i] == station) + { + return i; + } } - } - return -1; + return -1; } + diff --git a/src/context.h b/src/context.h index f1ee594..f521a3c 100644 --- a/src/context.h +++ b/src/context.h @@ -1,15 +1,16 @@ #pragma once -#include +#include #include "station.h" class Context { public: - Context(Station* stations, int stationCount, unsigned long delta, DFRobotDFPlayerMini* dfPlayer); + Context(Station* stations, int stationCount, unsigned long delta, DFPlayerMini_Fast* dfPlayer); Station* stations; int stationCount; unsigned long delta; - DFRobotDFPlayerMini* dfPlayer; + DFPlayerMini_Fast* dfPlayer; int getStationIndex(const Station* station) const; + bool isPlaying() const; }; diff --git a/src/main.cpp b/src/main.cpp index 8c2245a..130f17c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "station.h" #include "statemachine.h" @@ -22,7 +22,7 @@ constexpr 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 dfPlayer; +DFPlayerMini_Fast dfPlayer; Station stations[5] = { Station(1680767519, "Yellow"), Station(3346823711, "Green"), Station(3569318175, "Pink"), @@ -176,7 +176,8 @@ void setup(void) while (true) { delay(100); - printMp3Detail(&lcd, dfPlayer.readType(), dfPlayer.read()); + dfPlayer.printError(); + // printMp3Detail(&lcd, dfPlayer.readType(), dfPlayer.read()); } }