diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 31dd8a87c..5dfc21424 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -694,7 +694,7 @@ void SettingsLoad(void) { if (source) { settings_location = 1; if (Settings->cfg_holder == (uint16_t)CFG_HOLDER) { - AddLog(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from %s, " D_COUNT " %lu"), (source)?"File":"Nvm", Settings->save_flag); + AddLog(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from %s, " D_COUNT " %lu"), (2 == source)?"File":"NVS", Settings->save_flag); } } #endif // ESP32 diff --git a/tasmota/support_esp.ino b/tasmota/support_esp.ino index 93abe9daa..81b6ee6f6 100644 --- a/tasmota/support_esp.ino +++ b/tasmota/support_esp.ino @@ -137,34 +137,43 @@ String GetDeviceHardware(void) { #include -void NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) { - nvs_handle handle; - noInterrupts(); - nvs_open(sNvsName, NVS_READONLY, &handle); +bool NvmLoad(const char *sNvsName, const char *sName, void *pSettings, unsigned nSettingsLen) { + nvs_handle_t handle; +// noInterrupts(); + esp_err_t result = nvs_open(sNvsName, NVS_READONLY, &handle); + if (result != ESP_OK) { + AddLog(LOG_LEVEL_DEBUG, PSTR("NVS: Error %d"), result); + return false; + } size_t size = nSettingsLen; nvs_get_blob(handle, sName, pSettings, &size); nvs_close(handle); - interrupts(); +// interrupts(); + return true; } void NvmSave(const char *sNvsName, const char *sName, const void *pSettings, unsigned nSettingsLen) { - nvs_handle handle; - noInterrupts(); - nvs_open(sNvsName, NVS_READWRITE, &handle); + nvs_handle_t handle; +// noInterrupts(); + esp_err_t result = nvs_open(sNvsName, NVS_READWRITE, &handle); + if (result != ESP_OK) { + AddLog(LOG_LEVEL_DEBUG, PSTR("NVS: Error %d"), result); + return; + } nvs_set_blob(handle, sName, pSettings, nSettingsLen); nvs_commit(handle); nvs_close(handle); - interrupts(); +// interrupts(); } int32_t NvmErase(const char *sNvsName) { - nvs_handle handle; - noInterrupts(); + nvs_handle_t handle; +// noInterrupts(); int32_t result = nvs_open(sNvsName, NVS_READWRITE, &handle); if (ESP_OK == result) { result = nvs_erase_all(handle); } if (ESP_OK == result) { result = nvs_commit(handle); } nvs_close(handle); - interrupts(); +// interrupts(); return result; } @@ -208,23 +217,25 @@ void SettingsErase(uint8_t type) { } uint32_t SettingsRead(void *data, size_t size) { - uint32_t source = 1; -#ifdef USE_UFILESYS - if (!TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)data, size)) { -#endif - source = 0; - NvmLoad("main", "Settings", data, size); #ifdef USE_UFILESYS + if (TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)data, size)) { + return 2; } #endif - return source; + if (NvmLoad("main", "Settings", data, size)) { + return 1; + }; + return 0; } void SettingsWrite(const void *pSettings, unsigned nSettingsLen) { #ifdef USE_UFILESYS TfsSaveFile(TASM_FILE_SETTINGS, (const uint8_t*)pSettings, nSettingsLen); #endif - NvmSave("main", "Settings", pSettings, nSettingsLen); +#ifdef USE_WEBCAM + if (!WcStreamActive()) +#endif + NvmSave("main", "Settings", pSettings, nSettingsLen); } void QPCRead(void *pSettings, unsigned nSettingsLen) { diff --git a/tasmota/xdrv_50_filesystem.ino b/tasmota/xdrv_50_filesystem.ino index 8a0ed1d16..7150fbd85 100644 --- a/tasmota/xdrv_50_filesystem.ino +++ b/tasmota/xdrv_50_filesystem.ino @@ -294,7 +294,23 @@ bool TfsSaveFile(const char *fname, const uint8_t *buf, uint32_t len) { return false; } - file.write(buf, len); +// This will timeout on ESP32-webcam +// file.write(buf, len); + + uint32_t count = len / 512; + uint32_t chunk = len / count; + for (uint32_t i = 0; i < count; i++) { + file.write(buf + (i * chunk), chunk); + // do actually wait a little to allow ESP32 tasks to tick + // fixes task timeout in ESP32Solo1 style unicore code and webcam. + delay(10); + OsWatchLoop(); + } + uint32_t left = len % count; + if (left) { + file.write(buf + (count * chunk), left); + } + file.close(); return true; } diff --git a/tasmota/xdrv_81_esp32_webcam.ino b/tasmota/xdrv_81_esp32_webcam.ino index dca8ec936..273885049 100644 --- a/tasmota/xdrv_81_esp32_webcam.ino +++ b/tasmota/xdrv_81_esp32_webcam.ino @@ -876,6 +876,10 @@ void WcStreamControl() { WcSetup(Settings->webcam_config.resolution); } +bool WcStreamActive(void) { + return (Wc.stream_active); +} + /*********************************************************************************************/