diff --git a/src/main.cpp.old b/src/main.cpp.old deleted file mode 100644 index 13c63e7..0000000 --- a/src/main.cpp.old +++ /dev/null @@ -1,188 +0,0 @@ -// Cleaned up and fixed to use SoftwareSerial on D4 (RX) and D1 (TX) - -#include -#include -#include - -class Mp3Notify; - -// Use a DFPlayer variant that doesn't require ACKs on all commands -// to avoid blocking on modules that don't ACK reset. -typedef DFMiniMp3 DfMp3; -// DFPlayer wiring: DF TX -> D4 (GPIO2), DF RX -> D1 (GPIO5) -// Important: Do NOT use GPIO1/GPIO3 for DFPlayer if you want USB Serial. -// SoftwareSerial args are (rx, tx) from ESP8266 perspective. -SoftwareSerial mp3Serial(/*rx =*/D4, /*tx =*/D1); -DfMp3 dfmp3(mp3Serial); - -// NOTE: These GPIO numbers currently map to GPIO0, GPIO1, GPIO2, GPIO3. -// Adjust to your wiring; avoid using GPIO1 (TX0) and GPIO2 (D4) if used by DFPlayer. -const int buzzerPins[4] = {0, 1, 2, 3}; // FIXME: update to match your wiring -const int ledPins[4] = {14, 12, 13, 15}; // D5–D8 -const int resetPin = 16; // D0 - -int activeBuzzer = -1; -bool adminMode = false; -unsigned long resetPressStart = 0; - -class Mp3Notify -{ -public: - static void PrintlnSourceAction(DfMp3_PlaySources source, const char *action) - { - if (source & DfMp3_PlaySources_Sd) - { - Serial.print("SD Card, "); - } - if (source & DfMp3_PlaySources_Usb) - { - Serial.print("USB Disk, "); - } - if (source & DfMp3_PlaySources_Flash) - { - Serial.print("Flash, "); - } - Serial.println(action); - } - static void OnError([[maybe_unused]] DfMp3 &mp3, uint16_t errorCode) - { - Serial.println(); - Serial.print("Com Error "); - Serial.println(errorCode); - } - static void OnPlayFinished([[maybe_unused]] DfMp3 &mp3, [[maybe_unused]] DfMp3_PlaySources source, uint16_t track) - { - Serial.print("Play finished for #"); - Serial.println(track); - - track += 1; - if (track > 3) - { - track = 1; - } - dfmp3.playMp3FolderTrack(track); - } - static void OnPlaySourceOnline([[maybe_unused]] DfMp3 &mp3, DfMp3_PlaySources source) - { - PrintlnSourceAction(source, "online"); - } - static void OnPlaySourceInserted([[maybe_unused]] DfMp3 &mp3, DfMp3_PlaySources source) - { - PrintlnSourceAction(source, "inserted"); - } - static void OnPlaySourceRemoved([[maybe_unused]] DfMp3 &mp3, DfMp3_PlaySources source) - { - PrintlnSourceAction(source, "removed"); - } -}; - -void setup() -{ - Serial.begin(9600); - Serial.println("Booting..."); - - mp3Serial.begin(9600); - Serial.println("After mp3Serial begin"); - - dfmp3.begin(); - dfmp3.setComRetries(1); // reduce blocking if no response - Serial.println("After dfmp3 begin"); - - delay(200); // let DFPlayer settle - - dfmp3.reset(); - // many DFPlayer clones need >1s after reset before responding reliably - delay(1200); - Serial.println("After dfmp3 reset"); - - for (int i = 0; i < 4; i++) - { - pinMode(buzzerPins[i], INPUT_PULLUP); - pinMode(ledPins[i], OUTPUT); - digitalWrite(ledPins[i], LOW); - } - pinMode(resetPin, INPUT_PULLUP); - - // Warn about potential pin conflicts with DFPlayer serial (D4/D1) - for (int i = 0; i < 4; i++) - { - if (buzzerPins[i] == D4 || buzzerPins[i] == D1) - { - Serial.print("WARNING: buzzer pin conflicts with DF serial: index "); - Serial.println(i); - } - } - - uint16_t version = dfmp3.getSoftwareVersion(); - Serial.print("version "); - Serial.println(version); - - uint16_t volume = dfmp3.getVolume(); - Serial.print("volume "); - Serial.println(volume); - dfmp3.setVolume(24); - - uint16_t count = dfmp3.getTotalTrackCount(DfMp3_PlaySource_Sd); - Serial.print("files "); - Serial.println(count); - - Serial.println("starting..."); - - dfmp3.playMp3FolderTrack(1); -} - -void loop() -{ - // Process DFPlayer callbacks - dfmp3.loop(); - - if (digitalRead(resetPin) == LOW && resetPressStart == 0) - { - resetPressStart = millis(); - } - - if (digitalRead(resetPin) == LOW && !adminMode && millis() - resetPressStart > 3000) - { - adminMode = true; - for (int i = 0; i < 4; i++) - { - digitalWrite(ledPins[i], HIGH); - } - } - - if (digitalRead(resetPin) == HIGH && resetPressStart != 0) - { - if (adminMode) - { - adminMode = false; - for (int i = 0; i < 4; i++) - { - digitalWrite(ledPins[i], LOW); - } - activeBuzzer = -1; - } - else if (activeBuzzer != -1) - { - digitalWrite(ledPins[activeBuzzer], LOW); - activeBuzzer = -1; - } - resetPressStart = 0; - delay(300); - } - - if (activeBuzzer == -1 && !adminMode) - { - for (int i = 0; i < 4; i++) - { - if (digitalRead(buzzerPins[i]) == LOW) - { - activeBuzzer = i; - for (int j = 0; j < 4; j++) - { - digitalWrite(ledPins[j], j == i ? HIGH : LOW); - } - break; - } - } - } -}