diff --git a/sound_picture_app/Audio_Player.cpp b/sound_picture_app/Audio_Player.cpp index bf5ed5e..87cfda5 100644 --- a/sound_picture_app/Audio_Player.cpp +++ b/sound_picture_app/Audio_Player.cpp @@ -29,7 +29,7 @@ void initAudioPlayer() { xTaskCreatePinnedToCore( audioLoopTask, "audioLoopTask", - 8192, // Stack size (ESP32-audioI2S requires a larger stack size for decoding) + 16384, // Increased from 8192 — ESP32-audioI2S MP3 decode needs ~12-16KB stack NULL, 5, // Priority &audioTaskHandle, @@ -66,6 +66,14 @@ uint8_t getPlayerVolume() { return currentVolume; } +// Case-insensitive check if filename ends with a given extension +static bool hasExtension(const char* name, const char* ext) { + size_t nLen = strlen(name); + size_t eLen = strlen(ext); + if (nLen < eLen) return false; + return strcasecmp(name + nLen - eLen, ext) == 0; +} + void Search_Audio(const char* directory) { File Path = SD_MMC.open(directory); if (!Path) { @@ -79,8 +87,8 @@ void Search_Audio(const char* directory) { while (file && fileCount < 100) { if (!file.isDirectory()) { const char* name = file.name(); - // Match WAV or MP3 files - if (strstr(name, ".wav") || strstr(name, ".mp3") || strstr(name, ".WAV") || strstr(name, ".MP3")) { + // Case-insensitive extension match to handle FAT32 uppercase names + if (hasExtension(name, ".wav") || hasExtension(name, ".mp3")) { strncpy(Audio_Names[fileCount], name, sizeof(Audio_Names[fileCount]) - 1); Audio_Names[fileCount][sizeof(Audio_Names[fileCount]) - 1] = '\0'; fileCount++; diff --git a/sound_picture_app/Display_PNG.cpp b/sound_picture_app/Display_PNG.cpp index 168aedc..a1e42ca 100644 --- a/sound_picture_app/Display_PNG.cpp +++ b/sound_picture_app/Display_PNG.cpp @@ -16,8 +16,8 @@ void * pngOpen(const char *filePath, int32_t *size) { } void pngClose(void *handle) { - File Image_file = *((File*)handle); - if (Image_file) Image_file.close(); + File* fp = (File*)handle; + if (fp && *fp) fp->close(); } int32_t pngRead(PNGFILE *page, uint8_t *buffer, int32_t length) { @@ -44,6 +44,15 @@ void Search_Images(const char* directory) { Image_Count = Folder_retrieval(directory, ".png", Image_Names, 100); } +// Fill entire screen with black before drawing a new image +static void clearScreen() { + static uint16_t blackLine[MAX_IMAGE_WIDTH]; + memset(blackLine, 0, sizeof(blackLine)); + for (int y = 0; y < LCD_HEIGHT; y++) { + LCD_addWindow(0, y, LCD_WIDTH - 1, y, blackLine); + } +} + void Display_Image_By_Path(const char* filePath) { printf("Displaying image: %s\r\n", filePath); int16_t ret = png.open(filePath, pngOpen, pngClose, pngRead, pngSeek, pngDraw); @@ -52,6 +61,7 @@ void Display_Image_By_Path(const char* filePath) { if (png.getWidth() > MAX_IMAGE_WIDTH) { printf("Image is too wide for line buffer!\r\n"); } else { + clearScreen(); // Clear leftovers from previous smaller image ret = png.decode(NULL, 0); png.close(); } diff --git a/sound_picture_app/SD_Card.cpp b/sound_picture_app/SD_Card.cpp index 0f81cf9..038a72f 100644 --- a/sound_picture_app/SD_Card.cpp +++ b/sound_picture_app/SD_Card.cpp @@ -7,11 +7,11 @@ uint16_t SDCard_Size; uint16_t Flash_Size; void SD_Init() { - if(!SD_MMC.setPins(SD_CLK_PIN, SD_CMD_PIN, SD_D0_PIN, SD_D1_PIN, SD_D2_PIN, SD_D3_PIN)){ + if(!SD_MMC.setPins(SD_CLK_PIN, SD_CMD_PIN, SD_D0_PIN)){ printf("SD MMC: Pin change failed!\r\n"); return; } - if (SD_MMC.begin("/sdcard", false, true)) { + if (SD_MMC.begin("/sdcard", true, true)) { // true = 1-bit mode (avoids GPIO conflict on D3/CS) printf("SD card initialization successful (4-bit mode)!\r\n"); } else { printf("SD card initialization failed!\r\n"); @@ -81,7 +81,8 @@ uint16_t Folder_retrieval(const char* directory, const char* fileExtension, char File file = Path.openNextFile(); while (file && fileCount < maxFiles) { if (!file.isDirectory() && strstr(file.name(), fileExtension)) { - strncpy(File_Name[fileCount], file.name(), sizeof(File_Name[fileCount])); + strncpy(File_Name[fileCount], file.name(), sizeof(File_Name[fileCount]) - 1); + File_Name[fileCount][sizeof(File_Name[fileCount]) - 1] = '\0'; // Ensure null-termination if (strcmp(directory, "/") == 0) { snprintf(filePath, 100, "%s%s", directory, file.name()); } else { diff --git a/sound_picture_app/Web_Server.cpp b/sound_picture_app/Web_Server.cpp index a3a36bf..75ffc32 100644 --- a/sound_picture_app/Web_Server.cpp +++ b/sound_picture_app/Web_Server.cpp @@ -7,103 +7,224 @@ WebServer server(80); File uploadFile; +bool uploadSuccess = false; +String uploadedFilename = ""; const char* uploadPage = R"rawliteral( - +
-Upload media to the SD card wirelessly
+ + %TOAST% +