From 385bba7d0e08af79495953363a105419f15f1724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 29 Aug 2017 18:58:55 +0200 Subject: [PATCH] Issue #190. Race condition inside a ticker callback caused a crash loop on boot --- code/espurna/config/general.h | 10 +++++++++- code/espurna/config/version.h | 2 +- code/espurna/espurna.ino | 4 +--- code/espurna/settings.ino | 22 ++++++++++++++-------- 4 files changed, 25 insertions(+), 13 deletions(-) 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(); }