SetPixelColor clears Animation state

If there is an active animation for the pixel when SetPixelColor is
called, it will be stopped.
This commit is contained in:
Makuna
2014-10-13 10:25:46 -07:00
parent 5f484cf939
commit b06f90a0af
2 changed files with 38 additions and 19 deletions

View File

@@ -876,25 +876,42 @@ void NeoPixelBus::SetPixelColor(
{
if (n < _countPixels)
{
uint8_t *p = &_pixels[n * 3];
#ifdef NEO_RGB
if ((_flagsPixels & NEO_COLMASK) == NEO_GRB)
// clear any animation
if (_animations[n].time != 0)
{
#endif
*p++ = g;
*p++ = r;
#ifdef NEO_RGB
}
else
{
*p++ = r;
*p++ = g;
_activeAnimations--;
_animations[n].time = 0;
_animations[n].remaining = 0;
}
#endif
*p = b;
UpdatePixelColor(n, r, g, b);
}
}
// Set pixel color from separate R,G,B components:
void NeoPixelBus::UpdatePixelColor(
uint16_t n,
uint8_t r,
uint8_t g,
uint8_t b)
{
uint8_t *p = &_pixels[n * 3];
#ifdef NEO_RGB
if ((_flagsPixels & NEO_COLMASK) == NEO_GRB)
{
#endif
*p++ = g;
*p++ = r;
#ifdef NEO_RGB
}
else
{
*p++ = r;
*p++ = g;
}
#endif
*p = b;
}
// Query color from previously-set pixel (returns packed 32-bit RGB value)
RgbColor NeoPixelBus::GetPixelColor(uint16_t n) const
{
@@ -979,17 +996,14 @@ void NeoPixelBus::UpdateAnimations()
pAnim->target,
progress);
SetPixelColor(iAnim, color);
UpdatePixelColor(iAnim, color);
countAnimations--;
}
else if (pAnim->remaining > 0)
{
// specifically calling SetPixelColor so it will clear animation state
SetPixelColor(iAnim, pAnim->target);
pAnim->remaining = 0;
pAnim->time = 0;
countAnimations--;
_activeAnimations--;
Serial.print(iAnim);
}
}
}

View File

@@ -80,6 +80,11 @@ public:
private:
void setPin(uint8_t p);
void UpdatePixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
void UpdatePixelColor(uint16_t n, RgbColor c)
{
UpdatePixelColor(n, c.R, c.G, c.B);
};
const uint16_t _countPixels; // Number of RGB LEDs in strip
const uint16_t _sizePixels; // Size of '_pixels' buffer below