Skip to content

Commit

Permalink
0.9.48:
Browse files Browse the repository at this point in the history
WS2812FX_DastLED.cpp:
- simplified / optimized "off animation"
- simplified a lot reverse / mirror and blending to LED data
- FIXED: Pride not using all pixels.
httpledstripe_esp.cpp:
- show FPS on Display screen.
  • Loading branch information
tobi01001 committed Feb 26, 2020
1 parent e606147 commit d10b14a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#endif

//#error "check version first"
#define BUILD_VERSION ("LED_Control_0.9.47")
#define BUILD_VERSION ("LED_Control_0.9.48")

#ifndef BUILD_VERSION
#error "We need a SW Version and Build Version!"
Expand Down
77 changes: 43 additions & 34 deletions lib/WS2812FX/WS2812FX_FastLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void WS2812FX::service()
unsigned long now = millis(); // Be aware, millis() rolls over every 49 days

if ((_segment.segments != old_segs) || _segment_runtime.modeinit)
{
{
_segment_runtime.start = 0;
_segment_runtime.length = (LED_COUNT / _segment.segments);
_segment_runtime.stop = _segment_runtime.start + _segment_runtime.length - 1;
Expand Down Expand Up @@ -371,17 +371,18 @@ void WS2812FX::service()
{
SEGMENT_RUNTIME.next_time = now + (uint32_t)(STRIP_DELAY_MICROSEC/1000);
// no need to write data if nothing is shown (safeguard)
bool stillOn = false;

// new version: Will fade rightaway once active led found.
for(uint16_t i = 0; i < LED_COUNT; i++)
{
if(_bleds[i] || leds[i]) stillOn = true;
}
if(stillOn)
{
fadeToBlackBy(_bleds, LED_COUNT, 4);
fadeToBlackBy( leds, LED_COUNT, 4);
FastLED.show();
if(_bleds[i] || leds[i]) {
fadeToBlackBy(_bleds, LED_COUNT, 16);
fadeToBlackBy( leds, LED_COUNT, 16);
FastLED.show();
return;
}
}

}
return;
}
Expand Down Expand Up @@ -425,60 +426,68 @@ void WS2812FX::service()
}
}

// the following constuct looks a bit weired and contains many loops
// but I preferred to not have multiple if - else conditions within a loop
// so depending on the logical combination only one loop is run.
// the inverse loop could be separated but this may affect performance
// so we loop only once.

if (_segment.reverse)
{
CRGB temp;
for (uint16_t i = 0; i <= _segment_runtime.length / 2; i++)
{
temp = leds[i];
leds[i] = leds[_segment_runtime.stop - i];
leds[_segment_runtime.stop - i] = temp;
}
}
// Thanks to some discussions on Github, I do still not use any memmove
// but I relaized that I need to nblend from the calculated frames to the led data.
// this could be simplified within the following nested loop which does now all at once and svaes 2 loops +
// one nblend over the complete strip data....
// as the combination of "mirror" and "reverse" is a bit redundant, this could maybe be simplified as well (later)

for (uint16_t j = 1; j < _segment.segments; j++)
for (uint16_t j = 0; j < _segment.segments; j++)
{
for (uint16_t i = 0; i < _segment_runtime.length; i++)
{
if (_segment.mirror && (j & 0x01))
{
leds[j * _segment_runtime.length + i] = leds[_segment_runtime.stop - i];
if(_segment.reverse)
{
nblend(_bleds[j * _segment_runtime.length + i], leds[i], l_blend);
}
else
{
nblend(_bleds[j * _segment_runtime.length + i], leds[_segment_runtime.stop - i], l_blend);
}
}
else
{
leds[j * _segment_runtime.length + i] = leds[i];
if(_segment.reverse)
{
nblend(_bleds[j * _segment_runtime.length + i], leds[_segment_runtime.stop - i], l_blend);
}
else
{
nblend(_bleds[j * _segment_runtime.length + i], leds[i], l_blend);
}

}
}
}

// Write the data
// the value of 300 microseconds is the average between two service routine calls....
#define FRAME_CALC_WAIT_MICROINTERVAL ((uint32_t)300)
static uint32_t next_show = 0;
uint32_t now_micros = micros();

// if there is time left for another service call, we do not write the led data yet...
if(doShow && ((now_micros - next_show) > ((uint32_t)(STRIP_DELAY_MICROSEC) - FRAME_CALC_WAIT_MICROINTERVAL)))
{
// okay, the time budget is within the remaining (300) microseconds
// we wait until this time is over befor writing the leds
// this should give a wuite stable frame rate...
if(((next_show + FRAME_CALC_WAIT_MICROINTERVAL) < now_micros) )
// && ((now_micros - (next_show + FRAME_CALC_WAIT_MICROINTERVAL)) < FRAME_CALC_WAIT_MICROINTERVAL))
{
while((micros() - (next_show + FRAME_CALC_WAIT_MICROINTERVAL)) < FRAME_CALC_WAIT_MICROINTERVAL);
//delayMicroseconds(now_micros - (next_show + FRAME_CALC_WAIT_MICROINTERVAL));
}

nblend(_bleds, leds, LED_COUNT, l_blend); // Only blend when actually writing the LEDs...
//nblend(_bleds, leds, LED_COUNT, l_blend); // Only blend when actually writing the LEDs...

next_show = now_micros;
// Write the data
FastLED.show();
}


/*
if (_segment.reverse)
{
CRGB temp;
Expand All @@ -489,7 +498,7 @@ void WS2812FX::service()
leds[_segment_runtime.stop - i] = temp;
}
}

*/
EVERY_N_MILLISECONDS(STRIP_MIN_DELAY) //(10)
{
if(_segment.isRunning) fadeToBlackBy(_bleds, LED_COUNT, 1);
Expand Down Expand Up @@ -1161,7 +1170,7 @@ uint16_t WS2812FX::pride(bool glitter = false)
SEGMENT_RUNTIME.modevars.pride.sHue16 += deltams * beatsin88((SEGMENT.beat88 / 5) * 2 + 1, 5, 9);
uint16_t brightnesstheta16 = SEGMENT_RUNTIME.modevars.pride.sPseudotime;

for (uint16_t i = _segment_runtime.start; i < _segment_runtime.stop; i++)
for (uint16_t i = _segment_runtime.start; i < _segment_runtime.length; i++)
{
hue16 += hueinc16;
uint8_t hue8 = hue16 / 256;
Expand All @@ -1181,7 +1190,7 @@ uint16_t WS2812FX::pride(bool glitter = false)
uint16_t pixelnumber = i;
pixelnumber = (_segment_runtime.stop) - pixelnumber;
*/
uint16_t pixelnumber = (_segment_runtime.stop-1) - i;
uint16_t pixelnumber = (_segment_runtime.stop) - i;

nblend(leds[pixelnumber], newcolor, 64);
}
Expand Down
5 changes: 3 additions & 2 deletions src/httpledstripe_esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3145,7 +3145,7 @@ void showDisplay(uint8_t curr_field, fieldtypes *fieldtype)
} */
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 20, "Lamp is:");
display.drawString(0, 20, "FPS:");
display.drawString(0, 30, "Leds on:");
display.drawString(0, 40, "M:");
display.drawString(0, 50, "C:");
Expand All @@ -3163,7 +3163,8 @@ void showDisplay(uint8_t curr_field, fieldtypes *fieldtype)
num_leds_on++;
}
}
display.drawString(127, 20, "ON");
FastLED.getFPS();
display.drawString(127, 20, String(FastLED.getFPS()));
display.drawString(127, 30, String(num_leds_on));
}
else
Expand Down

0 comments on commit d10b14a

Please sign in to comment.