Update DotStarColorFeatures.h (#265)

This commit is contained in:
owendelong
2019-04-23 18:13:19 -04:00
committed by Michael Miller
parent 13cb2eb014
commit 5edcd6671a

View File

@@ -324,3 +324,85 @@ public:
}; };
/* RGB Feature -- Some APA102s ship in RGB order */
class DotStarRgbFeature : public DotStar3Elements
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
*p++ = 0xff; // upper three bits are always 111 and brightness at max
*p++ = color.R;
*p++ = color.G;
*p = color.B;
}
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
uint8_t* p = getPixelAddress(pPixels, indexPixel);
p++; // ignore the first byte
color.R = *p++;
color.G = *p++;
color.B = *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
pgm_read_byte(p++); // ignore the first byte
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};
class DotStarLrgbFeature : public DotStar4Elements
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
*p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111
*p++ = color.R;
*p++ = color.G;
*p = color.B;
}
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
uint8_t* p = getPixelAddress(pPixels, indexPixel);
color.W = (*p++) & 0x1F; // mask out upper three bits
color.R = *p++;
color.G = *p++;
color.B = *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};