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() {
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);

View File

@ -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);