diff --git a/tasmota/settings.ino b/tasmota/settings.ino index d1985fee8..78d328c1d 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -562,8 +562,8 @@ void SettingsLoad(void) { } #endif // ESP8266 #ifdef ESP32 - SettingsRead(&Settings, sizeof(Settings)); - AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded, " D_COUNT " %lu"), Settings.save_flag); + uint32_t source = SettingsRead(&Settings, sizeof(Settings)); + AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from %s, " D_COUNT " %lu"), (source)?"File":"Nvm", Settings.save_flag); #endif // ESP32 #ifndef FIRMWARE_MINIMAL diff --git a/tasmota/support_esp32.ino b/tasmota/support_esp32.ino index 73d5836ff..ab6b4308c 100644 --- a/tasmota/support_esp32.ino +++ b/tasmota/support_esp32.ino @@ -171,20 +171,17 @@ void SettingsErase(uint8_t type) { } } -void SettingsRead(void *data, size_t size) { -#ifdef USE_UFILESYS -// if (!TfsLoadFile("/settings", (uint8_t*)data, size)) { +uint32_t SettingsRead(void *data, size_t size) { + uint32_t source = 1; + if (!TfsLoadFile("/settings", (uint8_t*)data, size)) { + source = 0; NvmLoad("main", "Settings", data, size); -// } -#else - NvmLoad("main", "Settings", data, size); -#endif + } + return source; } void SettingsWrite(const void *pSettings, unsigned nSettingsLen) { -#ifdef USE_UFILESYS -// TfsSaveFile("/settings", (const uint8_t*)pSettings, nSettingsLen); -#endif + TfsSaveFile("/settings", (const uint8_t*)pSettings, nSettingsLen); NvmSave("main", "Settings", pSettings, nSettingsLen); } diff --git a/tasmota/tasmota_configurations_ESP32.h b/tasmota/tasmota_configurations_ESP32.h index 63a973e19..0a507dc2b 100644 --- a/tasmota/tasmota_configurations_ESP32.h +++ b/tasmota/tasmota_configurations_ESP32.h @@ -52,7 +52,6 @@ #define FALLBACK_MODULE ODROID_GO // [Module2] Select default module on fast reboot where USER_MODULE is user template #define USE_ODROID_GO // Add support for Odroid Go -#define USE_UFILESYS #define USE_SDCARD #define USE_ADC #define USE_SPI diff --git a/tasmota/xdrv_50_filesystem.ino b/tasmota/xdrv_50_filesystem.ino index 14992eb9d..bc09d5579 100644 --- a/tasmota/xdrv_50_filesystem.ino +++ b/tasmota/xdrv_50_filesystem.ino @@ -88,7 +88,7 @@ uint8_t ffs_type; /*********************************************************************************************/ -void UfsInit(void) { +void UfsInitOnce(void) { ufs_type = 0; ffsp = 0; ufs_dir = 0; @@ -162,6 +162,13 @@ void UfsInit(void) { dfsp = ufsp; } +void UfsInit(void) { + UfsInitOnce(); + if (ufs_type) { + AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: Type %d mounted with %dkB free"), ufs_type, UfsInfo(1, 0)); + } +} + uint32_t UfsInfo(uint32_t sel, uint32_t type) { uint32_t result = 0; FS *ifsp = ufsp; @@ -339,15 +346,25 @@ bool TfsLoadFile(const char *fname, uint8_t *buf, uint32_t len) { return true; } +bool TfsDeleteFile(const char *fname) { + if (!ufs_type) { return false; } + + if (!ffsp->remove(fname)) { + AddLog_P(LOG_LEVEL_INFO, PSTR("TFS: Delete failed")); + return false; + } + return true; +} + /*********************************************************************************************\ * Commands \*********************************************************************************************/ -const char kUFSCommands[] PROGMEM = "Ufs" "|" // Prefix - "|" "Type" "|" "Size" "|" "Free"; +const char kUFSCommands[] PROGMEM = "Ufs|" // Prefix + "|Type|Size|Free|Delete"; void (* const kUFSCommand[])(void) PROGMEM = { - &UFSInfo, &UFSType, &UFSSize, &UFSFree}; + &UFSInfo, &UFSType, &UFSSize, &UFSFree, &UFSDelete}; void UFSInfo(void) { Response_P(PSTR("{\"Ufs\":{\"Type\":%d,\"Size\":%d,\"Free\":%d}}"), ufs_type, UfsInfo(0, 0), UfsInfo(1, 0)); @@ -356,13 +373,25 @@ void UFSInfo(void) { void UFSType(void) { ResponseCmndNumber(ufs_type); } + void UFSSize(void) { ResponseCmndNumber(UfsInfo(0, 0)); } + void UFSFree(void) { ResponseCmndNumber(UfsInfo(1, 0)); } +void UFSDelete(void) { + if (XdrvMailbox.data_len > 0) { + if (!TfsDeleteFile(XdrvMailbox.data)) { + ResponseCmndChar(D_JSON_FAILED); + } else { + ResponseCmndDone(); + } + } +} + /*********************************************************************************************\ * Web support \*********************************************************************************************/