From f422391049cf864d4c77d2a06f81ece17c3762e2 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Tue, 16 Jul 2019 00:48:30 +0300 Subject: [PATCH] Always apply channel inputValue->value --- code/espurna/light.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/espurna/light.ino b/code/espurna/light.ino index aefbfcf9db..b6a5cbdbc0 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -68,6 +68,7 @@ const char _light_channel_desc[5][5] PROGMEM = { {'R', 'G', 'B', 'W', 0}, {'R', 'G', 'B', 'W', 'C'} }; +static_assert((LIGHT_CHANNELS * LIGHT_CHANNELS) == (sizeof(_light_channel_desc)), "Out-of-bounds array access"); // Gamma Correction lookup table (8 bit) const unsigned char _light_gamma_table[] PROGMEM = { @@ -88,6 +89,7 @@ const unsigned char _light_gamma_table[] PROGMEM = { 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 238, 240, 242, 244, 246, 248, 251, 253, 255 }; +static_assert(LIGHT_MAX_VALUE <= sizeof(_light_gamma_table), "Out-of-bounds array access"); // ----------------------------------------------------------------------------- // UTILS @@ -106,9 +108,12 @@ void _setCCTInputValue(unsigned char warm, unsigned char cold) { void _lightApplyBrightness(unsigned char channels = lightChannels()) { - double brightness = (double) _light_brightness / LIGHT_MAX_BRIGHTNESS; + double brightness = static_cast(_light_brightness) / static_cast(LIGHT_MAX_BRIGHTNESS); + + channels = std::min(channels, lightChannels()); - for (unsigned char i=0; i < channels; i++) { + for (unsigned char i=0; i < lightChannels(); i++) { + if (i >= channels) brightness = 1; _light_channel[i].value = _light_channel[i].inputValue * brightness; }