diff --git a/ESP32_AP-Flasher/include/storage.h b/ESP32_AP-Flasher/include/storage.h index 9cd265d9..a1732e25 100644 --- a/ESP32_AP-Flasher/include/storage.h +++ b/ESP32_AP-Flasher/include/storage.h @@ -25,6 +25,7 @@ class DynStorage { public: DynStorage(); void begin(); + void end(); void listFiles(); size_t freeSpace(); diff --git a/ESP32_AP-Flasher/src/flasher.cpp b/ESP32_AP-Flasher/src/flasher.cpp index f1764caa..bd466201 100644 --- a/ESP32_AP-Flasher/src/flasher.cpp +++ b/ESP32_AP-Flasher/src/flasher.cpp @@ -3,6 +3,7 @@ #include #include #include "storage.h" +#include "LittleFS.h" #include // #include @@ -109,9 +110,11 @@ class flasher { flasher::flasher() { zbs = new ZBS_interface; + Storage.end(); } flasher::~flasher() { delete zbs; + Storage.begin(); } bool flasher::connectTag(uint8_t port) { diff --git a/ESP32_AP-Flasher/src/storage.cpp b/ESP32_AP-Flasher/src/storage.cpp index fe40ccb6..2cb5849f 100644 --- a/ESP32_AP-Flasher/src/storage.cpp +++ b/ESP32_AP-Flasher/src/storage.cpp @@ -141,6 +141,27 @@ void DynStorage::begin() { } } +void DynStorage::end() { +#ifdef HAS_SDCARD + initLittleFS(); + if (SD_CARD_CLK == FLASHER_AP_CLK || + SD_CARD_MISO == FLASHER_AP_MISO || + SD_CARD_MOSI == FLASHER_AP_MOSI) { + Serial.println("Tearing down SD card connection"); + + copyBetweenFS(*contentFS, "/tag_md5_db.json", LittleFS); + copyBetweenFS(*contentFS, "/AP_FW_Pack.bin", LittleFS); + if (contentFS->exists("/AP_force_flash.bin")) { + copyBetweenFS(*contentFS, "/AP_force_flash.bin", LittleFS); + contentFS->remove("/AP_force_flash.bin"); + } + Serial.println("Swapping to LittleFS"); + + contentFS = &LittleFS; + } + +#endif +} void listDir(fs::FS& fs, const char* dirname, uint8_t levels) { Storage.begin();