diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 7888e5f3..5dc59214 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -11,6 +11,7 @@ Copyright (C) 2016-2019 by Xose PĂ©rez #include "light.h" #include +#include #include #include @@ -42,14 +43,18 @@ struct channel_t { }; std::vector _light_channel; -bool _light_state = false; -bool _light_use_transitions = false; -unsigned int _light_transition_time = LIGHT_TRANSITION_TIME; bool _light_has_color = false; bool _light_use_white = false; bool _light_use_cct = false; bool _light_use_gamma = false; + +bool _light_provider_update = false; + +bool _light_use_transitions = false; +unsigned int _light_transition_time = LIGHT_TRANSITION_TIME; unsigned long _light_steps_left = 1; + +bool _light_state = false; unsigned char _light_brightness = Light::BRIGHTNESS_MAX; unsigned int _light_mireds = lround((LIGHT_COLDWHITE_MIRED+LIGHT_WARMWHITE_MIRED)/2); @@ -507,6 +512,10 @@ void _transition() { void _lightProviderUpdate() { + if (_light_provider_update) return; + + _light_provider_update = true; + _transition(); #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY92XX @@ -528,6 +537,12 @@ void _lightProviderUpdate() { #endif + _light_provider_update = false; + +} + +void _lightProviderDoUpdate() { + schedule_function(_lightProviderUpdate); } // ----------------------------------------------------------------------------- @@ -589,7 +604,6 @@ void _lightRestoreSettings() { } _light_brightness = getSetting("brightness", Light::BRIGHTNESS_MAX).toInt(); _light_mireds = getSetting("mireds", _light_mireds).toInt(); - lightUpdate(false, false); } // ----------------------------------------------------------------------------- @@ -807,7 +821,7 @@ void lightUpdate(bool save, bool forward, bool group_forward) { // Configure color transition _light_steps_left = _light_use_transitions ? _light_transition_time / LIGHT_TRANSITION_STEP : 1; - _light_transition_ticker.attach_ms(LIGHT_TRANSITION_STEP, _lightProviderUpdate); + _light_transition_ticker.attach_ms(LIGHT_TRANSITION_STEP, _lightProviderDoUpdate); // Delay every communication 100ms to avoid jamming unsigned char mask = 0; @@ -1306,6 +1320,7 @@ void lightSetup() { } else { _lightRestoreSettings(); } + lightUpdate(false, false); #if WEB_SUPPORT wsRegister()