diff --git a/esp32_marauder/configs.h b/esp32_marauder/configs.h index 7267e2791..7fc789f4e 100644 --- a/esp32_marauder/configs.h +++ b/esp32_marauder/configs.h @@ -140,6 +140,7 @@ #define USE_SD #define HAS_TEMP_SENSOR //#define HAS_GPS + #define USE_FFAT #endif #ifdef MARAUDER_KIT diff --git a/esp32_marauder/settings.cpp b/esp32_marauder/settings.cpp index 83bc12550..d651b90a4 100644 --- a/esp32_marauder/settings.cpp +++ b/esp32_marauder/settings.cpp @@ -5,35 +5,59 @@ String Settings::getSettingsString() { } bool Settings::begin() { + #ifndef USE_FFAT if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){ Serial.println("Settings SPIFFS Mount Failed"); return false; } + #else + if(!FFat.begin(FORMAT_SPIFFS_IF_FAILED)){ + return false; + } + Serial.println("Using FFat"); + + File root = FFat.open("/"); + if(!root){ + Serial.println("failed to open root directory - formatiing"); + FFat.format(); + } + else { + Serial.println("FFat root good"); + root.close(); + } + Serial.println("Found default fs FFat"); + #endif File settingsFile; //SPIFFS.remove("/settings.json"); // NEED TO REMOVE THIS LINE - if (SPIFFS.exists("/settings.json")) { - settingsFile = SPIFFS.open("/settings.json", FILE_READ); - - if (!settingsFile) { + #ifndef USE_FFAT + if (SPIFFS.exists("/settings.jsn")) { + settingsFile = SPIFFS.open("/settings.jsn", FILE_READ); + } + #else + if(FFat.exists("/settings.json")) { + settingsFile = FFat.open("/settings.jsn", FILE_READ); + } + #endif + + if (!settingsFile) { settingsFile.close(); Serial.println(F("Could not find settings file")); + #ifndef USE_FFAT if (this->createDefaultSettings(SPIFFS)) return true; + #else + if (this->createDefaultSettings(FFat)) + return true; + #endif else - return false; - } - } - else { - Serial.println("Settings file does not exist"); - if (this->createDefaultSettings(SPIFFS)) - return true; - else - return false; + return false; } + Serial.println("Created settings file"); + String json_string; DynamicJsonDocument jsonBuffer(1024); DeserializationError error = deserializeJson(jsonBuffer, settingsFile); @@ -131,6 +155,7 @@ bool Settings::saveSetting(String key, bool value) { } String settings_string; + File settingsFile; for (int i = 0; i < json["Settings"].size(); i++) { if (json["Settings"][i]["name"].as() == key) { @@ -138,10 +163,15 @@ bool Settings::saveSetting(String key, bool value) { Serial.println("Saving setting..."); - File settingsFile = SPIFFS.open("/settings.json", FILE_WRITE); - + #ifndef USE_FFAT + settingsFile = SPIFFS.open("/settings.jsn", FILE_WRITE); + #else + settingsFile = FFat.open("/settings.jsn", FILE_WRITE); + #endif + if (!settingsFile) { - Serial.println(F("Failed to create settings file")); + Serial.print(F("Failed to create settings file - ")); + Serial.println(settingsFile, DEC); return false; } @@ -240,12 +270,13 @@ void Settings::printJsonSettings(String json_string) { } bool Settings::createDefaultSettings(fs::FS &fs) { - Serial.println(F("Creating default settings file: settings.json")); + Serial.println(F("Creating default settings file: settings.jsn")); - File settingsFile = fs.open("/settings.json", FILE_WRITE); + File settingsFile = fs.open("/settings.jsn", FILE_WRITE); if (!settingsFile) { - Serial.println(F("Failed to create settings file")); + Serial.print(F("Failed to create settings file - ")); + Serial.println(settingsFile, DEC); return false; } diff --git a/esp32_marauder/settings.h b/esp32_marauder/settings.h index c85b67516..b7be2051b 100644 --- a/esp32_marauder/settings.h +++ b/esp32_marauder/settings.h @@ -5,7 +5,11 @@ #include "configs.h" +#ifndef USE_FFAT #include "SPIFFS.h" +#else +#include "FFat.h" +#endif #include #include