Show only when we have changes

Keep track of a dirty flag and only do the time consuming communications
if there has been a change
This commit is contained in:
Makuna
2015-01-12 15:49:13 -08:00
parent 6afe930ea2
commit 2085fc524e
2 changed files with 29 additions and 8 deletions
+9 -2
View File
@@ -36,8 +36,8 @@ NeoPixelBus::NeoPixelBus(uint16_t n, uint8_t p, uint8_t t) :
_sizePixels(n * 3),
_pin(p),
_animationLastTick(0),
_activeAnimations(0)
,_flagsPixels(t)
_activeAnimations(0),
_flagsPixels(t)
{
setPin(p);
@@ -69,12 +69,16 @@ void NeoPixelBus::Begin(void)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
Dirty();
}
void NeoPixelBus::Show(void)
{
if (!_pixels)
return;
if (!IsDirty())
return;
// Data latch = 50+ microsecond pause in the output stream. Rather than
// put a delay at the end of the function, the ending time is noted and
@@ -849,6 +853,7 @@ void NeoPixelBus::Show(void)
#endif // end Architecture select
interrupts();
ResetDirty();
_endTime = micros(); // Save EOD time for latch on next call
}
@@ -892,6 +897,8 @@ void NeoPixelBus::UpdatePixelColor(
uint8_t g,
uint8_t b)
{
Dirty();
uint8_t *p = &_pixels[n * 3];
if ((_flagsPixels & NEO_COLMASK) == NEO_GRB)
{