diff --git a/code/espurna/light.h b/code/espurna/light.h index ab48c5f0..4fcbb75a 100644 --- a/code/espurna/light.h +++ b/code/espurna/light.h @@ -22,5 +22,10 @@ namespace Light { constexpr const long PWM_MIN = LIGHT_MIN_PWM; constexpr const long PWM_MAX = LIGHT_MAX_PWM; constexpr const long PWM_LIMIT = LIGHT_LIMIT_PWM; -} + enum Communications : unsigned char { + COMMS_NONE = 0, + COMMS_NORMAL = 1 << 0, + COMMS_GROUP = 1 << 1 + }; +} diff --git a/code/espurna/light.ino b/code/espurna/light.ino index aea3482b..149a90c0 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -819,12 +819,12 @@ bool lightUseCCT() { return _light_use_cct; } -void _lightComms(unsigned char mask) { +void _lightComms(const unsigned char mask) { - // Report color & brightness to MQTT broker + // Report color and brightness to MQTT broker #if MQTT_SUPPORT - if (mask & 0x01) lightMQTT(); - if (mask & 0x02) lightMQTTGroup(); + if (mask & Light::COMMS_NORMAL) lightMQTT(); + if (mask & Light::COMMS_GROUP) lightMQTTGroup(); #endif // Report color to WS clients (using current brightness setting) @@ -856,13 +856,13 @@ void lightUpdate(bool save, bool forward, bool group_forward) { // Channel transition will be handled by the provider function // User can configure total transition time, step time is a fixed value - unsigned long steps = _light_use_transitions ? _light_transition_time / LIGHT_TRANSITION_STEP : 1; + const unsigned long steps = _light_use_transitions ? _light_transition_time / LIGHT_TRANSITION_STEP : 1; _light_transition_ticker.once_ms(LIGHT_TRANSITION_STEP, _lightProviderScheduleUpdate, steps); // Delay every communication 100ms to avoid jamming - unsigned char mask = 0; - if (forward) mask += 1; - if (group_forward) mask += 2; + const unsigned char mask = + ((forward) ? Light::COMMS_NORMAL : Light::COMMS_NONE) | + ((group_forward) ? Light::COMMS_GROUP : Light::COMMS_NONE); _light_comms_ticker.once_ms(LIGHT_COMMS_DELAY, _lightComms, mask); _lightSaveRtcmem();