Renamed min/max macros to fix potential std::min/max conflict (depending on include order).

This commit is contained in:
Travis J Dean 2020-03-26 05:18:19 -04:00
parent 7bf1c35dcf
commit 30e3bbd0e8
4 changed files with 44 additions and 44 deletions

View File

@ -268,7 +268,7 @@ uint16_t WS2812FX::mode_breath(void) {
counter = (counter >> 2) + (counter >> 4); //0-16384 + 0-2048
if (counter < 16384) {
if (counter > 8192) counter = 8192 - (counter - 8192);
var = sin16(counter) / 103; //close to parabolic in range 0-8192, max val. 23170
var = sin16(counter) / 103; //close to parabolic in range 0-8192, MAX val. 23170
}
uint8_t lum = 30 + var;
@ -475,8 +475,8 @@ uint16_t WS2812FX::mode_twinkle(void) {
uint32_t it = now / cycleTime;
if (it != SEGENV.step)
{
uint16_t maxOn = map(SEGMENT.intensity, 0, 255, 1, SEGLEN); // make sure at least one LED is on
if (SEGENV.aux0 >= maxOn)
uint16_t MAXOn = map(SEGMENT.intensity, 0, 255, 1, SEGLEN); // make sure at least one LED is on
if (SEGENV.aux0 >= MAXOn)
{
SEGENV.aux0 = 0;
SEGENV.aux1 = random16(); //new seed for our PRNG
@ -601,7 +601,7 @@ uint16_t WS2812FX::mode_hyper_sparkle(void) {
}
if(random8(5) < 2) {
for(uint16_t i = 0; i < max(1, SEGLEN/3); i++) {
for(uint16_t i = 0; i < MAX(1, SEGLEN/3); i++) {
setPixelColor(random16(SEGLEN), SEGCOLOR(1));
}
return 20;
@ -1115,7 +1115,7 @@ uint16_t WS2812FX::mode_fireworks() {
if (valid1) setPixelColor(SEGENV.aux0 , sv1);
if (valid2) setPixelColor(SEGENV.aux1, sv2);
for(uint16_t i=0; i<max(1, SEGLEN/20); i++) {
for(uint16_t i=0; i<MAX(1, SEGLEN/20); i++) {
if(random8(129 - (SEGMENT.intensity >> 1)) == 0) {
uint16_t index = random(SEGLEN);
setPixelColor(index, color_from_palette(random8(), false, false, 0));
@ -1162,12 +1162,12 @@ uint16_t WS2812FX::mode_fire_flicker(void) {
byte r = (SEGCOLOR(0) >> 16) & 0xFF;
byte g = (SEGCOLOR(0) >> 8) & 0xFF;
byte b = (SEGCOLOR(0) & 0xFF);
byte lum = (SEGMENT.palette == 0) ? max(w, max(r, max(g, b))) : 255;
byte lum = (SEGMENT.palette == 0) ? MAX(w, MAX(r, MAX(g, b))) : 255;
lum /= (((256-SEGMENT.intensity)/16)+1);
for(uint16_t i = 0; i < SEGLEN; i++) {
byte flicker = random8(lum);
if (SEGMENT.palette == 0) {
setPixelColor(i, max(r - flicker, 0), max(g - flicker, 0), max(b - flicker, 0), max(w - flicker, 0));
setPixelColor(i, MAX(r - flicker, 0), MAX(g - flicker, 0), MAX(b - flicker, 0), MAX(w - flicker, 0));
} else {
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0, 255 - flicker));
}
@ -1197,7 +1197,7 @@ uint16_t WS2812FX::gradient_base(bool loading) {
{
val = abs(((i>pp) ? p2:pp) -i);
} else {
val = min(abs(pp-i),min(abs(p1-i),abs(p2-i)));
val = MIN(abs(pp-i),MIN(abs(p1-i),abs(p2-i)));
}
val = (brd > val) ? val/brd * 255 : 255;
setPixelColor(i, color_blend(SEGCOLOR(0), color_from_palette(i, true, PALETTE_SOLID_WRAP, 1), val));
@ -1597,8 +1597,8 @@ uint16_t WS2812FX::mode_oscillate(void)
uint16_t WS2812FX::mode_lightning(void)
{
uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash
uint16_t ledlen = random16(SEGLEN -1 -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
uint16_t ledstart = random16(SEGLEN); // DeterMINe starting location of flash
uint16_t ledlen = random16(SEGLEN -1 -ledstart); // DeterMINe length of flash (not to go beyond NUM_LEDS-1)
uint8_t bri = 255/random8(1, 3);
if (SEGENV.step == 0)
@ -1778,7 +1778,7 @@ uint16_t WS2812FX::mode_fire_2012()
// Step 4. Map from heat cells to LED colors
for (uint16_t j = 0; j < SEGLEN; j++) {
CRGB color = ColorFromPalette(currentPalette, min(heat[j],240), 255, LINEARBLEND);
CRGB color = ColorFromPalette(currentPalette, MIN(heat[j],240), 255, LINEARBLEND);
setPixelColor(j, color.red, color.green, color.blue);
}
return FRAMETIME;
@ -2153,9 +2153,9 @@ typedef struct Ripple {
uint16_t WS2812FX::ripple_base(bool rainbow)
{
uint16_t maxRipples = 1 + (SEGLEN >> 2);
if (maxRipples > 100) maxRipples = 100;
uint16_t dataSize = sizeof(ripple) * maxRipples;
uint16_t MAXRipples = 1 + (SEGLEN >> 2);
if (MAXRipples > 100) MAXRipples = 100;
uint16_t dataSize = sizeof(ripple) * MAXRipples;
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
@ -2181,7 +2181,7 @@ uint16_t WS2812FX::ripple_base(bool rainbow)
}
//draw wave
for (uint16_t i = 0; i < maxRipples; i++)
for (uint16_t i = 0; i < MAXRipples; i++)
{
uint16_t ripplestate = ripples[i].state;
if (ripplestate)
@ -2480,8 +2480,8 @@ uint16_t WS2812FX::spots_base(uint16_t threshold)
{
fill(SEGCOLOR(1));
uint16_t maxZones = SEGLEN >> 2;
uint16_t zones = 1 + ((SEGMENT.intensity * maxZones) >> 8);
uint16_t MAXZones = SEGLEN >> 2;
uint16_t zones = 1 + ((SEGMENT.intensity * MAXZones) >> 8);
uint16_t zoneLen = SEGLEN / zones;
uint16_t offset = (SEGLEN - zones * zoneLen) >> 1;
@ -2533,15 +2533,15 @@ typedef struct Ball {
*/
uint16_t WS2812FX::mode_bouncing_balls(void) {
//allocate segment data
uint16_t maxNumBalls = 16;
uint16_t dataSize = sizeof(ball) * maxNumBalls;
uint16_t MAXNumBalls = 16;
uint16_t dataSize = sizeof(ball) * MAXNumBalls;
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
Ball* balls = reinterpret_cast<Ball*>(SEGENV.data);
// number of balls based on intensity setting to max of 7 (cycles colors)
// number of balls based on intensity setting to MAX of 7 (cycles colors)
// non-chosen color is a random color
uint8_t numBalls = int(((SEGMENT.intensity * (maxNumBalls - 0.8f)) / 255) + 1);
uint8_t numBalls = int(((SEGMENT.intensity * (MAXNumBalls - 0.8f)) / 255) + 1);
float gravity = -9.81; // standard value of gravity
float impactVelocityStart = sqrt( -2 * gravity);
@ -2549,7 +2549,7 @@ uint16_t WS2812FX::mode_bouncing_balls(void) {
unsigned long time = millis();
if (SEGENV.call == 0) {
for (uint8_t i = 0; i < maxNumBalls; i++) balls[i].lastBounceTime = time;
for (uint8_t i = 0; i < MAXNumBalls; i++) balls[i].lastBounceTime = time;
}
bool hasCol2 = SEGCOLOR(2);
@ -2573,7 +2573,7 @@ uint16_t WS2812FX::mode_bouncing_balls(void) {
uint32_t color = SEGCOLOR(0);
if (SEGMENT.palette) {
color = color_wheel(i*(256/max(numBalls, 8)));
color = color_wheel(i*(256/MAX(numBalls, 8)));
} else if (hasCol2) {
color = SEGCOLOR(i % NUM_COLORS);
}
@ -2665,8 +2665,8 @@ typedef struct Spark {
*/
uint16_t WS2812FX::mode_popcorn(void) {
//allocate segment data
uint16_t maxNumPopcorn = 24;
uint16_t dataSize = sizeof(spark) * maxNumPopcorn;
uint16_t MAXNumPopcorn = 24;
uint16_t dataSize = sizeof(spark) * MAXNumPopcorn;
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
Spark* popcorn = reinterpret_cast<Spark*>(SEGENV.data);
@ -2677,7 +2677,7 @@ uint16_t WS2812FX::mode_popcorn(void) {
bool hasCol2 = SEGCOLOR(2);
fill(hasCol2 ? BLACK : SEGCOLOR(1));
uint8_t numPopcorn = SEGMENT.intensity*maxNumPopcorn/255;
uint8_t numPopcorn = SEGMENT.intensity*MAXNumPopcorn/255;
if (numPopcorn == 0) numPopcorn = 1;
for(uint8_t i = 0; i < numPopcorn; i++) {
@ -2792,13 +2792,13 @@ uint16_t WS2812FX::mode_starburst(void) {
star* stars = reinterpret_cast<star*>(SEGENV.data);
float maxSpeed = 375.0f; // Max velocity
float MAXSpeed = 375.0f; // Max velocity
float particleIgnition = 250.0f; // How long to "flash"
float particleFadeTime = 1500.0f; // Fade out time
for (int j = 0; j < numStars; j++)
{
// speed to adjust chance of a burst, max is nearly always.
// speed to adjust chance of a burst, MAX is nearly always.
if (random8((144-(SEGMENT.speed >> 1))) == 0 && stars[j].birth == 0)
{
// Pick a random color and location.
@ -2807,7 +2807,7 @@ uint16_t WS2812FX::mode_starburst(void) {
stars[j].color = col_to_crgb(color_wheel(random8()));
stars[j].pos = startPos;
stars[j].vel = maxSpeed * (float)(random8())/255.0 * multiplier;
stars[j].vel = MAXSpeed * (float)(random8())/255.0 * multiplier;
stars[j].birth = it;
stars[j].last = it;
// more fragments means larger burst effect
@ -3026,7 +3026,7 @@ uint16_t WS2812FX::mode_drip(void)
drops[j].pos = SEGLEN-1; // start at end
drops[j].vel = 0; // speed
drops[j].col = sourcedrop; // brightness
drops[j].colIndex = 1; // drop state (0 init, 1 forming, 2 falling, 5 bouncing)
drops[j].colIndex = 1; // drop state (0 init, 1 forMINg, 2 falling, 5 bouncing)
}
setPixelColor(SEGLEN-1,color_blend(BLACK,SEGCOLOR(0), sourcedrop));// water source
@ -3047,7 +3047,7 @@ uint16_t WS2812FX::mode_drip(void)
if (drops[j].pos < 0) drops[j].pos = 0;
drops[j].vel += gravity;
for (int i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets
for (int i=1;i<7-drops[j].colIndex;i++) { // some MINor math so we don't expand bouncing droplets
setPixelColor(int(drops[j].pos)+i,color_blend(BLACK,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling
}
@ -3055,7 +3055,7 @@ uint16_t WS2812FX::mode_drip(void)
setPixelColor(0,color_blend(SEGCOLOR(0),BLACK,drops[j].col));
}
} else { // we hit bottom
if (drops[j].colIndex > 2) { // already hit once, so back to forming
if (drops[j].colIndex > 2) { // already hit once, so back to forMINg
drops[j].colIndex = 0;
drops[j].col = sourcedrop;
@ -3100,7 +3100,7 @@ uint16_t WS2812FX::mode_plasma(void) {
*/
uint16_t WS2812FX::mode_percent(void) {
uint8_t percent = max(0, min(200, SEGMENT.intensity));
uint8_t percent = MAX(0, MIN(200, SEGMENT.intensity));
uint16_t active_leds = (percent < 100) ? SEGLEN * percent / 100.0
: SEGLEN * (200 - percent) / 100.0;

View File

@ -38,8 +38,8 @@
#define DEFAULT_SPEED (uint8_t)128
#define DEFAULT_COLOR (uint32_t)0xFFAA00
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
/* Not used in all effects yet */
#define WLED_FPS 42

View File

@ -224,7 +224,7 @@ void WS2812FX::show(void) {
if(useWackyWS2815PowerModel)
{
// ignore white component on WS2815 power calculation
powerSum += (max(max(c.R,c.G),c.B)) * 3;
powerSum += (MAX(MAX(c.R,c.G),c.B)) * 3;
}
else
{
@ -638,7 +638,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 MINimum distance of 42 from pos.
*/
uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) {
uint8_t r = 0, x = 0, y = 0, d = 0;
@ -647,7 +647,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 = MIN(x, y);
}
return r;
}
@ -730,8 +730,8 @@ void WS2812FX::handle_palette(void)
CHSV prim_hsv = rgb2hsv_approximate(prim);
targetPalette = CRGBPalette16(
CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v), //color itself
CHSV(prim_hsv.h, max(prim_hsv.s - 50,0), prim_hsv.v), //less saturated
CHSV(prim_hsv.h, prim_hsv.s, max(prim_hsv.v - 50,0)), //darker
CHSV(prim_hsv.h, MAX(prim_hsv.s - 50,0), prim_hsv.v), //less saturated
CHSV(prim_hsv.h, prim_hsv.s, MAX(prim_hsv.v - 50,0)), //darker
CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v)); //color itself
break;}
case 4: {//primary + secondary

View File

@ -468,10 +468,10 @@ extern WS2812FX strip;
#define DEBUG_PRINT(x) Serial.print(x)
#define DEBUG_PRINTLN(x) Serial.println(x)
#define DEBUG_PRINTF(x) Serial.printf(x)
unsigned long debugTime = 0;
int lastWifiState = 3;
unsigned long wifiStateChangedTime = 0;
int loops = 0;
extern unsigned long debugTime;
extern int lastWifiState;
extern unsigned long wifiStateChangedTime;
extern int loops;
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)