Skip to content

Commit

Permalink
Remove all files but the pin_mapping.json from filesystem on factory …
Browse files Browse the repository at this point in the history
…reset

This allows to create more user defined files and get them deleted on factory reset.
  • Loading branch information
tbnobody committed Jan 30, 2024
1 parent 48a722f commit 557c5d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class Utils {
static int getTimezoneOffset();
static void restartDtu();
static bool checkJsonAlloc(const DynamicJsonDocument& doc, const char* function, const uint16_t line);
static void removeAllFiles();
};
16 changes: 16 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "Display_Graphic.h"
#include "Led_Single.h"
#include "MessageOutput.h"
#include "PinMapping.h"
#include <Esp.h>
#include <LittleFS.h>

uint32_t Utils::getChipId()
{
Expand Down Expand Up @@ -76,3 +78,17 @@ bool Utils::checkJsonAlloc(const DynamicJsonDocument& doc, const char* function,

return true;
}

/// @brief Remove all files but the PINMAPPING_FILENAME
void Utils::removeAllFiles()
{
auto root = LittleFS.open("/");
auto file = root.getNextFileName();

while (file != "") {
if (file != PINMAPPING_FILENAME) {
LittleFS.remove(file);
}
file = root.getNextFileName();
}
}
2 changes: 1 addition & 1 deletion src/WebApi_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void WebApiConfigClass::onConfigDelete(AsyncWebServerRequest* request)
response->setLength();
request->send(response);

LittleFS.remove(CONFIG_FILENAME);
Utils::removeAllFiles();
Utils::restartDtu();
}

Expand Down

0 comments on commit 557c5d6

Please sign in to comment.