From 1f54884c46e34f951d982ac0e2900562b24c99ce Mon Sep 17 00:00:00 2001 From: Torsten Stauder Date: Sun, 28 Mar 2021 00:21:51 +0100 Subject: [PATCH] Added support for fileseek --- README.md | 4 +-- changelog.md | 3 ++- src/main.cpp | 73 ++++++++++++++++++++++---------------------------- src/settings.h | 3 +++ 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 3fbde5f..d6de8eb 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ ## Build status ![build workflow](https://github.com/biologist79/ESPuino/actions/workflows/build.yml/badge.svg) ## Changelog -Moved to [another location](changelog.md) as it became to prominent here. Only last three events are kept: -* 26.02.2021: Shutdown via webgui is now available. +Moved to [another location](changelog.md). Only last three events are kept: * 05.03.2021: Added support for remote control via infrared. Make sure to enable `IR_CONTROL_ENABLE` to use this feature and don't forget to assign corresponding rc-commands of *your* remote control to actions. * 19.03.2021: Added support for port-expander PCA9555. Can be used for everything, that is "button-like": buttons, headphone-detect, PN5180.IRQ. +* 28.03.2021: Added support for fileseek. With commands `CMD_SEEK_FORWARDS` and `CMD_SEEK_BACKWARDS` it's possible to jump a number of seconds defined in `jumpOffset`. ## Known bugs * Some webstreams don't run. Guess it's a combination of saturated connection-pool and lack of heap-memory. Works probably better if ESP32-WROVER (e.g. Lolin D32 pro) is used, as this chip has PSRAM. Advice: Don't enable modules (e.g. MQTT) if you don't need them as this could save memory (and trouble). * English translation/version for webgui is currently pretty outdated. This will be fixed soon when i18n-support will be integrated. diff --git a/changelog.md b/changelog.md index e70e41a..4366ae2 100644 --- a/changelog.md +++ b/changelog.md @@ -32,4 +32,5 @@ * 25.02.2021: Added support for .m4a and .wav-files. * 26.02.2021: Shutdown via webgui is now available. * 05.03.2021: Added support for remote control via infrared. Make sure to enable `IR_CONTROL_ENABLE` to use this feature and don't forget to assign corresponding rc-commands of *your* remote control to actions. -* 19.03.2021: Added support for port-expander PCA9555. Can be used for everything, that is "button-like": buttons, headphone-detect, PN5180.IRQ. \ No newline at end of file +* 19.03.2021: Added support for port-expander PCA9555. Can be used for everything, that is "button-like": buttons, headphone-detect, PN5180.IRQ. +* 28.03.2021: Added support for fileseek. With commands `CMD_SEEK_FORWARDS` and `CMD_SEEK_BACKWARDS` it's possible to jump a number of seconds defined in `jumpOffset`. \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 866fa4c..55c5591 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,8 +131,7 @@ typedef struct { // Bit field bool trackFinished: 1; // If current track is finished bool playlistFinished: 1; // If whole playlist is finished uint8_t playUntilTrackNumber: 6; // Number of tracks to play after which uC goes to sleep - uint8_t currentSeekmode: 2; // If seekmode is active and if yes: forward or backwards? - uint8_t lastSeekmode: 2; // Helper to determine if seekmode was changed + uint8_t seekmode: 2; // If seekmode is active and if yes: forward or backwards? } playProps; playProps playProperties; @@ -1478,8 +1477,6 @@ void playAudio(void *parameter) { playProperties.trackFinished = false; if (playProperties.playMode == NO_PLAYLIST) { playProperties.playlistFinished = true; - //playProperties.currentSeekmode = SEEK_NORMAL; - //playProperties.lastSeekmode = SEEK_NORMAL; continue; } if (playProperties.saveLastPlayPosition) { // Don't save for AUDIOBOOK_LOOP because not necessary @@ -1785,25 +1782,34 @@ void playAudio(void *parameter) { } } - if (playProperties.currentSeekmode != playProperties.lastSeekmode) { - Serial.println(F("Seekmode has changed!")); // Todo - bool seekmodeChangeSuccessful = false; - if (playProperties.currentSeekmode == SEEK_NORMAL) { - seekmodeChangeSuccessful = audio.audioFileSeek(1); - } else if (playProperties.currentSeekmode == SEEK_FORWARDS) { - seekmodeChangeSuccessful = audio.audioFileSeek(4); - } else if (playProperties.currentSeekmode == SEEK_BACKWARDS) { - seekmodeChangeSuccessful = audio.audioFileSeek(-4); - } - - if (seekmodeChangeSuccessful) { - playProperties.lastSeekmode = playProperties.currentSeekmode; - } else { - playProperties.currentSeekmode = playProperties.lastSeekmode; - #ifdef NEOPIXEL_ENABLE - showLedError = true; - #endif + // Handle seekmodes + if (playProperties.seekmode != SEEK_NORMAL) { + if (playProperties.seekmode == SEEK_FORWARDS) { + if (audio.setTimeOffset(jumpOffset)) { + #if (LANGUAGE == 1) + Serial.printf("%d Sekunden nach vorne gesprungen\n", jumpOffset); + #else + Serial.printf("Jumped %d seconds forwards\n", jumpOffset); + #endif + } else { + #ifdef NEOPIXEL_ENABLE + showLedError = true; + #endif + } + } else if (playProperties.seekmode == SEEK_BACKWARDS) { + if (audio.setTimeOffset(-(jumpOffset))) { + #if (LANGUAGE == 1) + Serial.printf("%d Sekunden zurueck gesprungen\n", jumpOffset); + #else + Serial.printf("Jumped %d seconds backwards\n", jumpOffset); + #endif + } else { + #ifdef NEOPIXEL_ENABLE + showLedError = true; + #endif + } } + playProperties.seekmode = SEEK_NORMAL; } // Calculate relative position in file (for neopixel) for SD-card-mode @@ -3235,25 +3241,11 @@ void doCmdAction(const uint16_t mod) { break; } case CMD_SEEK_FORWARDS: { - Serial.println(F("Seek forwards")); // todo - if (playProperties.currentSeekmode == SEEK_FORWARDS) { - playProperties.currentSeekmode = SEEK_NORMAL; - } else { - playProperties.currentSeekmode = SEEK_FORWARDS; - } - Serial.println(playProperties.currentSeekmode); - Serial.println(playProperties.lastSeekmode); + playProperties.seekmode = SEEK_FORWARDS; break; } case CMD_SEEK_BACKWARDS: { - Serial.println(F("Seek backwards")); // todo - if (playProperties.currentSeekmode == SEEK_BACKWARDS) { - playProperties.currentSeekmode = SEEK_NORMAL; - } else { - playProperties.currentSeekmode = SEEK_BACKWARDS; - } - Serial.println(playProperties.currentSeekmode); - Serial.println(playProperties.lastSeekmode); + playProperties.seekmode = SEEK_BACKWARDS; break; } default: { @@ -4664,8 +4656,7 @@ void setup() { playProperties.pausePlay = false; playProperties.trackFinished = NULL; playProperties.playlistFinished = true; - playProperties.currentSeekmode = SEEK_NORMAL; - playProperties.lastSeekmode = SEEK_NORMAL; + playProperties.seekmode = SEEK_NORMAL; // Examples for serialized RFID-actions that are stored in NVS // #### @@ -4746,7 +4737,7 @@ void setup() { loggerNl(serialDebug, (char *) FPSTR(rfidScannerReady), LOGLEVEL_DEBUG); #endif - // Init RC522 Card-Reader + // Init RC522 Card-Reader #if defined(RFID_READER_TYPE_MFRC522_I2C) || defined(RFID_READER_TYPE_MFRC522_SPI) mfrc522.PCD_Init(); mfrc522.PCD_SetAntennaGain(rfidGain); diff --git a/src/settings.h b/src/settings.h index 83a1688..72c4950 100644 --- a/src/settings.h +++ b/src/settings.h @@ -189,6 +189,9 @@ uint16_t headphoneLastDetectionDebounce = 1000; // Debounce-interval in ms when plugging in headphone #endif + // Seekmode-configuration + uint8_t jumpOffset = 30; // Offset in seconds to jump for commands CMD_SEEK_FORWARDS / CMD_SEEK_BACKWARDS + // (optional) Topics for MQTT #ifdef MQTT_ENABLE uint16_t mqttRetryInterval = 60; // Try to reconnect to MQTT-server every (n) seconds if connection is broken