diff --git a/src/msc/msc.cpp b/src/msc/msc.cpp index 368fdc6..40a6d35 100644 --- a/src/msc/msc.cpp +++ b/src/msc/msc.cpp @@ -92,14 +92,16 @@ namespace msc { } void print() { - File file; - FatFile rdir; - rdir.open("/"); + Serial.println("Available files:"); - // Open next file in root. - // Warning, openNext starts at the current directory position - // so a rewind of the directory may be required. - while(file.openNext(&rdir, O_RDONLY)) { + // Close file(s) + if (file.isOpen()) file.close(); + while (!file_stack.empty()) file_stack.pop(); + + SdFile root; + root.open("/"); + + while ( file.openNext(&root, O_RDONLY) ) { file.printFileSize(&Serial); Serial.write(' '); file.printName(&Serial); diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 8a6df4f..0f14849 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -101,6 +101,7 @@ namespace preferences { // Open the file and read it into a buffer if (!msc::open(PREFERENCES_PATH), false) return; msc::read(buffer, JSON_SIZE); + msc::close(); // Deserialize the JSON document DeserializationError error = deserializeJson(config_doc, buffer);