From 2cc5f3d6fccb2f86383bb8a5bd96583b65be60f9 Mon Sep 17 00:00:00 2001 From: radex Date: Sun, 2 Jun 2024 15:44:49 +0200 Subject: [PATCH] clean up --- firmware/platformio.ini | 3 +- firmware/src/sd.cpp | 127 ++++------------------------------------ 2 files changed, 12 insertions(+), 118 deletions(-) diff --git a/firmware/platformio.ini b/firmware/platformio.ini index c3f8741..427adc9 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -14,6 +14,5 @@ board = pico framework = arduino board_build.core = earlephilhower board_build.filesystem_size = 0.5m -lib_deps = - ; khoih-prog/RP2040_SD@^1.0.1 +; lib_deps = diff --git a/firmware/src/sd.cpp b/firmware/src/sd.cpp index 3f167e8..766b90d 100644 --- a/firmware/src/sd.cpp +++ b/firmware/src/sd.cpp @@ -1,6 +1,5 @@ #include #include -// #include #include "sd.h" #include "audio.h" #include "gfx_decoder.h" @@ -82,39 +81,17 @@ String playlist[128] = {}; size_t playlistSize = 0; void sd_loadPlaylist() { - // auto path = "video/playlist.txt"; - -/* - FRESULT result = f_stat(path, NULL); - if (result != FR_OK) { - Serial.println("Could not find playlist for videos :("); - return; - } -*/ + auto path = "video/playlist.txt"; FIL playlistFile; - FRESULT result = f_open(&playlistFile, "video/playlist.txt", FA_READ); + FRESULT result = f_open(&playlistFile, path, FA_READ); CHECK_RESULT(result, "playlist file open"); Serial.println("Playlist file opened"); - /* - - if (!SD.exists(path)) { - Serial.println("Could not find playlist for videos :("); - return; - } - - auto playlistFile = SD.open(path, FILE_READ); - Serial.println("Playlist file opened"); - */ - char playlist_buffer[512]; auto fileSize = f_size(&playlistFile); - /* - auto fileSize = playlistFile.size(); - */ if (fileSize > sizeof(playlist_buffer)) { Serial.print("Playlist file too large, max: "); Serial.println(sizeof(playlist_buffer)); @@ -135,14 +112,6 @@ void sd_loadPlaylist() { result = f_close(&playlistFile); CHECK_RESULT(result, "playlist file close"); - /* - if (playlistFile.read(&playlist_buffer, sizeof(playlist_buffer)) != fileSize) { - Serial.println("Could not read playlist file"); - return; - } - - playlistFile.close(); - */ Serial.println("Parsing playlist..."); @@ -181,7 +150,6 @@ void sd_loadPlaylist() { } } -// File audioFile; FIL *audioFile; void sd_loadAudio(size_t index) { @@ -204,18 +172,6 @@ void sd_loadAudio(size_t index) { result = f_open(audioFile, path.c_str(), FA_READ); CHECK_RESULT(result, "audio file open"); - /* - if (!SD.exists(path)) { - Serial.println("Audio not found :("); - return; - } - - if (audioFile) { - audioFile.close(); - } - - audioFile = SD.open(path, FILE_READ); - */ Serial.println("Audio file opened"); audio_stop(); @@ -236,19 +192,6 @@ void sd_loadAudio(size_t index) { return; } - /* - // load two buffers' worth of audio - if (audioFile.read(&wav_buffer_0, BUFFER_LEN) < BUFFER_LEN) { - Serial.println("Could not read first sample"); - return; - } - - if (audioFile.read(&wav_buffer_1, BUFFER_LEN) < BUFFER_LEN) { - Serial.println("Could not read second sample"); - return; - } - */ - audio_start(); } @@ -267,13 +210,7 @@ void sd_loadNextAudio() { result = f_read(audioFile, next_buffer, BUFFER_LEN, &bytesRead); CHECK_RESULT(result, "audio sample"); - /* - auto bytesRead = audioFile.read(next_buffer, BUFFER_LEN); - */ - if (bytesRead < BUFFER_LEN) { - // Serial.println("End of audio file, rewinding..."); - // audioFile.seek(0); Serial.println("End of audio."); audio_stop(); } else { @@ -295,16 +232,6 @@ bool sd_loadGfxFrameLengths(size_t index) { auto path = "video/" + playlist[index] + "/gfx_len.bin"; - /* - if (!SD.exists(path)) { - Serial.println("Frame lengths file not found :("); - return false; - } - - auto lengthsFile = SD.open(path, FILE_READ); - auto fileSize = lengthsFile.size(); - */ - FIL lengthsFile; FRESULT result = f_open(&lengthsFile, path.c_str(), FA_READ); CHECK_RESULT(result, "frame lengths file open"); @@ -333,27 +260,9 @@ bool sd_loadGfxFrameLengths(size_t index) { result = f_close(&lengthsFile); CHECK_RESULT(result, "frame lengths file close"); - /* - while (lengthsFile.available()) { - lengthsFile.read(&gfxFrameLengthsBuffer, sizeof(gfxFrameLengthsBuffer)); - } - - lengthsFile.close(); - */ - /* - Serial.println("Done reading frame lengths"); - Serial.println("lengths be:"); - for (size_t i = 0; i < 200; i++) { - Serial.print(i); - Serial.print(": "); - Serial.println(gfxFrameLengthsBuffer[i]); - } - */ - return true; } -// File gfxFile; FIL *gfxFile; uint16_t frameIdx = 0; @@ -366,18 +275,18 @@ bool sd_loadGfxBlob(size_t index) { auto path = "video/" + playlist[index] + "/gfx.bin"; - gfxFile = (FIL*) malloc(sizeof(FIL)); - FRESULT result = f_open(gfxFile, path.c_str(), FA_READ); - CHECK_RESULT(result, "gfx blob file open"); + FRESULT result; - /* - if (!SD.exists(path)) { - Serial.println("Gfx blob file not found :("); - return false; + if (gfxFile) { + result = f_close(gfxFile); + CHECK_RESULT(result, "gfx file close"); + free(gfxFile); } - gfxFile = SD.open(path, FILE_READ); - */ + gfxFile = (FIL*) malloc(sizeof(FIL)); + result = f_open(gfxFile, path.c_str(), FA_READ); + CHECK_RESULT(result, "gfx blob file open"); + Serial.println("Opened video frames"); frameIdx = 0; @@ -396,13 +305,6 @@ int32_t sd_loadNextFrame() { return -1; } - /* - if (!gfxFile || !gfxFile.available()) { - Serial.println("Gfx file not available"); - return -1; - } - */ - if (frameIdx >= frameCount) { Serial.println("Frame out of range"); return -1; @@ -423,10 +325,6 @@ int32_t sd_loadNextFrame() { FRESULT result = f_read(gfxFile, &gfxFrameBuffer, frameSize, &bytesRead); CHECK_RESULT(result, "playlist file read"); - /* - // read data - auto bytesRead = gfxFile.read(&gfxFrameBuffer, frameSize); - */ if (bytesRead < frameSize) { Serial.println("Could not read the entire frame"); return -1; @@ -434,9 +332,6 @@ int32_t sd_loadNextFrame() { // increment if (frameIdx == frameCount - 1) { - // Serial.println("Last frame, rewinding..."); - // gfxFile.seek(0); - // frameIdx = 0; Serial.println("Last frame, next video!"); return -2; } else {