From 333e6fa1c68332a85e67e442c7aecb7dbb08dfa3 Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Fri, 6 Jun 2025 13:41:25 +0200 Subject: [PATCH] Format SPIFFS when it is corrupted --- src/gui.cpp | 1 - src/logbook.cpp | 28 ++++++++++++++++------------ src/touch.cpp | 1 - 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index 4241e82..1289c61 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1,7 +1,6 @@ #include "gui.h" #include "language.h" #include "constants.h" -#include "config.h" #include #include #include diff --git a/src/logbook.cpp b/src/logbook.cpp index 78b4471..268224f 100644 --- a/src/logbook.cpp +++ b/src/logbook.cpp @@ -2,7 +2,6 @@ #include "language.h" #include "constants.h" #include -#include "language.h" String UDPlogold = ""; @@ -188,37 +187,42 @@ void handleDownloadCSV() { } bool handleCreateNewLogbook() { + // Quick check if SPIFFS is mounted and accessible + if (!SPIFFS.exists("/")) { // "/" should always exist if mounted + // SPIFFS not accessible, try to format and remount + if (!SPIFFS.format()) { + return false; // format failed + } + if (!SPIFFS.begin()) { + return false; // remount failed + } + } + // Check if the file "logbook.csv" already exists if (SPIFFS.exists("/logbook.csv")) { // If it exists, delete the file if (!SPIFFS.remove("/logbook.csv")) { - // Return false if the file could not be deleted return false; } } // Create a new "logbook.csv" file in write mode fs::File file = SPIFFS.open("/logbook.csv", "w"); - - // Check if the file was successfully created if (!file) { - // Return false if file creation fails return false; } // Write the header to the new CSV file String header = "Date,Time,Frequency,PI,Signal,Stereo,TA,TP,PTY,ECC,PS,Radiotext\n"; - file.print(header); // Ensure that the header is written properly + file.print(header); - // Make sure the data is written before closing the file - file.flush(); // Ensure that everything is written to the file - file.close(); // Close the file after writing + file.flush(); + file.close(); - - logcounter = 0; // Reset logcounter + logcounter = 0; EEPROM.writeUInt(EE_UINT16_LOGCOUNTER, logcounter); EEPROM.commit(); - // Return true if the function runs without problems + return true; } diff --git a/src/touch.cpp b/src/touch.cpp index 6d40b08..8a7c8cf 100644 --- a/src/touch.cpp +++ b/src/touch.cpp @@ -1,7 +1,6 @@ #include "touch.h" #include "language.h" #include "constants.h" -#include "config.h" #include void doTouchEvent(uint16_t x, uint16_t y) {