Attempted to improve performance by simplifying pixel lock checks

This commit is contained in:
cschwinne 2017-10-28 16:51:00 +02:00
parent f37f01c016
commit d5a766a49f
3 changed files with 72 additions and 11 deletions

View File

@ -172,9 +172,14 @@ void WS2812FX::strip_off() {
} }
void WS2812FX::strip_off_respectLock() { void WS2812FX::strip_off_respectLock() {
for(uint16_t i=0; i < _led_count; i++) { if (_none_locked)
if (!_locked[i]) {
setPixelColor(i, 0); clear();
} else {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
setPixelColor(i, 0);
}
} }
show(); show();
} }
@ -223,9 +228,14 @@ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) {
* No blinking. Just plain old static light. * No blinking. Just plain old static light.
*/ */
void WS2812FX::mode_static(void) { void WS2812FX::mode_static(void) {
for(uint16_t i=0; i < _led_count; i++) { if (_none_locked)
if (!_locked[i]) {
setPixelColor(i, _color); setAllPixelColor(_color);
} else {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
setPixelColor(i, _color);
}
} }
show(); show();
_mode_delay = 25; _mode_delay = 25;
@ -237,9 +247,14 @@ void WS2812FX::mode_static(void) {
*/ */
void WS2812FX::mode_blink(void) { void WS2812FX::mode_blink(void) {
if(_counter_mode_call % 2 == 1) { if(_counter_mode_call % 2 == 1) {
for(uint16_t i=0; i < _led_count; i++) { if (_none_locked)
if (!_locked[i]) {
setPixelColor(i, _color); setAllPixelColor(_color);
} else {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
setPixelColor(i, _color);
}
} }
show(); show();
} else { } else {
@ -1639,7 +1654,10 @@ void WS2812FX::setRange(int i, int i2, uint32_t col)
void WS2812FX::lock(int i) void WS2812FX::lock(int i)
{ {
if (i >= 0 && i < _led_count) if (i >= 0 && i < _led_count)
_locked[i] = true; {
_locked[i] = true;
_none_locked = false;
}
} }
void WS2812FX::lockRange(int i, int i2) void WS2812FX::lockRange(int i, int i2)
@ -1647,7 +1665,10 @@ void WS2812FX::lockRange(int i, int i2)
for (int x = i; x < i2; x++) for (int x = i; x < i2; x++)
{ {
if (x >= 0 && x < _led_count) if (x >= 0 && x < _led_count)
{
_locked[x] = true; _locked[x] = true;
_none_locked = false;
}
} }
} }
@ -1655,12 +1676,16 @@ void WS2812FX::lockAll()
{ {
for (int x = 0; x < _led_count; x++) for (int x = 0; x < _led_count; x++)
_locked[x] = true; _locked[x] = true;
_none_locked = false;
} }
void WS2812FX::unlock(int i) void WS2812FX::unlock(int i)
{ {
if (i >= 0 && i < _led_count) if (i >= 0 && i < _led_count)
_locked[i] = false; _locked[i] = false;
//lock check
_none_locked = true;
for (int x = 0; x < _led_count; x++) if (_locked[x]) _none_locked = false;
} }
void WS2812FX::unlockRange(int i, int i2) void WS2812FX::unlockRange(int i, int i2)
@ -1670,12 +1695,16 @@ void WS2812FX::unlockRange(int i, int i2)
if (x >= 0 && x < _led_count) if (x >= 0 && x < _led_count)
_locked[x] = false; _locked[x] = false;
} }
//lock check
_none_locked = true;
for (int x = 0; x < _led_count; x++) if (_locked[x]) _none_locked = false;
} }
void WS2812FX::unlockAll() void WS2812FX::unlockAll()
{ {
for (int x = 0; x < _led_count; x++) for (int x = 0; x < _led_count; x++)
_locked[x] = false; _locked[x] = false;
_none_locked = true;
} }
void WS2812FX::setLedCount(uint16_t i) void WS2812FX::setLedCount(uint16_t i)
@ -1744,6 +1773,33 @@ void WS2812FX::clear()
#endif #endif
} }
void WS2812FX::setAllPixelColor(uint32_t c)
{
#ifdef RGBW
NeoPixelBrightnessBus::ClearTo(RgbwColor((c>>16) & 0xFF, (c>>8) & 0xFF, (c) & 0xFF, (c>>24) & 0xFF));
#else
NeoPixelBrightnessBus::ClearTo(RgbColor((c>>16) & 0xFF, (c>>8) & 0xFF, (c) & 0xFF));
#endif
}
void WS2812FX::setAllPixelColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
{
#ifdef RGBW
NeoPixelBrightnessBus::ClearTo(RgbwColor(r,g,b,w));
#else
NeoPixelBrightnessBus::ClearTo(RgbColor(r,g,b));
#endif
}
void WS2812FX::setAllPixelColor(uint8_t r, uint8_t g, uint8_t b)
{
#ifdef RGBW
NeoPixelBrightnessBus::ClearTo(RgbwColor(r,g,b,0));
#else
NeoPixelBrightnessBus::ClearTo(RgbColor(r,g,b));
#endif
}
void WS2812FX::begin() void WS2812FX::begin()
{ {
NeoPixelBrightnessBus::Begin(); NeoPixelBrightnessBus::Begin();

View File

@ -236,6 +236,7 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
_counter_mode_call = 0; _counter_mode_call = 0;
_counter_mode_step = 0; _counter_mode_step = 0;
_locked = new boolean[n]; _locked = new boolean[n];
_none_locked = true;
} }
void void
@ -292,6 +293,9 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
setPixelColor(uint16_t i, uint32_t c), setPixelColor(uint16_t i, uint32_t c),
setPixelColor(uint16_t i, uint8_t r, uint8_t g, uint8_t b), setPixelColor(uint16_t i, uint8_t r, uint8_t g, uint8_t b),
setPixelColor(uint16_t i, uint8_t r, uint8_t g, uint8_t b, uint8_t w), setPixelColor(uint16_t i, uint8_t r, uint8_t g, uint8_t b, uint8_t w),
setAllPixelColor(uint32_t c),
setAllPixelColor(uint8_t r, uint8_t g, uint8_t b),
setAllPixelColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w),
dofade(void), dofade(void),
strip_off(void), strip_off(void),
strip_off_respectLock(void), strip_off_respectLock(void),
@ -352,6 +356,7 @@ class WS2812FX : public NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart800Kb
boolean boolean
_triggered, _triggered,
_none_locked,
_running; _running;
boolean* boolean*

View File

@ -20,7 +20,7 @@
#include "CallbackFunction.h" #include "CallbackFunction.h"
//version in format yymmddb (b = daily build) //version in format yymmddb (b = daily build)
#define VERSION 1710121 #define VERSION 1710280
//uncomment if you have an RGBW strip //uncomment if you have an RGBW strip
#define RGBW #define RGBW