diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 77dfcf35..395c1650 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -402,12 +402,20 @@ PROGMEM const char* const custom_reset_string[] = { #define MQTT_USE_GETTER "" #define MQTT_USE_SETTER "/set" +// ----------------------------------------------------------------------------- +// SETTINGS +// ----------------------------------------------------------------------------- + +#ifndef SETTINGS_AUTOSAVE +#define SETTINGS_AUTOSAVE 1 // Autosave settings o force manual commit +#endif + // ----------------------------------------------------------------------------- // I2C // ----------------------------------------------------------------------------- #ifndef I2C_SUPPORT -#define I2C_SUPPORT 0 // I2C enabled +#define I2C_SUPPORT 0 // I2C enabled #endif #define I2C_SDA_PIN 4 // SDA GPIO diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index 9ebb631d..0eba9db1 100644 --- a/code/espurna/config/version.h +++ b/code/espurna/config/version.h @@ -1,4 +1,4 @@ #define APP_NAME "ESPurna" -#define APP_VERSION "1.9.1" +#define APP_VERSION "1.9.2b" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index c11e8338..43552eea 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -210,6 +210,7 @@ void loop() { wifiLoop(); otaLoop(); mqttLoop(); + settingsLoop(); #ifdef ITEAD_SONOFF_RFBRIDGE rfbLoop(); @@ -218,9 +219,6 @@ void loop() { #if NTP_SUPPORT ntpLoop(); #endif - #if TERMINAL_SUPPORT - settingsLoop(); - #endif #if ALEXA_SUPPORT alexaLoop(); #endif diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index 0a8328b9..2ca13b08 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -11,14 +11,14 @@ Copyright (C) 2016-2017 by Xose PĂ©rez #include "spi_flash.h" #include -#define AUTO_SAVE 1 - #ifdef DEBUG_PORT Embedis embedis(DEBUG_PORT); #else Embedis embedis(Serial); #endif +bool _settings_save = false; + // ----------------------------------------------------------------------------- // Settings // ----------------------------------------------------------------------------- @@ -86,8 +86,8 @@ void settingsSetup() { SPI_FLASH_SEC_SIZE, [](size_t pos) -> char { return EEPROM.read(pos); }, [](size_t pos, char value) { EEPROM.write(pos, value); }, - #if AUTO_SAVE - []() { EEPROM.commit(); } + #if SETTINGS_AUTOSAVE + []() { _settings_save = true; } #else []() {} #endif @@ -246,7 +246,14 @@ void settingsDump() { } void settingsLoop() { - embedis.process(); + if (_settings_save) { + DEBUG_MSG_P(PSTR("[SETTINGS] Saving\n")); + EEPROM.commit(); + _settings_save = false; + } + #if TERMINAL_SUPPORT + embedis.process(); + #endif } void moveSetting(const char * from, const char * to) { @@ -302,9 +309,8 @@ bool hasSetting(const String& key, unsigned int index) { } void saveSettings() { - DEBUG_MSG_P(PSTR("[SETTINGS] Saving\n")); - #if not AUTO_SAVE - EEPROM.commit(); + #if not SETTINGS_AUTOSAVE + _settings_save = true; #endif //settingsDump(); }