From 0c1ed9081cc5af6dfca035153655c2b9532e4b45 Mon Sep 17 00:00:00 2001 From: snowrodeo Date: Mon, 21 Oct 2024 21:27:28 -0700 Subject: [PATCH 1/3] Fix for broken max macro --- src/WS2812FX.cpp | 2 +- src/WS2812FX.h | 8 ++------ src/modes.cpp | 4 ++-- src/modes_funcs.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/WS2812FX.cpp b/src/WS2812FX.cpp index 5eed240..beaf6a4 100644 --- a/src/WS2812FX.cpp +++ b/src/WS2812FX.cpp @@ -79,7 +79,7 @@ bool WS2812FX::service() { SET_FRAME; doShow = true; uint16_t delay = (MODE_PTR(_seg->mode))(); - _seg_rt->next_time = now + max(delay, SPEED_MIN); + _seg_rt->next_time = now + ws2812fx_max(delay, SPEED_MIN); _seg_rt->counter_mode_call++; } } diff --git a/src/WS2812FX.h b/src/WS2812FX.h index 23c3b44..4eca2b8 100644 --- a/src/WS2812FX.h +++ b/src/WS2812FX.h @@ -46,12 +46,8 @@ #include #endif -// include max macro for ESP boards -#ifndef max -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) +#ifndef ws2812fx_max +#define ws2812fx_max(a, b) ((a) > (b) ? (a) : (b)) #endif #define DEFAULT_BRIGHTNESS (uint8_t)50 diff --git a/src/modes.cpp b/src/modes.cpp index efb60b5..d60790c 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -302,7 +302,7 @@ uint16_t WS2812FX::mode_theater_chase_rainbow(void) { */ uint16_t WS2812FX::mode_running_lights(void) { uint8_t size = 1 << SIZE_OPTION; - uint8_t sineIncr = max((uint8_t)1, (256 / _seg_len) * size); + uint8_t sineIncr = ws2812fx_max((uint8_t)1, (256 / _seg_len) * size); for(uint16_t i=0; i < _seg_len; i++) { int lum = (int)sine8(((i + _seg_rt->counter_mode_step) * sineIncr)); uint32_t color = color_blend(_seg->colors[0], _seg->colors[1], lum); @@ -865,7 +865,7 @@ uint16_t WS2812FX::mode_rainbow_fireworks(void) { // occasionally create a random red pixel if(random8(4) == 0) { - uint16_t index = _seg->start + 6 + random16(max((uint8_t)1, _seg_len - 12)); + uint16_t index = _seg->start + 6 + random16(ws2812fx_max((uint8_t)1, _seg_len - 12)); setRawPixelColor(index, RED); // set the raw pixel color (ignore global brightness) SET_CYCLE; } diff --git a/src/modes_funcs.cpp b/src/modes_funcs.cpp index 01c97f5..99c3b4a 100644 --- a/src/modes_funcs.cpp +++ b/src/modes_funcs.cpp @@ -386,7 +386,7 @@ uint16_t WS2812FX::fireworks(uint32_t color) { uint8_t size = 2 << SIZE_OPTION; if(!_triggered) { - for(uint16_t i=0; istart + random16(_seg_len - size + 1); fill(color, index, size); @@ -394,7 +394,7 @@ uint16_t WS2812FX::fireworks(uint32_t color) { } } } else { - for(uint16_t i=0; istart + random16(_seg_len - size + 1); fill(color, index, size); SET_CYCLE; @@ -412,10 +412,10 @@ uint16_t WS2812FX::fire_flicker(int rev_intensity) { byte r = (_seg->colors[0] >> 16) & 0xFF; byte g = (_seg->colors[0] >> 8) & 0xFF; byte b = (_seg->colors[0] & 0xFF); - byte lum = max(w, max(r, max(g, b))) / rev_intensity; + byte lum = ws2812fx_max(w, ws2812fx_max(r, ws2812fx_max(g, b))) / rev_intensity; for(uint16_t i=_seg->start; i <= _seg->stop; i++) { int flicker = random8(lum); - setPixelColor(i, max(r - flicker, 0), max(g - flicker, 0), max(b - flicker, 0), max(w - flicker, 0)); + setPixelColor(i, ws2812fx_max(r - flicker, 0), ws2812fx_max(g - flicker, 0), ws2812fx_max(b - flicker, 0), ws2812fx_max(w - flicker, 0)); } SET_CYCLE; From 8d8be514100c3530c8f1147ce81695a5be73d703 Mon Sep 17 00:00:00 2001 From: snowrodeo Date: Tue, 22 Oct 2024 12:13:17 -0700 Subject: [PATCH 2/3] Changed fix for max macro to std::max usage --- src/WS2812FX.cpp | 2 +- src/WS2812FX.h | 5 ++--- src/modes.cpp | 4 ++-- src/modes_funcs.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/WS2812FX.cpp b/src/WS2812FX.cpp index beaf6a4..c2b310b 100644 --- a/src/WS2812FX.cpp +++ b/src/WS2812FX.cpp @@ -79,7 +79,7 @@ bool WS2812FX::service() { SET_FRAME; doShow = true; uint16_t delay = (MODE_PTR(_seg->mode))(); - _seg_rt->next_time = now + ws2812fx_max(delay, SPEED_MIN); + _seg_rt->next_time = now + std::max(delay, SPEED_MIN); _seg_rt->counter_mode_call++; } } diff --git a/src/WS2812FX.h b/src/WS2812FX.h index 4eca2b8..438bec4 100644 --- a/src/WS2812FX.h +++ b/src/WS2812FX.h @@ -46,9 +46,8 @@ #include #endif -#ifndef ws2812fx_max -#define ws2812fx_max(a, b) ((a) > (b) ? (a) : (b)) -#endif +// needed for std::max +#include #define DEFAULT_BRIGHTNESS (uint8_t)50 #define DEFAULT_MODE (uint8_t)0 diff --git a/src/modes.cpp b/src/modes.cpp index d60790c..2db5325 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -302,7 +302,7 @@ uint16_t WS2812FX::mode_theater_chase_rainbow(void) { */ uint16_t WS2812FX::mode_running_lights(void) { uint8_t size = 1 << SIZE_OPTION; - uint8_t sineIncr = ws2812fx_max((uint8_t)1, (256 / _seg_len) * size); + uint8_t sineIncr = std::max((uint8_t)1, (uint8_t)((256 / _seg_len) * size)); for(uint16_t i=0; i < _seg_len; i++) { int lum = (int)sine8(((i + _seg_rt->counter_mode_step) * sineIncr)); uint32_t color = color_blend(_seg->colors[0], _seg->colors[1], lum); @@ -865,7 +865,7 @@ uint16_t WS2812FX::mode_rainbow_fireworks(void) { // occasionally create a random red pixel if(random8(4) == 0) { - uint16_t index = _seg->start + 6 + random16(ws2812fx_max((uint8_t)1, _seg_len - 12)); + uint16_t index = _seg->start + 6 + random16(std::max((uint8_t)1, (uint8_t)(_seg_len - 12))); setRawPixelColor(index, RED); // set the raw pixel color (ignore global brightness) SET_CYCLE; } diff --git a/src/modes_funcs.cpp b/src/modes_funcs.cpp index 99c3b4a..871b889 100644 --- a/src/modes_funcs.cpp +++ b/src/modes_funcs.cpp @@ -386,7 +386,7 @@ uint16_t WS2812FX::fireworks(uint32_t color) { uint8_t size = 2 << SIZE_OPTION; if(!_triggered) { - for(uint16_t i=0; istart + random16(_seg_len - size + 1); fill(color, index, size); @@ -394,7 +394,7 @@ uint16_t WS2812FX::fireworks(uint32_t color) { } } } else { - for(uint16_t i=0; istart + random16(_seg_len - size + 1); fill(color, index, size); SET_CYCLE; @@ -412,10 +412,10 @@ uint16_t WS2812FX::fire_flicker(int rev_intensity) { byte r = (_seg->colors[0] >> 16) & 0xFF; byte g = (_seg->colors[0] >> 8) & 0xFF; byte b = (_seg->colors[0] & 0xFF); - byte lum = ws2812fx_max(w, ws2812fx_max(r, ws2812fx_max(g, b))) / rev_intensity; + byte lum = std::max(w, std::max(r, std::max(g, b))) / rev_intensity; for(uint16_t i=_seg->start; i <= _seg->stop; i++) { int flicker = random8(lum); - setPixelColor(i, ws2812fx_max(r - flicker, 0), ws2812fx_max(g - flicker, 0), ws2812fx_max(b - flicker, 0), ws2812fx_max(w - flicker, 0)); + setPixelColor(i, std::max(r - flicker, 0), std::max(g - flicker, 0), std::max(b - flicker, 0), std::max(w - flicker, 0)); } SET_CYCLE; From 3028024003f332e176f0ccb247d66790fbaeb818 Mon Sep 17 00:00:00 2001 From: snowrodeo Date: Tue, 22 Oct 2024 17:31:45 -0700 Subject: [PATCH 3/3] Changed min to std::min in WS2812FX.cpp --- src/WS2812FX.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WS2812FX.cpp b/src/WS2812FX.cpp index c2b310b..8392ee3 100644 --- a/src/WS2812FX.cpp +++ b/src/WS2812FX.cpp @@ -585,7 +585,7 @@ uint32_t WS2812FX::color_wheel(uint8_t pos) { } /* - * Returns a new, random wheel index with a minimum distance of 42 from pos. + * Returns a new, random wheel index with a histimum distance of 42 from pos. */ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) { uint8_t r = 0; @@ -597,7 +597,7 @@ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) { r = random8(); x = abs(pos - r); y = 255 - x; - d = min(x, y); + d = std::min(x, y); } return r;