Minor bugfix and for loop optimization.

This commit is contained in:
Blaz Kristan 2022-07-19 22:14:46 +02:00
parent a46894f395
commit b6e53b1a0c
5 changed files with 93 additions and 88 deletions

View File

@ -612,7 +612,7 @@ uint16_t dissolve(uint32_t color) {
for (uint16_t j = 0; j <= SEGLEN / 15; j++) for (uint16_t j = 0; j <= SEGLEN / 15; j++)
{ {
if (random8() <= SEGMENT.intensity) { if (random8() <= SEGMENT.intensity) {
for (uint8_t times = 0; times < 10; times++) //attempt to spawn a new pixel 5 times for (size_t times = 0; times < 10; times++) //attempt to spawn a new pixel 5 times
{ {
uint16_t i = random16(SEGLEN); uint16_t i = random16(SEGLEN);
if (SEGENV.aux0) { //dissolve to primary/palette if (SEGENV.aux0) { //dissolve to primary/palette
@ -937,11 +937,11 @@ uint16_t mode_colorful(void) {
if (SEGMENT.intensity > 160 || SEGMENT.palette) { //palette or color if (SEGMENT.intensity > 160 || SEGMENT.palette) { //palette or color
if (!SEGMENT.palette) { if (!SEGMENT.palette) {
numColors = 3; numColors = 3;
for (uint8_t i = 0; i < 3; i++) cols[i] = SEGCOLOR(i); for (size_t i = 0; i < 3; i++) cols[i] = SEGCOLOR(i);
} else { } else {
uint16_t fac = 80; uint16_t fac = 80;
if (SEGMENT.palette == 52) {numColors = 5; fac = 61;} //C9 2 has 5 colors if (SEGMENT.palette == 52) {numColors = 5; fac = 61;} //C9 2 has 5 colors
for (uint8_t i = 0; i < numColors; i++) { for (size_t i = 0; i < numColors; i++) {
cols[i] = SEGMENT.color_from_palette(i*fac, false, true, 255); cols[i] = SEGMENT.color_from_palette(i*fac, false, true, 255);
} }
} }
@ -952,7 +952,7 @@ uint16_t mode_colorful(void) {
cols[2] = 0x0077FF77; cols[2] = 0x0077FF77;
cols[3] = 0x0077F0F0; cols[3] = 0x0077F0F0;
} }
for (uint8_t i = numColors; i < numColors*2 -1; i++) cols[i] = cols[i-numColors]; for (size_t i = numColors; i < numColors*2 -1; i++) cols[i] = cols[i-numColors];
uint32_t cycleTime = 50 + (8 * (uint32_t)(255 - SEGMENT.speed)); uint32_t cycleTime = 50 + (8 * (uint32_t)(255 - SEGMENT.speed));
uint32_t it = strip.now / cycleTime; uint32_t it = strip.now / cycleTime;
@ -2253,7 +2253,7 @@ uint16_t mode_colortwinkle()
for (uint16_t j = 0; j <= rows*cols / 50; j++) { for (uint16_t j = 0; j <= rows*cols / 50; j++) {
if (random8() <= SEGMENT.intensity) { if (random8() <= SEGMENT.intensity) {
for (uint8_t times = 0; times < 5; times++) { //attempt to spawn a new pixel 5 times for (size_t times = 0; times < 5; times++) { //attempt to spawn a new pixel 5 times
uint16_t i = random16(rows*cols); uint16_t i = random16(rows*cols);
uint16_t j = i % cols, k = i / cols; uint16_t j = i % cols, k = i / cols;
uint32_t col = strip.isMatrix ? SEGMENT.getPixelColorXY(j, k) : SEGMENT.getPixelColor(i); uint32_t col = strip.isMatrix ? SEGMENT.getPixelColorXY(j, k) : SEGMENT.getPixelColor(i);
@ -2832,13 +2832,13 @@ uint16_t mode_bouncing_balls(void) {
unsigned long time = millis(); unsigned long time = millis();
if (SEGENV.call == 0) { if (SEGENV.call == 0) {
for (uint8_t i = 0; i < maxNumBalls; i++) balls[i].lastBounceTime = time; for (size_t i = 0; i < maxNumBalls; i++) balls[i].lastBounceTime = time;
} }
bool hasCol2 = SEGCOLOR(2); bool hasCol2 = SEGCOLOR(2);
SEGMENT.fill(hasCol2 ? BLACK : SEGCOLOR(1)); SEGMENT.fill(hasCol2 ? BLACK : SEGCOLOR(1));
for (uint8_t i = 0; i < numBalls; i++) { for (size_t i = 0; i < numBalls; i++) {
float timeSinceLastBounce = (time - balls[i].lastBounceTime)/((255-SEGMENT.speed)*8/256 +1); float timeSinceLastBounce = (time - balls[i].lastBounceTime)/((255-SEGMENT.speed)*8/256 +1);
balls[i].height = 0.5 * gravity * pow(timeSinceLastBounce/1000 , 2.0) + balls[i].impactVelocity * timeSinceLastBounce/1000; balls[i].height = 0.5 * gravity * pow(timeSinceLastBounce/1000 , 2.0) + balls[i].impactVelocity * timeSinceLastBounce/1000;
@ -3221,7 +3221,7 @@ uint16_t mode_starburst(void) {
float particleSize = (1.0f - fade) * 2.0f; float particleSize = (1.0f - fade) * 2.0f;
for (uint8_t index=0; index < STARBURST_MAX_FRAG*2; index++) { for (size_t index=0; index < STARBURST_MAX_FRAG*2; index++) {
bool mirrored = index & 0x1; bool mirrored = index & 0x1;
uint8_t i = index >> 1; uint8_t i = index >> 1;
if (stars[j].fragment[i] > 0) { if (stars[j].fragment[i] > 0) {
@ -3405,7 +3405,7 @@ uint16_t mode_drip(void)
int sourcedrop = 12; int sourcedrop = 12;
for (uint16_t k=0; k < cols; k++) { for (uint16_t k=0; k < cols; k++) {
for (uint8_t j=0; j < numDrops; j++) { for (size_t j=0; j < numDrops; j++) {
uint16_t idx = k*numDrops + j; uint16_t idx = k*numDrops + j;
if (drops[idx].colIndex == 0) { //init if (drops[idx].colIndex == 0) { //init
@ -4051,7 +4051,7 @@ uint16_t mode_dancing_shadows(void)
unsigned long time = millis(); unsigned long time = millis();
bool respawn = false; bool respawn = false;
for (uint8_t i = 0; i < numSpotlights; i++) { for (size_t i = 0; i < numSpotlights; i++) {
if (!initialize) { if (!initialize) {
// advance the position of the spotlight // advance the position of the spotlight
int16_t delta = (float)(time - spotlights[i].lastUpdateTime) * int16_t delta = (float)(time - spotlights[i].lastUpdateTime) *
@ -4098,7 +4098,7 @@ uint16_t mode_dancing_shadows(void)
} else { } else {
switch (spotlights[i].type) { switch (spotlights[i].type) {
case SPOT_TYPE_SOLID: case SPOT_TYPE_SOLID:
for (uint8_t j = 0; j < spotlights[i].width; j++) { for (size_t j = 0; j < spotlights[i].width; j++) {
if ((start + j) >= 0 && (start + j) < SEGLEN) { if ((start + j) >= 0 && (start + j) < SEGLEN) {
SEGMENT.blendPixelColor(start + j, color, 128); SEGMENT.blendPixelColor(start + j, color, 128);
} }
@ -4106,7 +4106,7 @@ uint16_t mode_dancing_shadows(void)
break; break;
case SPOT_TYPE_GRADIENT: case SPOT_TYPE_GRADIENT:
for (uint8_t j = 0; j < spotlights[i].width; j++) { for (size_t j = 0; j < spotlights[i].width; j++) {
if ((start + j) >= 0 && (start + j) < SEGLEN) { if ((start + j) >= 0 && (start + j) < SEGLEN) {
SEGMENT.blendPixelColor(start + j, color, cubicwave8(map(j, 0, spotlights[i].width - 1, 0, 255))); SEGMENT.blendPixelColor(start + j, color, cubicwave8(map(j, 0, spotlights[i].width - 1, 0, 255)));
} }
@ -4114,7 +4114,7 @@ uint16_t mode_dancing_shadows(void)
break; break;
case SPOT_TYPE_2X_GRADIENT: case SPOT_TYPE_2X_GRADIENT:
for (uint8_t j = 0; j < spotlights[i].width; j++) { for (size_t j = 0; j < spotlights[i].width; j++) {
if ((start + j) >= 0 && (start + j) < SEGLEN) { if ((start + j) >= 0 && (start + j) < SEGLEN) {
SEGMENT.blendPixelColor(start + j, color, cubicwave8(2 * map(j, 0, spotlights[i].width - 1, 0, 255))); SEGMENT.blendPixelColor(start + j, color, cubicwave8(2 * map(j, 0, spotlights[i].width - 1, 0, 255)));
} }
@ -4122,7 +4122,7 @@ uint16_t mode_dancing_shadows(void)
break; break;
case SPOT_TYPE_2X_DOT: case SPOT_TYPE_2X_DOT:
for (uint8_t j = 0; j < spotlights[i].width; j += 2) { for (size_t j = 0; j < spotlights[i].width; j += 2) {
if ((start + j) >= 0 && (start + j) < SEGLEN) { if ((start + j) >= 0 && (start + j) < SEGLEN) {
SEGMENT.blendPixelColor(start + j, color, 128); SEGMENT.blendPixelColor(start + j, color, 128);
} }
@ -4130,7 +4130,7 @@ uint16_t mode_dancing_shadows(void)
break; break;
case SPOT_TYPE_3X_DOT: case SPOT_TYPE_3X_DOT:
for (uint8_t j = 0; j < spotlights[i].width; j += 3) { for (size_t j = 0; j < spotlights[i].width; j += 3) {
if ((start + j) >= 0 && (start + j) < SEGLEN) { if ((start + j) >= 0 && (start + j) < SEGLEN) {
SEGMENT.blendPixelColor(start + j, color, 128); SEGMENT.blendPixelColor(start + j, color, 128);
} }
@ -4138,7 +4138,7 @@ uint16_t mode_dancing_shadows(void)
break; break;
case SPOT_TYPE_4X_DOT: case SPOT_TYPE_4X_DOT:
for (uint8_t j = 0; j < spotlights[i].width; j += 4) { for (size_t j = 0; j < spotlights[i].width; j += 4) {
if ((start + j) >= 0 && (start + j) < SEGLEN) { if ((start + j) >= 0 && (start + j) < SEGLEN) {
SEGMENT.blendPixelColor(start + j, color, 128); SEGMENT.blendPixelColor(start + j, color, 128);
} }
@ -4580,13 +4580,13 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma
SEGMENT.fadeToBlackBy(leds, 16 + (SEGMENT.speed>>3)); // create fading trails SEGMENT.fadeToBlackBy(leds, 16 + (SEGMENT.speed>>3)); // create fading trails
float t = (float)(millis())/128; // timebase float t = (float)(millis())/128; // timebase
// outer stars // outer stars
for (byte i = 0; i < 8; i++) { for (size_t i = 0; i < 8; i++) {
x = beatsin8(SEGMENT.custom1>>3, 0, cols - 1, 0, ((i % 2) ? 128 : 0) + t * i); x = beatsin8(SEGMENT.custom1>>3, 0, cols - 1, 0, ((i % 2) ? 128 : 0) + t * i);
y = beatsin8(SEGMENT.intensity>>3, 0, rows - 1, 0, ((i % 2) ? 192 : 64) + t * i); y = beatsin8(SEGMENT.intensity>>3, 0, rows - 1, 0, ((i % 2) ? 192 : 64) + t * i);
leds[XY(x,y)] += CHSV(i*32, 255, 255); leds[XY(x,y)] += CHSV(i*32, 255, 255);
} }
// inner stars // inner stars
for (byte i = 0; i < 4; i++) { for (size_t i = 0; i < 4; i++) {
x = beatsin8(SEGMENT.custom2>>3, cols/4, cols - 1 - cols/4, 0, ((i % 2) ? 128 : 0) + t * i); x = beatsin8(SEGMENT.custom2>>3, cols/4, cols - 1 - cols/4, 0, ((i % 2) ? 128 : 0) + t * i);
y = beatsin8(SEGMENT.custom3>>3, rows/4, rows - 1 - rows/4, 0, ((i % 2) ? 192 : 64) + t * i); y = beatsin8(SEGMENT.custom3>>3, rows/4, rows - 1 - rows/4, 0, ((i % 2) ? 192 : 64) + t * i);
leds[XY(x,y)] += CHSV(i*32, 255, 255); leds[XY(x,y)] += CHSV(i*32, 255, 255);
@ -4629,7 +4629,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so
SEGENV.aux0++; // hue SEGENV.aux0++; // hue
SEGMENT.fadeToBlackBy(leds, 40); SEGMENT.fadeToBlackBy(leds, 40);
for (byte i = 0; i < numLines; i++) { for (size_t i = 0; i < numLines; i++) {
byte x1 = beatsin8(2 + SEGMENT.speed/16, 0, (cols - 1)); byte x1 = beatsin8(2 + SEGMENT.speed/16, 0, (cols - 1));
byte x2 = beatsin8(1 + SEGMENT.speed/16, 0, (cols - 1)); byte x2 = beatsin8(1 + SEGMENT.speed/16, 0, (cols - 1));
byte y1 = beatsin8(5 + SEGMENT.speed/16, 0, (rows - 1), 0, i * 24); byte y1 = beatsin8(5 + SEGMENT.speed/16, 0, (rows - 1), 0, i * 24);
@ -4640,7 +4640,7 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so
byte ysteps = abs8(x2 - y2) + 1; byte ysteps = abs8(x2 - y2) + 1;
byte steps = xsteps >= ysteps ? xsteps : ysteps; byte steps = xsteps >= ysteps ? xsteps : ysteps;
for (byte i = 1; i <= steps; i++) { for (size_t i = 1; i <= steps; i++) {
byte dx = lerp8by8(x1, y1, i * 255 / steps); byte dx = lerp8by8(x1, y1, i * 255 / steps);
byte dy = lerp8by8(x2, y2, i * 255 / steps); byte dy = lerp8by8(x2, y2, i * 255 / steps);
int index = XY(dx, dy); int index = XY(dx, dy);
@ -4721,7 +4721,7 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma
if ((i + ms / 8) & 3) { if ((i + ms / 8) & 3) {
x = x / 2; x1 = x1 / 2; x = x / 2; x1 = x1 / 2;
byte steps = abs8(x - x1) + 1; byte steps = abs8(x - x1) + 1;
for (byte k = 1; k <= steps; k++) { for (size_t k = 1; k <= steps; k++) {
byte dx = lerp8by8(x, x1, k * 255 / steps); byte dx = lerp8by8(x, x1, k * 255 / steps);
uint16_t index = XY(dx, i); uint16_t index = XY(dx, i);
leds[index] += ColorFromPalette(strip.currentPalette, SEGENV.aux0, 255, LINEARBLEND); leds[index] += ColorFromPalette(strip.currentPalette, SEGENV.aux0, 255, LINEARBLEND);
@ -4826,7 +4826,7 @@ uint16_t mode_2DFrizzles(void) { // By: Stepko https://editor.so
if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black); if (SEGENV.call == 0) SEGMENT.fill_solid(leds, CRGB::Black);
SEGMENT.fadeToBlackBy(leds, 16); SEGMENT.fadeToBlackBy(leds, 16);
for (byte i = 8; i > 0; i--) { for (size_t i = 8; i > 0; i--) {
leds[XY(beatsin8(SEGMENT.speed/8 + i, 0, cols - 1), beatsin8(SEGMENT.intensity/8 - i, 0, rows - 1))] += ColorFromPalette(strip.currentPalette, beatsin8(12, 0, 255), 255, LINEARBLEND); leds[XY(beatsin8(SEGMENT.speed/8 + i, 0, cols - 1), beatsin8(SEGMENT.intensity/8 - i, 0, rows - 1))] += ColorFromPalette(strip.currentPalette, beatsin8(12, 0, 255), 255, LINEARBLEND);
} }
SEGMENT.blur2d(leds, 16); SEGMENT.blur2d(leds, 16);
@ -5577,7 +5577,7 @@ uint16_t mode_2Dspaceships(void) { //// Space ships by stepko (c)05.02.21 [ht
SEGMENT.fadeToBlackBy(leds, map(SEGMENT.speed, 0, 255, 248, 16)); SEGMENT.fadeToBlackBy(leds, map(SEGMENT.speed, 0, 255, 248, 16));
SEGMENT.move(SEGENV.aux0, 1, leds); SEGMENT.move(SEGENV.aux0, 1, leds);
for (byte i = 0; i < 8; i++) { for (size_t i = 0; i < 8; i++) {
byte x = beatsin8(12 + i, 2, cols - 3); byte x = beatsin8(12 + i, 2, cols - 3);
byte y = beatsin8(15 + i, 2, rows - 3); byte y = beatsin8(15 + i, 2, rows - 3);
CRGB color = ColorFromPalette(strip.currentPalette, beatsin8(12 + i, 0, 255), 255); CRGB color = ColorFromPalette(strip.currentPalette, beatsin8(12 + i, 0, 255), 255);
@ -5633,7 +5633,7 @@ uint16_t mode_2Dcrazybees(void) {
if (SEGENV.call == 0) { if (SEGENV.call == 0) {
SEGMENT.fill_solid(leds, CRGB::Black); SEGMENT.fill_solid(leds, CRGB::Black);
for (byte i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
bee[i].posX = random8(0, cols); bee[i].posX = random8(0, cols);
bee[i].posY = random8(0, rows); bee[i].posY = random8(0, rows);
bee[i].aimed(cols, rows); bee[i].aimed(cols, rows);
@ -5645,7 +5645,7 @@ uint16_t mode_2Dcrazybees(void) {
SEGMENT.fadeToBlackBy(leds, 32); SEGMENT.fadeToBlackBy(leds, 32);
for (byte i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
leds[XY(bee[i].aimX + 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255); leds[XY(bee[i].aimX + 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255);
leds[XY(bee[i].aimX, bee[i].aimY + 1)] += CHSV(bee[i].hue, 255, 255); leds[XY(bee[i].aimX, bee[i].aimY + 1)] += CHSV(bee[i].hue, 255, 255);
leds[XY(bee[i].aimX - 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255); leds[XY(bee[i].aimX - 1, bee[i].aimY)] += CHSV(bee[i].hue, 255, 255);
@ -5714,7 +5714,7 @@ uint16_t mode_2Dghostrider(void) {
lighter->Vspeed = 5; lighter->Vspeed = 5;
lighter->gPosX = (cols/2) * 10; lighter->gPosX = (cols/2) * 10;
lighter->gPosY = (rows/2) * 10; lighter->gPosY = (rows/2) * 10;
for (byte i = 0; i < maxLighters; i++) { for (size_t i = 0; i < maxLighters; i++) {
lighter->lightersPosX[i] = lighter->gPosX; lighter->lightersPosX[i] = lighter->gPosX;
lighter->lightersPosY[i] = lighter->gPosY + i; lighter->lightersPosY[i] = lighter->gPosY + i;
lighter->time[i] = i * 2; lighter->time[i] = i * 2;
@ -5736,7 +5736,7 @@ uint16_t mode_2Dghostrider(void) {
if (lighter->gPosX > (cols - 1) * 10) lighter->gPosX = 0; if (lighter->gPosX > (cols - 1) * 10) lighter->gPosX = 0;
if (lighter->gPosY < 0) lighter->gPosY = (rows - 1) * 10; if (lighter->gPosY < 0) lighter->gPosY = (rows - 1) * 10;
if (lighter->gPosY > (rows - 1) * 10) lighter->gPosY = 0; if (lighter->gPosY > (rows - 1) * 10) lighter->gPosY = 0;
for (byte i = 0; i < maxLighters; i++) { for (size_t i = 0; i < maxLighters; i++) {
lighter->time[i] += random8(5, 20); lighter->time[i] += random8(5, 20);
if (lighter->time[i] >= 255 || if (lighter->time[i] >= 255 ||
(lighter->lightersPosX[i] <= 0) || (lighter->lightersPosX[i] <= 0) ||
@ -5796,7 +5796,7 @@ uint16_t mode_2Dfloatingblobs(void) {
SEGENV.aux0 = cols; SEGENV.aux0 = cols;
SEGENV.aux1 = rows; SEGENV.aux1 = rows;
SEGMENT.fill_solid(leds, CRGB::Black); SEGMENT.fill_solid(leds, CRGB::Black);
for (byte i = 0; i < MAX_BLOBS; i++) { for (size_t i = 0; i < MAX_BLOBS; i++) {
blob->r[i] = cols>15 ? random8(1, cols/8.f) : 1; blob->r[i] = cols>15 ? random8(1, cols/8.f) : 1;
blob->sX[i] = (float) random8(3, cols) / (float)(256 - SEGMENT.speed); // speed x blob->sX[i] = (float) random8(3, cols) / (float)(256 - SEGMENT.speed); // speed x
blob->sY[i] = (float) random8(3, rows) / (float)(256 - SEGMENT.speed); // speed y blob->sY[i] = (float) random8(3, rows) / (float)(256 - SEGMENT.speed); // speed y
@ -5812,7 +5812,7 @@ uint16_t mode_2Dfloatingblobs(void) {
SEGMENT.fadeToBlackBy(leds, 20); SEGMENT.fadeToBlackBy(leds, 20);
// Bounce balls around // Bounce balls around
for (byte i = 0; i < Amount; i++) { for (size_t i = 0; i < Amount; i++) {
if (SEGENV.step < millis()) blob->color[i] = add8(blob->color[i], 4); // slowly change color if (SEGENV.step < millis()) blob->color[i] = add8(blob->color[i], 4); // slowly change color
// change radius if needed // change radius if needed
if (blob->grow[i]) { if (blob->grow[i]) {
@ -5943,7 +5943,7 @@ uint16_t mode_2Ddriftrose(void) {
} }
SEGMENT.fadeToBlackBy(leds, 32+(SEGMENT.speed>>3)); SEGMENT.fadeToBlackBy(leds, 32+(SEGMENT.speed>>3));
for (byte i = 1; i < 37; i++) { for (size_t i = 1; i < 37; i++) {
uint32_t x = (CX + (sin_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f; uint32_t x = (CX + (sin_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f;
uint32_t y = (CY + (cos_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f; uint32_t y = (CY + (cos_t(radians(i * 10)) * (beatsin8(i, 0, L*2)-L))) * 255.f;
SEGMENT.wu_pixel(leds, x, y, CHSV(i * 10, 255, 255)); SEGMENT.wu_pixel(leds, x, y, CHSV(i * 10, 255, 255));
@ -6578,7 +6578,7 @@ uint16_t mode_juggles(void) { // Juggles. By Andrew Tuline.
SEGMENT.fade_out(224); SEGMENT.fade_out(224);
uint16_t my_sampleAgc = fmax(fmin(sampleAgc, 255.0), 0); uint16_t my_sampleAgc = fmax(fmin(sampleAgc, 255.0), 0);
for (uint8_t i=0; i<SEGMENT.intensity/32+1; i++) { for (size_t i=0; i<SEGMENT.intensity/32+1; i++) {
SEGMENT.setPixelColor(beatsin16(SEGMENT.speed/4+i*2,0,SEGLEN-1), color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(millis()/4+i*2, false, PALETTE_SOLID_WRAP, 0), my_sampleAgc)); SEGMENT.setPixelColor(beatsin16(SEGMENT.speed/4+i*2,0,SEGLEN-1), color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(millis()/4+i*2, false, PALETTE_SOLID_WRAP, 0), my_sampleAgc));
} }

View File

@ -455,7 +455,9 @@ typedef struct Segment {
_capabilities(0), _capabilities(0),
_dataLen(0) _dataLen(0)
//_t(nullptr) //_t(nullptr)
{} {
refreshLightCapabilities();
}
Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) { Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) {
startY = sStartY; startY = sStartY;

View File

@ -401,7 +401,7 @@ uint8_t Segment::differs(Segment& b) {
} }
void Segment::refreshLightCapabilities() { void Segment::refreshLightCapabilities() {
uint8_t capabilities = 0; uint8_t capabilities = 0x01;
for (uint8_t b = 0; b < busses.getNumBusses(); b++) { for (uint8_t b = 0; b < busses.getNumBusses(); b++) {
Bus *bus = busses.getBus(b); Bus *bus = busses.getBus(b);
@ -411,7 +411,7 @@ void Segment::refreshLightCapabilities() {
if (bus->getStart() + bus->getLength() <= start) continue; if (bus->getStart() + bus->getLength() <= start) continue;
uint8_t type = bus->getType(); uint8_t type = bus->getType();
if (type != TYPE_ANALOG_1CH && (cctFromRgb || type != TYPE_ANALOG_2CH)) capabilities |= 0x01; // segment supports RGB (full color) if (type == TYPE_ANALOG_1CH || (!cctFromRgb && type == TYPE_ANALOG_2CH)) capabilities &= 0xFE; // does not support RGB
if (bus->isRgbw()) capabilities |= 0x02; // segment supports white channel if (bus->isRgbw()) capabilities |= 0x02; // segment supports white channel
if (!cctFromRgb) { if (!cctFromRgb) {
switch (type) { switch (type) {
@ -1002,7 +1002,7 @@ uint8_t WS2812FX::getLastActiveSegmentId(void) {
uint8_t WS2812FX::getActiveSegmentsNum(void) { uint8_t WS2812FX::getActiveSegmentsNum(void) {
uint8_t c = 0; uint8_t c = 0;
// for (uint8_t i = 0; i < getMaxSegments(); i++) { // for (uint8_t i = 0; i < getMaxSegments(); i++) {
for (int i = 0; i < _segments.size(); i++) { for (size_t i = 0; i < _segments.size(); i++) {
if (_segments[i].isActive()) c++; if (_segments[i].isActive()) c++;
} }
return c; return c;
@ -1180,15 +1180,16 @@ void WS2812FX::makeAutoSegments(bool forceReset) {
if (isMatrix) { if (isMatrix) {
#ifndef WLED_DISABLE_2D #ifndef WLED_DISABLE_2D
// only create 1 2D segment // only create 1 2D segment
if (forceReset || getActiveSegmentsNum() == 0) resetSegments(); // initialises 1 segment if (forceReset || getSegmentsNum() == 0) resetSegments(); // initialises 1 segment
else if (getActiveSegmentsNum() == 1) { else if (getActiveSegmentsNum() == 1) {
_segments[0].start = 0; size_t i = getLastActiveSegmentId();
_segments[0].stop = matrixWidth; _segments[i].start = 0;
_segments[0].startY = 0; _segments[i].stop = matrixWidth;
_segments[0].stopY = matrixHeight; _segments[i].startY = 0;
_segments[0].grouping = 1; _segments[i].stopY = matrixHeight;
_segments[0].spacing = 0; _segments[i].grouping = 1;
_mainSegment = 0; _segments[i].spacing = 0;
_mainSegment = i;
} }
#endif #endif
} else if (autoSegments) { //make one segment per bus } else if (autoSegments) { //make one segment per bus
@ -1224,11 +1225,12 @@ void WS2812FX::makeAutoSegments(bool forceReset) {
// } // }
_mainSegment = 0; _mainSegment = 0;
} else { } else {
if (forceReset || getActiveSegmentsNum() == 0) resetSegments(); if (forceReset || getSegmentsNum() == 0) resetSegments();
//expand the main seg to the entire length, but only if there are no other segments, or reset is forced //expand the main seg to the entire length, but only if there are no other segments, or reset is forced
else if (getActiveSegmentsNum() == 1) { else if (getActiveSegmentsNum() == 1) {
_segments[0].start = 0; size_t i = getLastActiveSegmentId();
_segments[0].stop = _length; _segments[i].start = 0;
_segments[i].stop = _length;
_mainSegment = 0; _mainSegment = 0;
} }
} }
@ -1238,7 +1240,7 @@ void WS2812FX::makeAutoSegments(bool forceReset) {
void WS2812FX::fixInvalidSegments() { void WS2812FX::fixInvalidSegments() {
//make sure no segment is longer than total (sanity check) //make sure no segment is longer than total (sanity check)
for (int i = _segments.size()-1; i > 0; i--) { for (int i = getSegmentsNum()-1; i > 0; i--) {
if (_segments[i].start >= _length) { _segments.erase(_segments.begin()+i); continue; } if (_segments[i].start >= _length) { _segments.erase(_segments.begin()+i); continue; }
if (_segments[i].stop > _length) _segments[i].stop = _length; if (_segments[i].stop > _length) _segments[i].stop = _length;
// this is always called as the last step after finalizeInit(), update covered bus types // this is always called as the last step after finalizeInit(), update covered bus types
@ -1321,7 +1323,7 @@ void WS2812FX::load_gradient_palette(uint8_t index)
if (!pal.isNull() && pal.size()>7) { // not an empty palette (at least 2 entries) if (!pal.isNull() && pal.size()>7) { // not an empty palette (at least 2 entries)
size_t palSize = MIN(pal.size(), 72); size_t palSize = MIN(pal.size(), 72);
palSize -= palSize % 4; // make sure size is multiple of 4 palSize -= palSize % 4; // make sure size is multiple of 4
for (int i=0; i<palSize && pal[i].as<int>()<256; i+=4) { for (size_t i=0; i<palSize && pal[i].as<int>()<256; i+=4) {
tcp[ i ] = (uint8_t) pal[ i ].as<int>(); // index tcp[ i ] = (uint8_t) pal[ i ].as<int>(); // index
tcp[i+1] = (uint8_t) pal[i+1].as<int>(); // R tcp[i+1] = (uint8_t) pal[i+1].as<int>(); // R
tcp[i+2] = (uint8_t) pal[i+2].as<int>(); // G tcp[i+2] = (uint8_t) pal[i+2].as<int>(); // G

View File

@ -39,7 +39,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
elem.remove("rpt"); // remove for recursive call elem.remove("rpt"); // remove for recursive call
elem.remove("n"); // remove for recursive call elem.remove("n"); // remove for recursive call
uint16_t len = stop - start; uint16_t len = stop - start;
for (byte i=id+1; i<strip.getMaxSegments(); i++) { for (size_t i=id+1; i<strip.getMaxSegments(); i++) {
start = start + len; start = start + len;
if (start >= strip.getLengthTotal()) break; if (start >= strip.getLengthTotal()) break;
//TODO: add support for 2D //TODO: add support for 2D
@ -112,7 +112,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
JsonArray colarr = elem["col"]; JsonArray colarr = elem["col"];
if (!colarr.isNull()) if (!colarr.isNull())
{ {
for (uint8_t i = 0; i < 3; i++) for (size_t i = 0; i < 3; i++)
{ {
int rgbw[] = {0,0,0,0}; int rgbw[] = {0,0,0,0};
bool colValid = false; bool colValid = false;
@ -129,7 +129,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
} else { //HEX string, e.g. "FFAA00" } else { //HEX string, e.g. "FFAA00"
colValid = colorFromHexString(brgbw, hexCol); colValid = colorFromHexString(brgbw, hexCol);
} }
for (uint8_t c = 0; c < 4; c++) rgbw[c] = brgbw[c]; for (size_t c = 0; c < 4; c++) rgbw[c] = brgbw[c];
} else { //Array of ints (RGB or RGBW color), e.g. [255,160,0] } else { //Array of ints (RGB or RGBW color), e.g. [255,160,0]
byte sz = colX.size(); byte sz = colX.size();
if (sz == 0) continue; //do nothing on empty array if (sz == 0) continue; //do nothing on empty array
@ -199,7 +199,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
uint16_t start = 0, stop = 0; uint16_t start = 0, stop = 0;
byte set = 0; //0 nothing set, 1 start set, 2 range set byte set = 0; //0 nothing set, 1 start set, 2 range set
for (uint16_t i = 0; i < iarr.size(); i++) { for (size_t i = 0; i < iarr.size(); i++) {
if(iarr[i].is<JsonInteger>()) { if(iarr[i].is<JsonInteger>()) {
if (!set) { if (!set) {
start = iarr[i]; start = iarr[i];
@ -218,12 +218,12 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
byte brgbw[] = {0,0,0,0}; byte brgbw[] = {0,0,0,0};
const char* hexCol = iarr[i]; const char* hexCol = iarr[i];
if (colorFromHexString(brgbw, hexCol)) { if (colorFromHexString(brgbw, hexCol)) {
for (uint8_t c = 0; c < 4; c++) rgbw[c] = brgbw[c]; for (size_t c = 0; c < 4; c++) rgbw[c] = brgbw[c];
} }
} }
if (set < 2) stop = start + 1; if (set < 2) stop = start + 1;
for (uint16_t i = start; i < stop; i++) { for (int i = start; i < stop; i++) {
if (strip.gammaCorrectCol) { if (strip.gammaCorrectCol) {
seg.setPixelColor(i, strip.gamma8(rgbw[0]), strip.gamma8(rgbw[1]), strip.gamma8(rgbw[2]), strip.gamma8(rgbw[3])); seg.setPixelColor(i, strip.gamma8(rgbw[0]), strip.gamma8(rgbw[1]), strip.gamma8(rgbw[2]), strip.gamma8(rgbw[3]));
} else { } else {
@ -257,7 +257,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
if (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't') toggleOnOff(); if (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't') toggleOnOff();
if (bri && !onBefore) { // unfreeze all segments when turning on if (bri && !onBefore) { // unfreeze all segments when turning on
for (uint8_t s=0; s < strip.getSegmentsNum(); s++) { for (size_t s=0; s < strip.getSegmentsNum(); s++) {
strip.getSegment(s).setOption(SEG_OPTION_FREEZE, false); strip.getSegment(s).setOption(SEG_OPTION_FREEZE, false);
} }
if (realtimeMode && !realtimeOverride && useMainSegmentOnly) { // keep live segment frozen if live if (realtimeMode && !realtimeOverride && useMainSegmentOnly) { // keep live segment frozen if live
@ -335,7 +335,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
if (id < 0) { if (id < 0) {
//apply all selected segments //apply all selected segments
//bool didSet = false; //bool didSet = false;
for (byte s = 0; s < strip.getSegmentsNum(); s++) { for (size_t s = 0; s < strip.getSegmentsNum(); s++) {
Segment &sg = strip.getSegment(s); Segment &sg = strip.getSegment(s);
if (sg.isSelected()) { if (sg.isSelected()) {
deserializeSegment(segVar, s, presetId); deserializeSegment(segVar, s, presetId);
@ -429,7 +429,7 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b
// this will reduce RAM footprint from ~300 bytes to 84 bytes per segment // this will reduce RAM footprint from ~300 bytes to 84 bytes per segment
char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255) char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255)
const char *format = strip.hasWhiteChannel() ? PSTR("[%u,%u,%u,%u]") : PSTR("[%u,%u,%u]"); const char *format = strip.hasWhiteChannel() ? PSTR("[%u,%u,%u,%u]") : PSTR("[%u,%u,%u]");
for (uint8_t i = 0; i < 3; i++) for (size_t i = 0; i < 3; i++)
{ {
byte segcol[4]; byte* c = segcol; byte segcol[4]; byte* c = segcol;
segcol[0] = R(seg.colors[i]); segcol[0] = R(seg.colors[i]);
@ -499,7 +499,7 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme
bool selectedSegmentsOnly = root[F("sc")] | false; bool selectedSegmentsOnly = root[F("sc")] | false;
JsonArray seg = root.createNestedArray("seg"); JsonArray seg = root.createNestedArray("seg");
for (byte s = 0; s < strip.getMaxSegments(); s++) { for (size_t s = 0; s < strip.getMaxSegments(); s++) {
if (s >= strip.getSegmentsNum()) { if (s >= strip.getSegmentsNum()) {
if (forPreset && segmentBounds) { //disable segments not part of preset if (forPreset && segmentBounds) { //disable segments not part of preset
JsonObject seg0 = seg.createNestedObject(); JsonObject seg0 = seg.createNestedObject();
@ -545,8 +545,9 @@ void serializeInfo(JsonObject root)
uint8_t totalLC = 0; uint8_t totalLC = 0;
JsonArray lcarr = leds.createNestedArray(F("seglc")); JsonArray lcarr = leds.createNestedArray(F("seglc"));
uint8_t nSegs = strip.getLastActiveSegmentId(); size_t nSegs = strip.getSegmentsNum();
for (byte s = 0; s <= nSegs; s++) { for (size_t s = 0; s < nSegs; s++) {
if (!strip.getSegment(s).isActive()) continue;
uint8_t lc = strip.getSegment(s).getLightCapabilities(); uint8_t lc = strip.getSegment(s).getLightCapabilities();
totalLC |= lc; totalLC |= lc;
lcarr.add(lc); lcarr.add(lc);
@ -594,7 +595,7 @@ void serializeInfo(JsonObject root)
root[F("palcount")] = strip.getPaletteCount(); root[F("palcount")] = strip.getPaletteCount();
JsonArray ledmaps = root.createNestedArray(F("maps")); JsonArray ledmaps = root.createNestedArray(F("maps"));
for (uint8_t i=0; i<10; i++) { for (size_t i=0; i<10; i++) {
char fileName[16]; char fileName[16];
strcpy_P(fileName, PSTR("/ledmap")); strcpy_P(fileName, PSTR("/ledmap"));
if (i) sprintf(fileName +7, "%d", i); if (i) sprintf(fileName +7, "%d", i);
@ -973,7 +974,7 @@ bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient)
obuf = buffer; obuf = buffer;
olen = 9; olen = 9;
for (uint16_t i= 0; i < used; i += n) for (size_t i= 0; i < used; i += n)
{ {
uint32_t c = strip.getPixelColor(i); uint32_t c = strip.getPixelColor(i);
uint8_t r = qadd8(W(c), R(c)); //add white channel to RGB channels as a simple RGBW -> RGB map uint8_t r = qadd8(W(c), R(c)); //add white channel to RGB channels as a simple RGBW -> RGB map

View File

@ -91,8 +91,8 @@ void notify(byte callMode, bool followUp)
udpOut[39] = strip.getActiveSegmentsNum(); udpOut[39] = strip.getActiveSegmentsNum();
udpOut[40] = UDP_SEG_SIZE; //size of each loop iteration (one segment) udpOut[40] = UDP_SEG_SIZE; //size of each loop iteration (one segment)
int s = 0; size_t s = 0, nsegs = strip.getSegmentsNum();
for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) { for (size_t i = 0; i < nsegs; i++) {
Segment &selseg = strip.getSegment(i); Segment &selseg = strip.getSegment(i);
if (!selseg.isActive()) continue; if (!selseg.isActive()) continue;
uint16_t ofs = 41 + s*UDP_SEG_SIZE; //start of segment offset byte uint16_t ofs = 41 + s*UDP_SEG_SIZE; //start of segment offset byte
@ -155,10 +155,10 @@ void realtimeLock(uint32_t timeoutMs, byte md)
stop = strip.getLengthTotal(); stop = strip.getLengthTotal();
} }
// clear strip/segment // clear strip/segment
for (uint16_t i = start; i < stop; i++) strip.setPixelColor(i,0,0,0,0); for (size_t i = start; i < stop; i++) strip.setPixelColor(i,0,0,0,0);
// if WLED was off and using main segment only, freeze non-main segments so they stay off // if WLED was off and using main segment only, freeze non-main segments so they stay off
if (useMainSegmentOnly && bri == 0) { if (useMainSegmentOnly && bri == 0) {
for (uint8_t s=0; s < strip.getSegmentsNum(); s++) { for (size_t s=0; s < strip.getSegmentsNum(); s++) {
strip.getSegment(s).setOption(SEG_OPTION_FREEZE, true); strip.getSegment(s).setOption(SEG_OPTION_FREEZE, true);
} }
} }
@ -224,7 +224,7 @@ void handleNotifications()
if (!udpConnected) return; if (!udpConnected) return;
bool isSupp = false; bool isSupp = false;
uint16_t packetSize = notifierUdp.parsePacket(); size_t packetSize = notifierUdp.parsePacket();
if (!packetSize && udp2Connected) { if (!packetSize && udp2Connected) {
packetSize = notifier2Udp.parsePacket(); packetSize = notifier2Udp.parsePacket();
isSupp = true; isSupp = true;
@ -244,7 +244,7 @@ void handleNotifications()
if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) return; if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) return;
uint16_t id = 0; uint16_t id = 0;
uint16_t totalLen = strip.getLengthTotal(); uint16_t totalLen = strip.getLengthTotal();
for (uint16_t i = 0; i < packetSize -2; i += 3) for (size_t i = 0; i < packetSize -2; i += 3)
{ {
setRealtimePixel(id, lbuf[i], lbuf[i+1], lbuf[i+2], 0); setRealtimePixel(id, lbuf[i], lbuf[i+1], lbuf[i+2], 0);
id++; if (id >= totalLen) break; id++; if (id >= totalLen) break;
@ -278,7 +278,7 @@ void handleNotifications()
} }
if (it != Nodes.end()) { if (it != Nodes.end()) {
for (byte x = 0; x < 4; x++) { for (size_t x = 0; x < 4; x++) {
it->second.ip[x] = udpIn[x + 2]; it->second.ip[x] = udpIn[x + 2];
} }
it->second.age = 0; // reset 'age counter' it->second.age = 0; // reset 'age counter'
@ -290,7 +290,7 @@ void handleNotifications()
it->second.nodeType = udpIn[38]; it->second.nodeType = udpIn[38];
uint32_t build = 0; uint32_t build = 0;
if (len >= 44) if (len >= 44)
for (byte i=0; i<sizeof(uint32_t); i++) for (size_t i=0; i<sizeof(uint32_t); i++)
build |= udpIn[40+i]<<(8*i); build |= udpIn[40+i]<<(8*i);
it->second.build = build; it->second.build = build;
} }
@ -342,7 +342,7 @@ void handleNotifications()
if (applyEffects && currentPlaylist >= 0) unloadPlaylist(); if (applyEffects && currentPlaylist >= 0) unloadPlaylist();
if (version > 10 && (receiveSegmentOptions || receiveSegmentBounds)) { if (version > 10 && (receiveSegmentOptions || receiveSegmentBounds)) {
uint8_t numSrcSegs = udpIn[39]; uint8_t numSrcSegs = udpIn[39];
for (uint8_t i = 0; i < numSrcSegs; i++) { for (size_t i = 0; i < numSrcSegs; i++) {
uint16_t ofs = 41 + i*udpIn[40]; //start of segment offset byte uint16_t ofs = 41 + i*udpIn[40]; //start of segment offset byte
uint8_t id = udpIn[0 +ofs]; uint8_t id = udpIn[0 +ofs];
if (id > strip.getSegmentsNum()) break; if (id > strip.getSegmentsNum()) break;
@ -354,7 +354,7 @@ void handleNotifications()
strip.setSegment(id, start, stop, selseg.grouping, selseg.spacing, offset); strip.setSegment(id, start, stop, selseg.grouping, selseg.spacing, offset);
continue; continue;
} }
for (uint8_t j = 0; j<4; j++) selseg.setOption(j, (udpIn[9 +ofs] >> j) & 0x01); //only take into account mirrored, selected, on, reversed for (size_t j = 0; j<4; j++) selseg.setOption(j, (udpIn[9 +ofs] >> j) & 0x01); //only take into account mirrored, selected, on, reversed
selseg.setOpacity(udpIn[10+ofs]); selseg.setOpacity(udpIn[10+ofs]);
if (applyEffects) { if (applyEffects) {
strip.setMode(id, udpIn[11+ofs]); strip.setMode(id, udpIn[11+ofs]);
@ -380,7 +380,7 @@ void handleNotifications()
// simple effect sync, applies to all selected segments // simple effect sync, applies to all selected segments
if (applyEffects && (version < 11 || !receiveSegmentOptions)) { if (applyEffects && (version < 11 || !receiveSegmentOptions)) {
for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) { for (size_t i = 0; i < strip.getSegmentsNum(); i++) {
Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
if (udpIn[8] < strip.getModeCount()) strip.setMode(i, udpIn[8]); if (udpIn[8] < strip.getModeCount()) strip.setMode(i, udpIn[8]);
@ -461,7 +461,7 @@ void handleNotifications()
uint16_t id = (tpmPayloadFrameSize/3)*(packetNum-1); //start LED uint16_t id = (tpmPayloadFrameSize/3)*(packetNum-1); //start LED
uint16_t totalLen = strip.getLengthTotal(); uint16_t totalLen = strip.getLengthTotal();
for (uint16_t i = 6; i < tpmPayloadFrameSize + 4; i += 3) for (size_t i = 6; i < tpmPayloadFrameSize + 4U; i += 3)
{ {
if (id < totalLen) if (id < totalLen)
{ {
@ -497,14 +497,14 @@ void handleNotifications()
uint16_t totalLen = strip.getLengthTotal(); uint16_t totalLen = strip.getLengthTotal();
if (udpIn[0] == 1) //warls if (udpIn[0] == 1) //warls
{ {
for (uint16_t i = 2; i < packetSize -3; i += 4) for (size_t i = 2; i < packetSize -3; i += 4)
{ {
setRealtimePixel(udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3], 0); setRealtimePixel(udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3], 0);
} }
} else if (udpIn[0] == 2) //drgb } else if (udpIn[0] == 2) //drgb
{ {
uint16_t id = 0; uint16_t id = 0;
for (uint16_t i = 2; i < packetSize -2; i += 3) for (size_t i = 2; i < packetSize -2; i += 3)
{ {
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0); setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
@ -513,7 +513,7 @@ void handleNotifications()
} else if (udpIn[0] == 3) //drgbw } else if (udpIn[0] == 3) //drgbw
{ {
uint16_t id = 0; uint16_t id = 0;
for (uint16_t i = 2; i < packetSize -3; i += 4) for (size_t i = 2; i < packetSize -3; i += 4)
{ {
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]); setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
@ -522,7 +522,7 @@ void handleNotifications()
} else if (udpIn[0] == 4) //dnrgb } else if (udpIn[0] == 4) //dnrgb
{ {
uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00); uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00);
for (uint16_t i = 4; i < packetSize -2; i += 3) for (size_t i = 4; i < packetSize -2; i += 3)
{ {
if (id >= totalLen) break; if (id >= totalLen) break;
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0); setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], 0);
@ -531,7 +531,7 @@ void handleNotifications()
} else if (udpIn[0] == 5) //dnrgbw } else if (udpIn[0] == 5) //dnrgbw
{ {
uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00); uint16_t id = ((udpIn[3] << 0) & 0xFF) + ((udpIn[2] << 8) & 0xFF00);
for (uint16_t i = 4; i < packetSize -2; i += 4) for (size_t i = 4; i < packetSize -2; i += 4)
{ {
if (id >= totalLen) break; if (id >= totalLen) break;
setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]); setRealtimePixel(id, udpIn[i], udpIn[i+1], udpIn[i+2], udpIn[i+3]);
@ -621,7 +621,7 @@ void sendSysInfoUDP()
data[0] = 255; data[0] = 255;
data[1] = 1; data[1] = 1;
for (byte x = 0; x < 4; x++) { for (size_t x = 0; x < 4; x++) {
data[x + 2] = ip[x]; data[x + 2] = ip[x];
} }
memcpy((byte *)data + 6, serverDescription, 32); memcpy((byte *)data + 6, serverDescription, 32);
@ -635,7 +635,7 @@ void sendSysInfoUDP()
data[39] = ip[3]; // unit ID == last IP number data[39] = ip[3]; // unit ID == last IP number
uint32_t build = VERSION; uint32_t build = VERSION;
for (byte i=0; i<sizeof(uint32_t); i++) for (size_t i=0; i<sizeof(uint32_t); i++)
data[40+i] = (build>>(8*i)) & 0xFF; data[40+i] = (build>>(8*i)) & 0xFF;
IPAddress broadcastIP(255, 255, 255, 255); IPAddress broadcastIP(255, 255, 255, 255);
@ -687,15 +687,15 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8
case 0: // DDP case 0: // DDP
{ {
// calculate the number of UDP packets we need to send // calculate the number of UDP packets we need to send
uint16_t channelCount = length * 3; // 1 channel for every R,G,B value size_t channelCount = length * 3; // 1 channel for every R,G,B value
uint16_t packetCount = ((channelCount-1) / DDP_CHANNELS_PER_PACKET) +1; size_t packetCount = ((channelCount-1) / DDP_CHANNELS_PER_PACKET) +1;
// there are 3 channels per RGB pixel // there are 3 channels per RGB pixel
uint32_t channel = 0; // TODO: allow specifying the start channel uint32_t channel = 0; // TODO: allow specifying the start channel
// the current position in the buffer // the current position in the buffer
uint16_t bufferOffset = 0; size_t bufferOffset = 0;
for (uint16_t currentPacket = 0; currentPacket < packetCount; currentPacket++) { for (size_t currentPacket = 0; currentPacket < packetCount; currentPacket++) {
if (sequenceNumber > 15) sequenceNumber = 0; if (sequenceNumber > 15) sequenceNumber = 0;
if (!ddpUdp.beginPacket(client, DDP_DEFAULT_PORT)) { // port defined in ESPAsyncE131.h if (!ddpUdp.beginPacket(client, DDP_DEFAULT_PORT)) { // port defined in ESPAsyncE131.h
@ -704,10 +704,10 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8
} }
// the amount of data is AFTER the header in the current packet // the amount of data is AFTER the header in the current packet
uint16_t packetSize = DDP_CHANNELS_PER_PACKET; size_t packetSize = DDP_CHANNELS_PER_PACKET;
uint8_t flags = DDP_FLAGS1_VER1; uint8_t flags = DDP_FLAGS1_VER1;
if (currentPacket == (packetCount - 1)) { if (currentPacket == (packetCount - 1U)) {
// last packet, set the push flag // last packet, set the push flag
// TODO: determine if we want to send an empty push packet to each destination after sending the pixel data // TODO: determine if we want to send an empty push packet to each destination after sending the pixel data
flags = DDP_FLAGS1_VER1 | DDP_FLAGS1_PUSH; flags = DDP_FLAGS1_VER1 | DDP_FLAGS1_PUSH;
@ -732,7 +732,7 @@ uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, uint8
// write the colors, the write write(const uint8_t *buffer, size_t size) // write the colors, the write write(const uint8_t *buffer, size_t size)
// function is just a loop internally too // function is just a loop internally too
for (uint16_t i = 0; i < packetSize; i += 3) { for (size_t i = 0; i < packetSize; i += 3) {
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // R ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // R
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // G
ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B ddpUdp.write(scale8(buffer[bufferOffset++], bri)); // B