Fix 8 bugs: SD 1-bit mode GPIO conflict, PNG file handle leak, audio stack overflow, null terminator, error degradation logic, modulo div-by-zero, upload file validation, screen clear before PNG draw. Improve web UI with progress bar and toast feedback.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user