Fix bug where preferences.json was never closed

This commit is contained in:
Spacehuhn 2022-11-01 14:26:49 +01:00
parent 2532230c39
commit 64b1b86047
2 changed files with 10 additions and 7 deletions

View File

@ -92,14 +92,16 @@ namespace msc {
} }
void print() { void print() {
File file; Serial.println("Available files:");
FatFile rdir;
rdir.open("/");
// Open next file in root. // Close file(s)
// Warning, openNext starts at the current directory position if (file.isOpen()) file.close();
// so a rewind of the directory may be required. while (!file_stack.empty()) file_stack.pop();
while(file.openNext(&rdir, O_RDONLY)) {
SdFile root;
root.open("/");
while ( file.openNext(&root, O_RDONLY) ) {
file.printFileSize(&Serial); file.printFileSize(&Serial);
Serial.write(' '); Serial.write(' ');
file.printName(&Serial); file.printName(&Serial);

View File

@ -101,6 +101,7 @@ namespace preferences {
// Open the file and read it into a buffer // Open the file and read it into a buffer
if (!msc::open(PREFERENCES_PATH), false) return; if (!msc::open(PREFERENCES_PATH), false) return;
msc::read(buffer, JSON_SIZE); msc::read(buffer, JSON_SIZE);
msc::close();
// Deserialize the JSON document // Deserialize the JSON document
DeserializationError error = deserializeJson(config_doc, buffer); DeserializationError error = deserializeJson(config_doc, buffer);