diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index fc01deb0..dcca6654 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -486,6 +486,10 @@ PROGMEM const char* const custom_reset_string[] = { // 4 channels => RGBW // 5 channels => RGBWW +#ifndef LIGHT_SAVE_ENABLED +#define LIGHT_SAVE_ENABLED 1 // Light channel values saved by default after each change +#endif + #define LIGHT_SAVE_DELAY 5 // Persist color after 5 seconds to avoid wearing out #define LIGHT_PWM_FREQUENCY 1000 // PWM frequency #define LIGHT_MAX_PWM 4095 // Maximum PWM value diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 9fe53374..693827ff 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -272,7 +272,7 @@ void _lightColorSave() { void _lightColorRestore() { for (unsigned int i=0; i < _channels.size(); i++) { - _channels[i].value = getSetting("ch", i, 0).toInt(); + _channels[i].value = getSetting("ch", i, i==0 ? 255 : 0).toInt(); } _brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt(); lightUpdate(false, false); @@ -415,11 +415,19 @@ void lightUpdate(bool save, bool forward) { } #endif - // Delay saving to EEPROM 5 seconds to avoid wearing it out unnecessarily - if (save) colorTicker.once(LIGHT_SAVE_DELAY, _lightColorSave); + #if LIGHT_SAVE_ENABLED + // Delay saving to EEPROM 5 seconds to avoid wearing it out unnecessarily + if (save) colorTicker.once(LIGHT_SAVE_DELAY, _lightColorSave); + #endif }; +#if LIGHT_SAVE_ENABLED == 0 +void lightSave() { + _lightColorSave(); +} +#endif + void lightState(bool state) { _lightState = state; } diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 6abcf66d..df46aa0c 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -428,6 +428,13 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) { #if POWER_PROVIDER != POWER_PROVIDER_NONE powerConfigure(); #endif + + #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE + #if LIGHT_SAVE_ENABLED == 0 + lightSave(); + #endif + #endif + #if NTP_SUPPORT if (changedNTP) ntpConnect(); #endif