From f6b1a6126851031a1db7d91aaa068385e0d60412 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 15 Feb 2023 17:47:47 -0500 Subject: [PATCH] added listDir --- cubesatsim/esp32-cam/esp32-cam.ino | 50 ++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/cubesatsim/esp32-cam/esp32-cam.ino b/cubesatsim/esp32-cam/esp32-cam.ino index dfcd43eb..bcb9e5f3 100644 --- a/cubesatsim/esp32-cam/esp32-cam.ino +++ b/cubesatsim/esp32-cam/esp32-cam.ino @@ -13,8 +13,50 @@ static esp_err_t init_camera(); #define FORMAT_SPIFFS_IF_FAILED true camera_fb_t *pic; -//File inFile; -//File outFile; + + +// example code from https://github.com/espressif/arduino-esp32/blob/master/libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino +// +void listDir(fs::FS &fs, const char * dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\r\n", dirname); + + File root = fs.open(dirname); + if (!root) { + Serial.println("- failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println(" - not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.name(), levels - 1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print("\tSIZE: "); + Serial.println(file.size()); + } + file = root.openNextFile(); + } +} + +void deleteFile(fs::FS &fs, const char * path) { + Serial.printf("Deleting file: %s\r\n", path); + if (fs.remove(path)) { + Serial.println("- file deleted"); + } else { + Serial.println("- delete failed"); + } +} + void setup() { // put your setup code here, to run once: @@ -35,8 +77,8 @@ void setup() { Serial.println("SPIFFS Mount Failed"); return; } - } + listDir(SPIFFS, "/", 0); } void loop() { @@ -69,6 +111,8 @@ void loop() { char filename[] = "/cam.bin"; save_camera_image(filename); + + listDir(SPIFFS, "/", 0); picosstvpp();