diff --git a/exsamples/myoptions.h b/exsamples/myoptions.h index 0272003..22a47c2 100644 --- a/exsamples/myoptions.h +++ b/exsamples/myoptions.h @@ -73,6 +73,7 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti /******************************************/ /* SDCARD */ +/* MISO is the same as D0, MOSI is the same as D1 */ //#define SDC_SPI 18, 19, 23 /* SDCARD SPI pins (SCK, MISO, MOSI) */ //#define SDC_CS 255 /* SDCARD CS pin */ diff --git a/yoRadio/data/www/style.css.gz b/yoRadio/data/www/style.css.gz index 81c9132..2d9fc53 100644 Binary files a/yoRadio/data/www/style.css.gz and b/yoRadio/data/www/style.css.gz differ diff --git a/yoRadio/src/audioI2S/Audio.cpp b/yoRadio/src/audioI2S/Audio.cpp index df60170..14fadd6 100644 --- a/yoRadio/src/audioI2S/Audio.cpp +++ b/yoRadio/src/audioI2S/Audio.cpp @@ -166,7 +166,7 @@ Audio::Audio(bool internalDAC /* = false */, uint8_t channelEnabled /* = I2S_DAC #ifdef AUDIO_LOG m_f_Log = true; #endif - + mutex_pl = xSemaphoreCreateMutex(); clientsecure.setInsecure(); // if that can't be resolved update to ESP32 Arduino version 1.0.5-rc05 or higher m_f_channelEnabled = channelEnabled; m_f_internalDAC = internalDAC; @@ -679,7 +679,8 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) { } AUDIO_INFO("Reading file: \"%s\"", audioName); vTaskDelay(2); - + if(audio_beginSDread) audio_beginSDread(); + cardLock(true); if(fs.exists(audioName)) { audiofile = fs.open(audioName); // #86 } @@ -689,24 +690,24 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) { audiofile = fs.open(audioName); } } - + cardLock(false); if(!audiofile) { if(audio_info) {vTaskDelay(2); audio_info("Failed to open file for reading");} return false; } - + cardLock(true); setDatamode(AUDIO_LOCALFILE); m_file_size = audiofile.size();//TEST loop - + cardLock(false); char* afn = NULL; // audioFileName - +cardLock(true); #ifdef SDFATFS_USED audiofile.getName(chbuf, sizeof(chbuf)); afn = strdup(chbuf); #else afn = strdup(audiofile.name()); #endif - +cardLock(false); uint8_t dotPos = lastIndexOf(afn, "."); for(uint8_t i = dotPos + 1; i < strlen(afn); i++){ afn[i] = toLowerCase(afn[i]); @@ -724,7 +725,9 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) { bool ret = initializeDecoder(); if(ret) m_f_running = true; - else audiofile.close(); + else { + cardLock(true);audiofile.close();cardLock(false); + } return ret; } //--------------------------------------------------------------------------------------------------------------------- @@ -974,7 +977,7 @@ void Audio::showID3Tag(const char* tag, const char* value){ if(!strcmp(tag, "OWNE")) sprintf(chbuf, "Ownership: %s", value); // if(!strcmp(tag, "PRIV")) sprintf(chbuf, "Private: %s", value); if(!strcmp(tag, "SYLT")) sprintf(chbuf, "SynLyrics: %s", value); - if(!strcmp(tag, "TALB")) sprintf(chbuf, "Album: %s", value); + if(!strcmp(tag, "TALB")) { sprintf(chbuf, "Album: %s", value); if(audio_id3album) audio_id3album(value); } if(!strcmp(tag, "TBPM")) sprintf(chbuf, "BeatsPerMinute: %s", value); if(!strcmp(tag, "TCMP")) sprintf(chbuf, "Compilation: %s", value); if(!strcmp(tag, "TCOM")) sprintf(chbuf, "Composer: %s", value); @@ -984,7 +987,7 @@ void Audio::showID3Tag(const char* tag, const char* value){ if(!strcmp(tag, "TEXT")) sprintf(chbuf, "Lyricist: %s", value); if(!strcmp(tag, "TIME")) sprintf(chbuf, "Time: %s", value); if(!strcmp(tag, "TIT1")) sprintf(chbuf, "Grouping: %s", value); - if(!strcmp(tag, "TIT2")) sprintf(chbuf, "Title: %s", value); + if(!strcmp(tag, "TIT2")) { sprintf(chbuf, "Title: %s", value); if(audio_id3album) audio_id3album(value); } if(!strcmp(tag, "TIT3")) sprintf(chbuf, "Subtitle: %s", value); if(!strcmp(tag, "TLAN")) sprintf(chbuf, "Language: %s", value); if(!strcmp(tag, "TLEN")) sprintf(chbuf, "Length (ms): %s", value); @@ -992,7 +995,7 @@ void Audio::showID3Tag(const char* tag, const char* value){ if(!strcmp(tag, "TOAL")) sprintf(chbuf, "OriginalAlbum: %s", value); if(!strcmp(tag, "TOPE")) sprintf(chbuf, "OriginalArtist: %s", value); if(!strcmp(tag, "TORY")) sprintf(chbuf, "OriginalReleaseYear: %s", value); - if(!strcmp(tag, "TPE1")) sprintf(chbuf, "Artist: %s", value); + if(!strcmp(tag, "TPE1")) { sprintf(chbuf, "Artist: %s", value); if(audio_id3artist) audio_id3artist(value); } if(!strcmp(tag, "TPE2")) sprintf(chbuf, "Band: %s", value); if(!strcmp(tag, "TPE3")) sprintf(chbuf, "Conductor: %s", value); if(!strcmp(tag, "TPE4")) sprintf(chbuf, "InterpretedBy: %s", value); @@ -1728,9 +1731,11 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) { m_audioDataSize = m_contentlength - m_audioDataStart; AUDIO_INFO("Audio-Length: %u", m_audioDataSize); if(APIC_seen && audio_id3image){ + cardLock(true); size_t pos = audiofile.position(); audio_id3image(audiofile, APIC_pos, APIC_size); audiofile.seek(pos); // the filepointer could have been changed by the user, set it back + cardLock(false); } return 0; } @@ -2250,13 +2255,13 @@ uint32_t Audio::stopSong() { if(getDatamode() == AUDIO_LOCALFILE){ m_streamType = ST_NONE; pos = getFilePos() - inBufferFilled(); - audiofile.close(); + cardLock(true);audiofile.close();cardLock(false); AUDIO_INFO("Closing audio file"); } } if(audiofile){ // added this before putting 'm_f_localfile = false' in stopSong(); shoulf never occur.... - audiofile.close(); + cardLock(true);audiofile.close();cardLock(false); AUDIO_INFO("Closing audio file"); log_w("Closing audio file"); // for debug } @@ -2404,6 +2409,17 @@ bool Audio::playChunk() { return false; } //--------------------------------------------------------------------------------------------------------------------- + +void Audio::cardLock(bool lock){ +#if (TFT_CS!=255) || (SDC_CS!=255) + if(lock){ + xSemaphoreTake(mutex_pl, portMAX_DELAY); + }else{ + xSemaphoreGive(mutex_pl); + } +#endif +} + void Audio::loop() { if(!m_f_running) return; @@ -2903,7 +2919,7 @@ void Audio::processLocalFile() { if(m_resumeFilePos){ if(m_resumeFilePos < m_audioDataStart) m_resumeFilePos = m_audioDataStart; if(m_avr_bitrate) m_audioCurrentTime = ((m_resumeFilePos - m_audioDataStart) / m_avr_bitrate) * 8; - audiofile.seek(m_resumeFilePos); + cardLock(true);audiofile.seek(m_resumeFilePos);cardLock(false); InBuff.resetBuffer(); if(m_f_Log) log_i("m_resumeFilePos %i", m_resumeFilePos); } @@ -2921,7 +2937,7 @@ void Audio::processLocalFile() { } //---------------------------------------------------------------------------------------------------- - bytesAddedToBuffer = audiofile.read(InBuff.getWritePtr(), bytesCanBeWritten); + cardLock(true); bytesAddedToBuffer = audiofile.read(InBuff.getWritePtr(), bytesCanBeWritten); cardLock(false); if(bytesAddedToBuffer > 0) { InBuff.bytesWritten(bytesAddedToBuffer); } @@ -2974,14 +2990,14 @@ void Audio::processLocalFile() { } //TEST loop f_stream = false; m_streamType = ST_NONE; - +cardLock(true); #ifdef SDFATFS_USED audiofile.getName(chbuf, sizeof(chbuf)); char *afn =strdup(chbuf); #else char *afn =strdup(audiofile.name()); // store temporary the name #endif - +cardLock(false); stopSong(); if(m_codec == CODEC_MP3) MP3Decoder_FreeBuffers(); if(m_codec == CODEC_AAC) AACDecoder_FreeBuffers(); @@ -4336,12 +4352,18 @@ bool Audio::setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT, int8_t DIN, int8_ //--------------------------------------------------------------------------------------------------------------------- uint32_t Audio::getFileSize() { if(!audiofile) return 0; - return audiofile.size(); + cardLock(true); + uint32_t s = audiofile.size(); + cardLock(false); + return s; } //--------------------------------------------------------------------------------------------------------------------- uint32_t Audio::getFilePos() { if(!audiofile) return 0; - return audiofile.position(); + cardLock(true); + uint32_t p = audiofile.position(); + cardLock(false); + return p; } //--------------------------------------------------------------------------------------------------------------------- uint32_t Audio::getAudioDataStartPos() { diff --git a/yoRadio/src/audioI2S/AudioEx.h b/yoRadio/src/audioI2S/AudioEx.h index 5d6ab3f..3e8a070 100644 --- a/yoRadio/src/audioI2S/AudioEx.h +++ b/yoRadio/src/audioI2S/AudioEx.h @@ -73,6 +73,10 @@ using namespace std; extern __attribute__((weak)) void audio_info(const char*); extern __attribute__((weak)) void audio_id3data(const char*); //ID3 metadata +extern __attribute__((weak)) void audio_id3artist(const char*); +extern __attribute__((weak)) void audio_id3album(const char*); +extern __attribute__((weak)) void audio_id3title(const char*); +extern __attribute__((weak)) void audio_beginSDread(); extern __attribute__((weak)) void audio_id3image(File& file, const size_t pos, const size_t size); //ID3 metadata image extern __attribute__((weak)) void audio_eof_mp3(const char*); //end of mp3 file extern __attribute__((weak)) void audio_showstreamtitle(const char*); @@ -213,7 +217,7 @@ public: void setI2SCommFMT_LSB(bool commFMT); int getCodec() {return m_codec;} const char *getCodecname() {return codecname[m_codec];} - + void cardLock(bool lock); private: #ifndef ESP_ARDUINO_VERSION_VAL diff --git a/yoRadio/src/audioVS1053/audioVS1053Ex.cpp b/yoRadio/src/audioVS1053/audioVS1053Ex.cpp index 8ed90f4..03ddd65 100644 --- a/yoRadio/src/audioVS1053/audioVS1053Ex.cpp +++ b/yoRadio/src/audioVS1053/audioVS1053Ex.cpp @@ -568,6 +568,16 @@ void Audio::showstreamtitle(const char* ml) { } } //--------------------------------------------------------------------------------------------------------------------- +void Audio::cardLock(bool lock){ +#if (TFT_CS!=255) || (SDC_CS!=255) + if(lock){ + xSemaphoreTake(mutex_pl, portMAX_DELAY); + }else{ + xSemaphoreGive(mutex_pl); + } +#endif +} +//--------------------------------------------------------------------------------------------------------------------- void Audio::loop(){ // - localfile - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if(m_f_localfile) { // Playing file fron SPIFFS or SD? @@ -634,7 +644,7 @@ void Audio::processLocalFile() { } } //---------------------------------------------------------------------------------------------------- - bytesAddedToBuffer = audiofile.read(InBuff.getWritePtr(), bytesCanBeWritten); + cardLock(true); bytesAddedToBuffer = audiofile.read(InBuff.getWritePtr(), bytesCanBeWritten); cardLock(false); if(bytesAddedToBuffer > 0) { InBuff.bytesWritten(bytesAddedToBuffer); } @@ -718,9 +728,9 @@ void Audio::processLocalFile() { f_stream = false; m_f_localfile = false; - + cardLock(true); char *afn =strdup(audiofile.name()); // store temporary the name - + cardLock(false); stopSong(); sprintf(chbuf, "End of file \"%s\"", afn); if(audio_info) audio_info(chbuf); @@ -1562,7 +1572,7 @@ uint32_t Audio::stop_mp3client(){ uint32_t pos = 0; if(m_f_localfile){ pos = getFilePos() - InBuff.bufferFilled(); - audiofile.close(); + cardLock(true); audiofile.close(); cardLock(false); m_f_localfile=false; } int v=read_register(SCI_VOL); @@ -1897,14 +1907,14 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) { sprintf(chbuf, "Reading file: \"%s\"", audioName); if(audio_info) {vTaskDelay(2); audio_info(chbuf);} - - audiofile.close(); + if(audio_beginSDread) audio_beginSDread(); + cardLock(true); audiofile.close(); cardLock(false); if(fs.exists(audioName)) { - audiofile = fs.open(audioName); + cardLock(true); audiofile = fs.open(audioName); cardLock(false); } else { UTF8toASCII(audioName); if(fs.exists(audioName)) { - audiofile = fs.open(audioName); + cardLock(true); audiofile = fs.open(audioName); cardLock(false); } } @@ -1914,9 +1924,11 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) { } m_f_localfile = true; + cardLock(true); m_file_size = audiofile.size();//TEST loop - + char* afn = strdup(audiofile.name()); // audioFileName + cardLock(false); uint8_t dotPos = lastIndexOf(afn, "."); for(uint8_t i = dotPos + 1; i < strlen(afn); i++){ afn[i] = toLowerCase(afn[i]); @@ -1960,7 +1972,7 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) { sprintf(chbuf, "The %s format is not supported", afn + dotPos); if(audio_info) audio_info(chbuf); - audiofile.close(); + cardLock(true); audiofile.close(); cardLock(false); if(afn) free(afn); return false; } @@ -2391,7 +2403,7 @@ void Audio::showID3Tag(const char* tag, const char* value){ if(!strcmp(tag, "OWNE")) sprintf(chbuf, "Ownership: %s", value); // if(!strcmp(tag, "PRIV")) sprintf(chbuf, "Private: %s", value); if(!strcmp(tag, "SYLT")) sprintf(chbuf, "SynLyrics: %s", value); - if(!strcmp(tag, "TALB")) sprintf(chbuf, "Album: %s", value); + if(!strcmp(tag, "TALB")) { sprintf(chbuf, "Album: %s", value); if(audio_id3album) audio_id3album(value); } if(!strcmp(tag, "TBPM")) sprintf(chbuf, "BeatsPerMinute: %s", value); if(!strcmp(tag, "TCMP")) sprintf(chbuf, "Compilation: %s", value); if(!strcmp(tag, "TCOM")) sprintf(chbuf, "Composer: %s", value); @@ -2401,7 +2413,7 @@ void Audio::showID3Tag(const char* tag, const char* value){ if(!strcmp(tag, "TEXT")) sprintf(chbuf, "Lyricist: %s", value); if(!strcmp(tag, "TIME")) sprintf(chbuf, "Time: %s", value); if(!strcmp(tag, "TIT1")) sprintf(chbuf, "Grouping: %s", value); - if(!strcmp(tag, "TIT2")) sprintf(chbuf, "Title: %s", value); + if(!strcmp(tag, "TIT2")) { sprintf(chbuf, "Title: %s", value); if(audio_id3album) audio_id3album(value); } if(!strcmp(tag, "TIT3")) sprintf(chbuf, "Subtitle: %s", value); if(!strcmp(tag, "TLAN")) sprintf(chbuf, "Language: %s", value); if(!strcmp(tag, "TLEN")) sprintf(chbuf, "Length (ms): %s", value); @@ -2409,7 +2421,7 @@ void Audio::showID3Tag(const char* tag, const char* value){ if(!strcmp(tag, "TOAL")) sprintf(chbuf, "OriginalAlbum: %s", value); if(!strcmp(tag, "TOPE")) sprintf(chbuf, "OriginalArtist: %s", value); if(!strcmp(tag, "TORY")) sprintf(chbuf, "OriginalReleaseYear: %s", value); - if(!strcmp(tag, "TPE1")) sprintf(chbuf, "Artist: %s", value); + if(!strcmp(tag, "TPE1")) { sprintf(chbuf, "Artist: %s", value); if(audio_id3artist) audio_id3artist(value); } if(!strcmp(tag, "TPE2")) sprintf(chbuf, "Band: %s", value); if(!strcmp(tag, "TPE3")) sprintf(chbuf, "Conductor: %s", value); if(!strcmp(tag, "TPE4")) sprintf(chbuf, "InterpretedBy: %s", value); @@ -2431,17 +2443,26 @@ void Audio::showID3Tag(const char* tag, const char* value){ //--------------------------------------------------------------------------------------------------------------------- uint32_t Audio::getFileSize(){ if (!audiofile) return 0; - return audiofile.size(); + cardLock(true); + uint32_t s = audiofile.size(); + cardLock(false); + return s; } //--------------------------------------------------------------------------------------------------------------------- uint32_t Audio::getFilePos(){ if (!audiofile) return 0; - return audiofile.position(); + cardLock(true); + uint32_t p = audiofile.position(); + cardLock(false); + return p; } //--------------------------------------------------------------------------------------------------------------------- bool Audio::setFilePos(uint32_t pos){ if (!audiofile) return false; - return audiofile.seek(pos); + cardLock(true); + uint32_t s = audiofile.seek(pos); + cardLock(false); + return s; } //--------------------------------------------------------------------------------------------------------------------- uint32_t Audio::getAudioDataStartPos() { diff --git a/yoRadio/src/audioVS1053/audioVS1053Ex.h b/yoRadio/src/audioVS1053/audioVS1053Ex.h index b7020ba..3151114 100644 --- a/yoRadio/src/audioVS1053/audioVS1053Ex.h +++ b/yoRadio/src/audioVS1053/audioVS1053Ex.h @@ -36,6 +36,10 @@ extern __attribute__((weak)) void audio_showstreamtitle(const char*); extern __attribute__((weak)) void audio_showstation(const char*); extern __attribute__((weak)) void audio_showstreaminfo(const char*); extern __attribute__((weak)) void audio_id3data(const char*); //ID3 metadata +extern __attribute__((weak)) void audio_id3artist(const char*); +extern __attribute__((weak)) void audio_id3album(const char*); +extern __attribute__((weak)) void audio_id3title(const char*); +extern __attribute__((weak)) void audio_beginSDread(); extern __attribute__((weak)) void audio_id3image(File& file, const size_t pos, const size_t size); //ID3 metadata image extern __attribute__((weak)) void audio_eof_mp3(const char*); extern __attribute__((weak)) void audio_eof_speech(const char*); @@ -311,7 +315,7 @@ public: void setVUmeter(); void getVUlevel(); uint8_t vuLeft, vuRight; - + void cardLock(bool lock); // implement several function with respect to the index of string bool startsWith (const char* base, const char* str) { return (strstr(base, str) - base) == 0;} bool endsWith (const char* base, const char* str) { diff --git a/yoRadio/src/core/config.cpp b/yoRadio/src/core/config.cpp index 5a07319..f4c36d8 100644 --- a/yoRadio/src/core/config.cpp +++ b/yoRadio/src/core/config.cpp @@ -9,7 +9,7 @@ Config config; #if DSP_HSPI || TS_HSPI || VS_HSPI SPIClass SPI2(HSPI); #endif -SPIClass SDSPI(VSPI); +//SPIClass SDSPI(VSPI); void u8fix(char *src){ char last = src[strlen(src)-1]; @@ -32,10 +32,11 @@ void Config::init() { loadTheme(); ssidsCount = 0; - if(SDC_CS!=255 && store.play_mode==PM_WEB){ - pinMode(SDC_CS, OUTPUT); digitalWrite(SDC_CS, HIGH); - SDSPI.begin(SDC_SPI); - SDSPI.setFrequency(1000000); + if(SDC_CS!=255 && store.play_mode==PM_SDCARD){ + //pinMode(SDC_CS, OUTPUT); digitalWrite(SDC_CS, HIGH); + //SDSPI.begin(SDC_SPI); + //SDSPI.setFrequency(1000000); + //SDSPI.setFrequency(100000); if(!SD.begin(SDC_CS)){ store.play_mode=PM_WEB; Serial.println("##[ERROR]#\tCard Mount Failed"); @@ -49,6 +50,7 @@ void Config::init() { store.lastStation = 1; save(); } + loadStation(store.lastStation); #if IR_PIN!=255 eepromRead(EEPROM_START_IR, ircodes); @@ -297,11 +299,11 @@ bool endsWith (const char* base, const char* str) { void Config::listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8_t levels){ File root = SD.open(dirname); if(!root){ - Serial.println("Failed to open directory"); + Serial.println("##[ERROR]#\tFailed to open directory"); return; } if(!root.isDirectory()){ - Serial.println("Not a directory"); + Serial.println("##[ERROR]#\tNot a directory"); return; } @@ -315,12 +317,10 @@ void Config::listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8 listSD(plSDfile, plSDindex, file.path(), levels -1); } } else { - if(endsWith(file.name(), ".mp3") || endsWith(file.name(), ".m4a") || endsWith(file.name(), ".aac") || endsWith(file.name(), ".wav") || endsWith(file.name(), ".flac")){ + if(endsWith(strlwr((char*)file.name()), ".mp3") || endsWith(file.name(), ".m4a") || endsWith(file.name(), ".aac") || endsWith(file.name(), ".wav") || endsWith(file.name(), ".flac")){ pos = plSDfile.position(); plSDfile.print(file.name()); plSDfile.print("\t"); plSDfile.print(file.path()); plSDfile.print("\t"); plSDfile.println(0); plSDindex.write((byte *) &pos, 4); - Serial.print(" plSDfile.position:\t"); - Serial.println(pos); } } file = root.openNextFile(); @@ -342,8 +342,9 @@ void Config::initSDPlaylist() { store.countStation = 0; indexSDPlaylist(); if (SPIFFS.exists(INDEX_SD_PATH)) { - File index = SD.open(INDEX_SD_PATH, "r"); + File index = SPIFFS.open(INDEX_SD_PATH, "r"); store.countStation = index.size() / 4; + store.lastStation = random(1, store.countStation); index.close(); save(); } @@ -362,9 +363,9 @@ void Config::loadStation(uint16_t ls) { if (ls > store.countStation) { ls = 1; } - File playlist = SPIFFS.open(PLAYLIST_PATH, "r"); + File playlist = SPIFFS.open(REAL_PLAYL, "r"); - File index = SPIFFS.open(INDEX_PATH, "r"); + File index = SPIFFS.open(REAL_INDEX, "r"); index.seek((ls - 1) * 4, SeekSet); uint32_t pos; @@ -378,7 +379,7 @@ void Config::loadStation(uint16_t ls) { strncpy(station.name, sName, BUFLEN); strncpy(station.url, sUrl, BUFLEN); station.ovol = sOvol; - setLastStation(ls); + if(store.play_mode==PM_WEB) setLastStation(ls); } playlist.close(); } @@ -392,8 +393,8 @@ void Config::fillPlMenu(char plmenu[][40], int from, byte count, bool removeNum) if (store.countStation == 0) { return; } - File playlist = SPIFFS.open(PLAYLIST_PATH, "r"); - File index = SPIFFS.open(INDEX_PATH, "r"); + File playlist = SPIFFS.open(REAL_PLAYL, "r"); + File index = SPIFFS.open(REAL_INDEX, "r"); while (true) { if (ls < 1) { ls++; diff --git a/yoRadio/src/core/config.h b/yoRadio/src/core/config.h index 07f52c2..6a9458b 100644 --- a/yoRadio/src/core/config.h +++ b/yoRadio/src/core/config.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include "SD.h" #include "options.h" #define EEPROM_SIZE 768 @@ -29,6 +29,8 @@ #endif #define BOOTLOG( ... ) { char buf[120]; sprintf( buf, __VA_ARGS__ ) ; Serial.print("##[BOOT]#\t"); Serial.println(buf); } #define EVERY_MS(x) static uint32_t tmr; bool flag = millis() - tmr >= (x); if (flag) tmr += (x); if (flag) +#define REAL_PLAYL store.play_mode==PM_WEB?PLAYLIST_PATH:PLAYLIST_SD_PATH +#define REAL_INDEX store.play_mode==PM_WEB?INDEX_PATH:INDEX_SD_PATH #define MAX_PLAY_MODE 1 diff --git a/yoRadio/src/core/controls.cpp b/yoRadio/src/core/controls.cpp index e8e80eb..adff3a6 100644 --- a/yoRadio/src/core/controls.cpp +++ b/yoRadio/src/core/controls.cpp @@ -363,8 +363,8 @@ void onBtnLongPressStart(int id) { break; } case EVT_BTNMODE: { - //onBtnClick(EVT_BTNMODE); - config.doSleepW(); + //config.doSleepW(); + display.putRequest(NEWMODE, SLEEPING); break; } default: break; @@ -380,6 +380,10 @@ void onBtnLongPressStop(int id) { lpId = -1; break; } + case EVT_BTNMODE: { + config.doSleepW(); + break; + } default: break; } @@ -498,9 +502,9 @@ void onBtnClick(int id) { config.store.play_mode++; if(config.store.play_mode > MAX_PLAY_MODE){ config.store.play_mode=0; - config.save(); - ESP.restart(); } + config.save(); + ESP.restart(); break; } default: break; diff --git a/yoRadio/src/core/display.cpp b/yoRadio/src/core/display.cpp index def32e2..26dab6a 100644 --- a/yoRadio/src/core/display.cpp +++ b/yoRadio/src/core/display.cpp @@ -262,6 +262,7 @@ void Display::_swichMode(displayMode_e newmode) { } if (newmode == LOST) _showDialog(const_DlgLost); if (newmode == UPDATING) _showDialog(const_DlgUpdate); + if (newmode == SLEEPING) _showDialog("SLEEPING"); if (newmode == INFO || newmode == SETTINGS || newmode == TIMEZONE || newmode == WIFI) _showDialog(const_DlgNextion); if (newmode == NUMBERS) _showDialog(""); if (newmode == STATIONS) { @@ -443,8 +444,12 @@ void Display::_title() { /*#ifdef USE_NEXTION nextion.newTitle(config.station.title); #endif*/ - if (player_on_track_change) player_on_track_change(); + + }else{ + _title1.setText(""); + if(_title2) _title2->setText(""); } + if (player_on_track_change) player_on_track_change(); } void Display::_time(bool redraw) { diff --git a/yoRadio/src/core/display.h b/yoRadio/src/core/display.h index 18c9f0a..2b85613 100644 --- a/yoRadio/src/core/display.h +++ b/yoRadio/src/core/display.h @@ -8,7 +8,7 @@ #include "../displays/dspcore.h" -enum displayMode_e { PLAYER, VOL, STATIONS, NUMBERS, LOST, UPDATING, INFO, SETTINGS, TIMEZONE, WIFI, CLEAR }; +enum displayMode_e { PLAYER, VOL, STATIONS, NUMBERS, LOST, UPDATING, INFO, SETTINGS, TIMEZONE, WIFI, CLEAR, SLEEPING }; enum pages_e : uint8_t { PG_PLAYER=0, PG_DIALOG=1, PG_PLAYLIST=2 }; //enum dialogType_e : uint8_t { DG_NONE=0, DG_VOLUME=1, DG_LOST=2, DG_UPDATING=3, DG_NEXTION=4 }; diff --git a/yoRadio/src/core/netserver.cpp b/yoRadio/src/core/netserver.cpp index 87fdc99..a6d38ba 100644 --- a/yoRadio/src/core/netserver.cpp +++ b/yoRadio/src/core/netserver.cpp @@ -636,7 +636,11 @@ void handleHTTPArgs(AsyncWebServerRequest * request) { #ifdef MQTT_HOST if (strcmp(request->url().c_str(), PLAYLIST_PATH) == 0) while (mqttplaylistblock) vTaskDelay(5); #endif - netserver.chunkedHtmlPage("application/octet-stream", request, request->url().c_str()); + if(strcmp(request->url().c_str(), PLAYLIST_PATH) == 0 && config.store.play_mode==PM_SDCARD){ + netserver.chunkedHtmlPage("application/octet-stream", request, PLAYLIST_SD_PATH); + }else{ + netserver.chunkedHtmlPage("application/octet-stream", request, request->url().c_str()); + } return; } if (strcmp(request->url().c_str(), "/") == 0 && request->params() == 0) { diff --git a/yoRadio/src/core/network.cpp b/yoRadio/src/core/network.cpp index 144f4ce..59c7e07 100644 --- a/yoRadio/src/core/network.cpp +++ b/yoRadio/src/core/network.cpp @@ -76,6 +76,7 @@ void Network::begin() { errcnt = 0; ls++; if (ls > config.ssidsCount - 1) ls = 0; + Serial.println(); break; } } diff --git a/yoRadio/src/core/options.h b/yoRadio/src/core/options.h index 15f9ba5..cd4b916 100644 --- a/yoRadio/src/core/options.h +++ b/yoRadio/src/core/options.h @@ -1,7 +1,7 @@ #ifndef options_h #define options_h -#define YOVERSION "0.9.000" +#define YOVERSION "0.8.800" /******************************************************* DO NOT EDIT THIS FILE. @@ -58,7 +58,7 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti /* TFT DISPLAY */ #ifndef TFT_CS - #define TFT_CS 5 + #define TFT_CS 255 #endif #ifndef TFT_RST #define TFT_RST 15 // Or set to -1 and connect to Esp EN pin diff --git a/yoRadio/src/core/player.cpp b/yoRadio/src/core/player.cpp index d8c56db..54cde3d 100644 --- a/yoRadio/src/core/player.cpp +++ b/yoRadio/src/core/player.cpp @@ -128,7 +128,7 @@ void Player::play(uint16_t stationId) { display.putRequest(PSTOP); setDefaults(); setOutputPins(false); - config.setTitle(const_PlConnect); + config.setTitle(config.store.play_mode==PM_WEB?const_PlConnect:""); config.station.bitrate=0; netserver.requestOnChange(TITLE, 0); config.loadStation(stationId); @@ -136,8 +136,10 @@ void Player::play(uint16_t stationId) { display.putRequest(NEWSTATION); netserver.requestOnChange(STATION, 0); telnet.printf("##CLI.NAMESET#: %d %s\n", config.store.lastStation, config.station.name); - if (connecttohost(config.station.url)) { + if (config.store.play_mode==PM_WEB?connecttohost(config.station.url):connecttoFS(SD,config.station.url)) { mode = PLAYING; + config.setTitle(""); + netserver.requestOnChange(TITLE, 0); config.setSmartStart(1); netserver.requestOnChange(MODE, 0); setOutputPins(true); @@ -150,13 +152,19 @@ void Player::play(uint16_t stationId) { } void Player::prev() { - if (config.store.lastStation == 1) config.store.lastStation = config.store.countStation; else config.store.lastStation--; + if(config.store.play_mode==PM_WEB){ + if (config.store.lastStation == 1) config.store.lastStation = config.store.countStation; else config.store.lastStation--; + } request.station = config.store.lastStation; request.doSave = true; } void Player::next() { - if (config.store.lastStation == config.store.countStation) config.store.lastStation = 1; else config.store.lastStation++; + if(config.store.play_mode==PM_WEB){ + if (config.store.lastStation == config.store.countStation) config.store.lastStation = 1; else config.store.lastStation++; + }else{ + config.store.lastStation = random(1, config.store.countStation); + } request.station = config.store.lastStation; request.doSave = true; } diff --git a/yoRadio/yoRadio.ino b/yoRadio/yoRadio.ino index bbae0c8..7a2f255 100644 --- a/yoRadio/yoRadio.ino +++ b/yoRadio/yoRadio.ino @@ -100,8 +100,17 @@ void audio_info(const char *info) { #ifdef USE_NEXTION nextion.audioinfo(info); #endif + if (strstr(info, "skip metadata") != NULL){ + config.setTitle(config.station.name); + netserver.requestOnChange(TITLE, 0); + } if (strstr(info, "failed!") != NULL || strstr(info, " 404") != NULL || strstr(info, " 403") != NULL || strstr(info, "address is empty") != NULL) player.stop(info); if (strstr(info, "not supported") != NULL || strstr(info, "Account already in use") != NULL || strstr(info, "HTTP/1.0 401") != NULL) player.stop(info); + char* ici; char b[20]={0}; + if ((ici = strstr(info, "BitRate: ")) != NULL) { + strlcpy(b, ici + 9, 50); + audio_bitrate(b); + } } void audio_bitrate(const char *info) @@ -149,3 +158,41 @@ void audio_showstreamtitle(const char *info) { netserver.requestOnChange(TITLE, 0); } } + +void audio_id3artist(const char *info){ + if(printable(info)) config.setStation(info); + display.putRequest(NEWSTATION); + netserver.requestOnChange(STATION, 0); + +} + +void audio_id3album(const char *info){ + if(printable(info)){ + if(strlen(config.station.title)==0){ + config.setTitle(info); + }else{ + char out[BUFLEN]= {0}; + strlcat(out, config.station.title, BUFLEN); + strlcat(out, " - ", BUFLEN); + strlcat(out, info, BUFLEN); + config.setTitle(out); + } + netserver.requestOnChange(TITLE, 0); + } +} + +void audio_id3title(const char *info){ + audio_id3album(info); +} + +void audio_beginSDread(){ + config.setTitle(""); + netserver.requestOnChange(TITLE, 0); +} + +void audio_id3data(const char *info){ //id3 metadata + telnet.printf("##AUDIO.ID3#: %s\n", info); +} +void audio_eof_mp3(const char *info){ //end of file + player.play(random(1, config.store.countStation)); +}