features and colors first pass

This commit is contained in:
Michael Miller
2024-04-10 13:29:26 -07:00
parent cc1eeb5cc1
commit 66218d1fd0
38 changed files with 453 additions and 925 deletions

View File

@@ -37,7 +37,7 @@ struct Rgb16Color : RgbColorBase
// ------------------------------------------------------------------------
// Construct a Rgb16Color using R, G, B values (0-255)
// ------------------------------------------------------------------------
Rgb16Color(uint8_t r, uint8_t g, uint8_t b)
Rgb16Color(ElementType r, ElementType g, ElementType b)
{
setR(r);
setG(g);
@@ -49,7 +49,7 @@ struct Rgb16Color : RgbColorBase
// This works well for creating gray tone colors
// (0) = black, (255) = white, (128) = gray
// ------------------------------------------------------------------------
Rgb16Color(uint8_t brightness)
Rgb16Color(ElementType brightness)
{
setR(brightness);
setG(brightness);
@@ -123,32 +123,32 @@ struct Rgb16Color : RgbColorBase
// ------------------------------------------------------------------------
// properties
// ------------------------------------------------------------------------
void setR(uint8_t r)
void setR(ElementType r)
{
Color565 &= 0x07ff;
Color565 |= ((r & 0xf8) << 8);
};
uint8_t getR() const
ElementType getR() const
{
return (Color565 & 0xf800) >> 8;
};
void setG(uint8_t g)
void setG(ElementType g)
{
Color565 &= 0xf81f;
Color565 |= ((g & 0xfe) << 3);
Color565 |= ((g & 0xfc) << 3);
};
uint8_t getG() const
ElementType getG() const
{
return (Color565 & 0x07e0) >> 3;
};
void setB(uint8_t b)
void setB(ElementType b)
{
Color565 &= 0xffe0;
Color565 |= ((b & 0xf8) >> 3);
};
uint8_t getB() const
ElementType getB() const
{
return (Color565 & 0x001f) << 3;
};
@@ -158,7 +158,7 @@ struct Rgb16Color : RgbColorBase
// access elements in order by index rather than R,G,B
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t operator[](size_t idx) const
ElementType operator[](size_t idx) const
{
switch (idx)
{
@@ -188,7 +188,7 @@ struct Rgb16Color : RgbColorBase
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint8_t CalculateBrightness() const
ElementType CalculateBrightness() const
{
RgbColor converted = *this;
return converted.CalculateBrightness();
@@ -227,7 +227,7 @@ struct Rgb16Color : RgbColorBase
// NOTE: This is a simple linear change
// delta - (0-255) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint8_t delta)
void Darken(ElementType delta)
{
RgbColor converted = *this;
@@ -242,7 +242,7 @@ struct Rgb16Color : RgbColorBase
// NOTE: This is a simple linear change
// delta - (0-255) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint8_t delta)
void Lighten(ElementType delta)
{
RgbColor converted = *this;
@@ -309,7 +309,8 @@ struct Rgb16Color : RgbColorBase
uint16_t Color565;
const static uint8_t Max = 255;
const static ElementType Max = 255;
const static size_t Count = 3; // three elements in []
const static size_t Size = 2;
};

View File

@@ -51,9 +51,9 @@ Rgb48Color::Rgb48Color(const HslColor& color)
_HslToRgb(color, &r, &g, &b);
R = static_cast<uint16_t>(r * Max);
G = static_cast<uint16_t>(g * Max);
B = static_cast<uint16_t>(b * Max);
R = static_cast<ElementType>(r * Max);
G = static_cast<ElementType>(g * Max);
B = static_cast<ElementType>(b * Max);
}
Rgb48Color::Rgb48Color(const HsbColor& color)
@@ -64,14 +64,14 @@ Rgb48Color::Rgb48Color(const HsbColor& color)
_HsbToRgb(color, &r, &g, &b);
R = static_cast<uint16_t>(r * Max);
G = static_cast<uint16_t>(g * Max);
B = static_cast<uint16_t>(b * Max);
R = static_cast<ElementType>(r * Max);
G = static_cast<ElementType>(g * Max);
B = static_cast<ElementType>(b * Max);
}
uint16_t Rgb48Color::CalculateBrightness() const
ElementType Rgb48Color::CalculateBrightness() const
{
return static_cast<uint16_t>((static_cast<uint32_t>(R) + static_cast<uint32_t>(G) + static_cast<uint32_t>(B)) / 3);
return static_cast<ElementType>((static_cast<uint32_t>(R) + static_cast<uint32_t>(G) + static_cast<uint32_t>(B)) / 3);
}
Rgb48Color Rgb48Color::Dim(uint16_t ratio) const
@@ -86,7 +86,7 @@ Rgb48Color Rgb48Color::Brighten(uint16_t ratio) const
return Rgb48Color(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio));
}
void Rgb48Color::Darken(uint16_t delta)
void Rgb48Color::Darken(ElementType delta)
{
if (R > delta)
{
@@ -116,7 +116,7 @@ void Rgb48Color::Darken(uint16_t delta)
}
}
void Rgb48Color::Lighten(uint16_t delta)
void Rgb48Color::Lighten(ElementType delta)
{
if (R < Max - delta)
{

View File

@@ -108,9 +108,9 @@ RgbColor::RgbColor(const HslColor& color)
_HslToRgb(color, &r, &g, &b);
R = static_cast<uint8_t>(r * Max);
G = static_cast<uint8_t>(g * Max);
B = static_cast<uint8_t>(b * Max);
R = static_cast<ElementType>(r * Max);
G = static_cast<ElementType>(g * Max);
B = static_cast<ElementType>(b * Max);
}
RgbColor::RgbColor(const HsbColor& color)
@@ -121,9 +121,9 @@ RgbColor::RgbColor(const HsbColor& color)
_HsbToRgb(color, &r, &g, &b);
R = static_cast<uint8_t>(r * Max);
G = static_cast<uint8_t>(g * Max);
B = static_cast<uint8_t>(b * Max);
R = static_cast<ElementType>(r * Max);
G = static_cast<ElementType>(g * Max);
B = static_cast<ElementType>(b * Max);
}
uint8_t RgbColor::CalculateBrightness() const
@@ -143,7 +143,7 @@ RgbColor RgbColor::Brighten(uint8_t ratio) const
return RgbColor(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio));
}
void RgbColor::Darken(uint8_t delta)
void RgbColor::Darken(ElementType delta)
{
if (R > delta)
{
@@ -173,7 +173,7 @@ void RgbColor::Darken(uint8_t delta)
}
}
void RgbColor::Lighten(uint8_t delta)
void RgbColor::Lighten(ElementType delta)
{
if (R < Max - delta)
{

View File

@@ -206,7 +206,7 @@ struct RgbColor : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbColor Dim(ElementType ratio) const;
RgbColor Dim(uint8_t ratio) const;
// ------------------------------------------------------------------------
// Brighten will return a new color that is blended to white with the given ratio
@@ -214,7 +214,7 @@ struct RgbColor : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbColor Brighten(ElementType ratio) const;
RgbColor Brighten(uint8_t ratio) const;
// ------------------------------------------------------------------------
// Darken will adjust the color by the given delta toward black

View File

@@ -47,9 +47,9 @@ Rgbw64Color::Rgbw64Color(const HsbColor& color)
*this = rgbColor;
}
uint16_t Rgbw64Color::CalculateBrightness() const
ElementType Rgbw64Color::CalculateBrightness() const
{
uint16_t colorB = static_cast<uint16_t>((static_cast<uint32_t>(R) + static_cast<uint32_t>(G) + static_cast<uint32_t>(B)) / 3);
ElementType colorB = static_cast<ElementType>((static_cast<uint32_t>(R) + static_cast<uint32_t>(G) + static_cast<uint32_t>(B)) / 3);
if (W > colorB)
{
return W;
@@ -60,19 +60,19 @@ uint16_t Rgbw64Color::CalculateBrightness() const
}
}
Rgbw64Color Rgbw64Color::Dim(uint16_t ratio) const
Rgbw64Color Rgbw64Color::Dim(ElementType ratio) const
{
// specifically avoids float math
return Rgbw64Color(_elementDim(R, ratio), _elementDim(G, ratio), _elementDim(B, ratio), _elementDim(W, ratio));
}
Rgbw64Color Rgbw64Color::Brighten(uint16_t ratio) const
Rgbw64Color Rgbw64Color::Brighten(ElementType ratio) const
{
// specifically avoids float math
return Rgbw64Color(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio), _elementBrighten(W, ratio));
}
void Rgbw64Color::Darken(uint16_t delta)
void Rgbw64Color::Darken(ElementType delta)
{
if (R > delta)
{
@@ -111,7 +111,7 @@ void Rgbw64Color::Darken(uint16_t delta)
}
}
void Rgbw64Color::Lighten(uint16_t delta)
void Rgbw64Color::Lighten(ElementType delta)
{
if (IsColorLess())
{

View File

@@ -36,12 +36,13 @@ struct HsbColor;
// ------------------------------------------------------------------------
struct Rgbw64Color : RgbColorBase
{
typedef uint16_t ElementType;
typedef NeoRgbwCurrentSettings SettingsObject;
// ------------------------------------------------------------------------
// Construct a Rgbw64Color using R, G, B, W values (0-65535)
// ------------------------------------------------------------------------
Rgbw64Color(uint16_t r, uint16_t g, uint16_t b, uint16_t w = 0) :
Rgbw64Color(ElementType r, ElementType g, ElementType b, ElementType w = 0) :
R(r), G(g), B(b), W(w)
{
};
@@ -51,7 +52,7 @@ struct Rgbw64Color : RgbColorBase
// This works well for creating gray tone colors
// (0) = black, (65535) = white, (32768) = gray
// ------------------------------------------------------------------------
Rgbw64Color(uint16_t brightness) :
Rgbw64Color(ElementType brightness) :
R(0), G(0), B(0), W(brightness)
{
};
@@ -81,10 +82,10 @@ struct Rgbw64Color : RgbColorBase
Rgbw64Color(const RgbwColor& color)
{
// x16 = map(x8, 0, 255, 0, 65535); // refactors to just * 257
R = (uint16_t)color.R * 257; // 257 = MAXUINT16/MAXUINT8 = 65535/255
G = (uint16_t)color.G * 257;
B = (uint16_t)color.B * 257;
W = (uint16_t)color.W * 257;
R = (ElementType)color.R * 257; // 257 = MAXUINT16/MAXUINT8 = 65535/255
G = (ElementType)color.G * 257;
B = (ElementType)color.B * 257;
W = (ElementType)color.W * 257;
};
@@ -135,7 +136,7 @@ struct Rgbw64Color : RgbColorBase
// negative - this is less than other
// positive - this is greater than other
// ------------------------------------------------------------------------
int32_t CompareTo(const Rgbw64Color& other, uint16_t epsilon = 256)
int32_t CompareTo(const Rgbw64Color& other, ElementType epsilon = 256)
{
return _Compare<Rgbw64Color, int32_t>(*this, other, epsilon);
}
@@ -148,7 +149,7 @@ struct Rgbw64Color : RgbColorBase
// negative - left is less than right
// positive - left is greater than right
// ------------------------------------------------------------------------
static int32_t Compare(const Rgbw64Color& left, const Rgbw64Color& right, uint16_t epsilon = 256)
static int32_t Compare(const Rgbw64Color& left, const Rgbw64Color& right, ElementType epsilon = 256)
{
return _Compare<Rgbw64Color, int32_t>(left, right, epsilon);
}
@@ -158,7 +159,7 @@ struct Rgbw64Color : RgbColorBase
// access elements in order by index rather than R,G,B
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint16_t operator[](size_t idx) const
ElementType operator[](size_t idx) const
{
switch (idx)
{
@@ -178,7 +179,7 @@ struct Rgbw64Color : RgbColorBase
// access elements in order by index rather than R,G,B
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint16_t& operator[](size_t idx)
ElementType& operator[](size_t idx)
{
switch (idx)
{
@@ -214,7 +215,7 @@ struct Rgbw64Color : RgbColorBase
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint16_t CalculateBrightness() const;
ElementType CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@@ -222,7 +223,7 @@ struct Rgbw64Color : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
Rgbw64Color Dim(uint16_t ratio) const;
Rgbw64Color Dim(ElementType ratio) const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@@ -232,7 +233,7 @@ struct Rgbw64Color : RgbColorBase
// ------------------------------------------------------------------------
Rgbw64Color Dim(uint8_t ratio) const
{
uint16_t expanded = ratio << 8;
ElementType expanded = ratio << 8;
return Dim(expanded);
}
@@ -242,7 +243,7 @@ struct Rgbw64Color : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
Rgbw64Color Brighten(uint16_t ratio) const;
Rgbw64Color Brighten(ElementType ratio) const;
// ------------------------------------------------------------------------
// Brighten will return a new color that is blended to white with the given ratio
@@ -252,7 +253,7 @@ struct Rgbw64Color : RgbColorBase
// ------------------------------------------------------------------------
Rgbw64Color Brighten(uint8_t ratio) const
{
uint16_t expanded = ratio << 8;
ElementType expanded = ratio << 8;
return Brighten(expanded);
}
@@ -261,14 +262,14 @@ struct Rgbw64Color : RgbColorBase
// NOTE: This is a simple linear change
// delta - (0-65535) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint16_t delta);
void Darken(ElementType delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-65535) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint16_t delta);
void Lighten(ElementType delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@@ -299,7 +300,7 @@ struct Rgbw64Color : RgbColorBase
float x,
float y);
uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
{
auto total = 0;
@@ -316,21 +317,22 @@ struct Rgbw64Color : RgbColorBase
// (0,0,0,0) is black and (65535,65535,65535, 0) and (0,0,0,65535) is white
// Note (65535,65535,65535,65535) is extreme bright white
// ------------------------------------------------------------------------
uint16_t R;
uint16_t G;
uint16_t B;
uint16_t W;
ElementType R;
ElementType G;
ElementType B;
ElementType W;
const static uint16_t Max = 65535;
const static ElementType Max = 65535;
const static size_t Count = 4; // four elements in []
const static size_t Size = Count * sizeof(ElementType);
private:
inline static uint16_t _elementDim(uint16_t value, uint16_t ratio)
inline static ElementType _elementDim(ElementType value, ElementType ratio)
{
return (static_cast<uint32_t>(value) * (static_cast<uint32_t>(ratio) + 1)) >> 16;
}
inline static uint16_t _elementBrighten(uint16_t value, uint16_t ratio)
inline static ElementType _elementBrighten(ElementType value, ElementType ratio)
{
uint32_t element = ((static_cast<uint32_t>(value) + 1) << 16) / (static_cast<uint32_t>(ratio) + 1);

View File

@@ -43,7 +43,7 @@ RgbwColor::RgbwColor(const RgbwwColor& color) :
R(color.R),
G(color.G),
B(color.B),
W(static_cast<uint8_t>((static_cast<uint16_t>(color.WW) + static_cast<uint16_t>(color.CW)) / 2))
W(static_cast<ElementType>((static_cast<uint16_t>(color.WW) + static_cast<uint16_t>(color.CW)) / 2))
{
};
@@ -51,7 +51,7 @@ RgbwColor::RgbwColor(const RgbwwwColor& color) :
R(color.R),
G(color.G),
B(color.B),
W(static_cast<uint8_t>((static_cast<uint16_t>(color.W1) + static_cast<uint16_t>(color.W2) + static_cast<uint16_t>(color.W3)) / 3))
W(static_cast<ElementType>((static_cast<uint16_t>(color.W1) + static_cast<uint16_t>(color.W2) + static_cast<uint16_t>(color.W3)) / 3))
{
};
@@ -67,7 +67,7 @@ RgbwColor::RgbwColor(const Rgbww80Color& color) :
R(color.R >> 8),
G(color.G >> 8),
B(color.B >> 8),
W(static_cast<uint8_t>((static_cast<uint32_t>(color.WW) + static_cast<uint32_t>(color.CW)) >> 9)) // div 2 >> 8
W(static_cast<ElementType>((static_cast<uint32_t>(color.WW) + static_cast<uint32_t>(color.CW)) >> 9)) // div 2 >> 8
{
};
@@ -95,9 +95,9 @@ RgbwColor::RgbwColor(const HsbColor& color)
*this = rgbColor;
}
uint8_t RgbwColor::CalculateBrightness() const
ElementType RgbwColor::CalculateBrightness() const
{
uint8_t colorB = static_cast<uint8_t>((static_cast<uint16_t>(R) + static_cast<uint16_t>(G) + static_cast<uint16_t>(B)) / 3);
ElementType colorB = static_cast<ElementType>((static_cast<uint16_t>(R) + static_cast<uint16_t>(G) + static_cast<uint16_t>(B)) / 3);
if (W > colorB)
{
return W;
@@ -120,7 +120,7 @@ RgbwColor RgbwColor::Brighten(uint8_t ratio) const
return RgbwColor(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio), _elementBrighten(W, ratio));
}
void RgbwColor::Darken(uint8_t delta)
void RgbwColor::Darken(ElementType delta)
{
if (R > delta)
{
@@ -159,7 +159,7 @@ void RgbwColor::Darken(uint8_t delta)
}
}
void RgbwColor::Lighten(uint8_t delta)
void RgbwColor::Lighten(ElementType delta)
{
if (IsColorLess())
{

View File

@@ -41,12 +41,13 @@ struct Rgbww80Color;
// ------------------------------------------------------------------------
struct RgbwColor : RgbColorBase
{
typedef uint8_t ElementType;
typedef NeoRgbwCurrentSettings SettingsObject;
// ------------------------------------------------------------------------
// Construct a RgbwColor using R, G, B, W values (0-255)
// ------------------------------------------------------------------------
RgbwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) :
RgbwColor(ElementType r, ElementType g, ElementType b, ElementType w = 0) :
R(r), G(g), B(b), W(w)
{
};
@@ -56,7 +57,7 @@ struct RgbwColor : RgbColorBase
// This works well for creating gray tone colors
// (0) = black, (255) = white, (128) = gray
// ------------------------------------------------------------------------
RgbwColor(uint8_t brightness) :
RgbwColor(ElementType brightness) :
R(0), G(0), B(0), W(brightness)
{
};
@@ -136,7 +137,7 @@ struct RgbwColor : RgbColorBase
// negative - this is less than other
// positive - this is greater than other
// ------------------------------------------------------------------------
int16_t CompareTo(const RgbwColor& other, uint8_t epsilon = 1)
int16_t CompareTo(const RgbwColor& other, ElementType epsilon = 1)
{
return _Compare<RgbwColor, int16_t>(*this, other, epsilon);
}
@@ -149,7 +150,7 @@ struct RgbwColor : RgbColorBase
// negative - left is less than right
// positive - left is greater than right
// ------------------------------------------------------------------------
static int16_t Compare(const RgbwColor& left, const RgbwColor& right, uint8_t epsilon = 1)
static int16_t Compare(const RgbwColor& left, const RgbwColor& right, ElementType epsilon = 1)
{
return _Compare<RgbwColor, int16_t>(left, right, epsilon);
}
@@ -159,7 +160,7 @@ struct RgbwColor : RgbColorBase
// access elements in order by index rather than R,G,B
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t operator[](size_t idx) const
ElementType operator[](size_t idx) const
{
switch (idx)
{
@@ -179,7 +180,7 @@ struct RgbwColor : RgbColorBase
// access elements in order by index rather than R,G,B
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t& operator[](size_t idx)
ElementType& operator[](size_t idx)
{
switch (idx)
{
@@ -215,7 +216,7 @@ struct RgbwColor : RgbColorBase
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint8_t CalculateBrightness() const;
ElementType CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@@ -238,14 +239,14 @@ struct RgbwColor : RgbColorBase
// NOTE: This is a simple linear change
// delta - (0-255) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint8_t delta);
void Darken(ElementType delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-255) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint8_t delta);
void Lighten(ElementType delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@@ -293,21 +294,22 @@ struct RgbwColor : RgbColorBase
// (0,0,0,0) is black and (255,255,255, 0) and (0,0,0,255) is white
// Note (255,255,255,255) is extreme bright white
// ------------------------------------------------------------------------
uint8_t R;
uint8_t G;
uint8_t B;
uint8_t W;
ElementType R;
ElementType G;
ElementType B;
ElementType W;
const static uint8_t Max = 255;
const static ElementType Max = 255;
const static size_t Count = 4; // four elements in []
const static size_t Size = Count * sizeof(ElementType);
private:
inline static uint8_t _elementDim(uint8_t value, uint8_t ratio)
inline static ElementType _elementDim(ElementType value, ElementType ratio)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
}
inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio)
inline static ElementType _elementBrighten(ElementType value, ElementType ratio)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);

View File

@@ -52,15 +52,15 @@ Rgbww80Color::Rgbww80Color(const Rgbw64Color& color) :
{
};
uint16_t Rgbww80Color::CalculateBrightness() const
ElementType Rgbww80Color::CalculateBrightness() const
{
uint16_t colorB = static_cast<uint16_t>((static_cast<uint32_t>(R) + static_cast<uint32_t>(G) + static_cast<uint32_t>(B)) / 3);
uint16_t whiteB = static_cast<uint16_t>((static_cast<uint32_t>(WW) + static_cast<uint32_t>(CW)) / 2);
ElementType colorB = static_cast<ElementType>((static_cast<uint32_t>(R) + static_cast<uint32_t>(G) + static_cast<uint32_t>(B)) / 3);
ElementType whiteB = static_cast<ElementType>((static_cast<uint32_t>(WW) + static_cast<uint32_t>(CW)) / 2);
return (whiteB > colorB) ? whiteB : colorB;
}
Rgbww80Color Rgbww80Color::Dim(uint16_t ratio) const
Rgbww80Color Rgbww80Color::Dim(ElementType ratio) const
{
// specifically avoids float math
return Rgbww80Color(_elementDim(R, ratio),
@@ -70,7 +70,7 @@ Rgbww80Color Rgbww80Color::Dim(uint16_t ratio) const
_elementDim(CW, ratio));
}
Rgbww80Color Rgbww80Color::Brighten(uint16_t ratio) const
Rgbww80Color Rgbww80Color::Brighten(ElementType ratio) const
{
// specifically avoids float math
return Rgbww80Color(_elementBrighten(R, ratio),
@@ -80,7 +80,7 @@ Rgbww80Color Rgbww80Color::Brighten(uint16_t ratio) const
_elementBrighten(CW, ratio));
}
void Rgbww80Color::Darken(uint16_t delta)
void Rgbww80Color::Darken(ElementType delta)
{
if (R > delta)
{
@@ -128,7 +128,7 @@ void Rgbww80Color::Darken(uint16_t delta)
}
}
void Rgbww80Color::Lighten(uint16_t delta)
void Rgbww80Color::Lighten(ElementType delta)
{
if (IsColorLess())
{

View File

@@ -39,12 +39,13 @@ struct HsbColor;
// ------------------------------------------------------------------------
struct Rgbww80Color : RgbColorBase
{
typedef uint16_t ElementType;
typedef NeoRgbwwCurrentSettings SettingsObject;
// ------------------------------------------------------------------------
// Construct a Rgbww80Color using R, G, B, WW, CW values (0-65535)
// ------------------------------------------------------------------------
Rgbww80Color(uint16_t r, uint16_t g, uint16_t b, uint16_t warmW = 0, uint16_t coolW = 0) :
Rgbww80Color(ElementType r, ElementType g, ElementType b, ElementType warmW = 0, ElementType coolW = 0) :
R(r), G(g), B(b), WW(warmW), CW(coolW)
{
};
@@ -54,7 +55,7 @@ struct Rgbww80Color : RgbColorBase
// This works well for creating gray tone colors
// (0) = black, (65535) = white, (128) = gray
// ------------------------------------------------------------------------
Rgbww80Color(uint16_t brightness) :
Rgbww80Color(ElementType brightness) :
R(0), G(0), B(0), WW(brightness), CW(brightness)
{
};
@@ -142,7 +143,7 @@ struct Rgbww80Color : RgbColorBase
// negative - this is less than other
// positive - this is greater than other
// ------------------------------------------------------------------------
int32_t CompareTo(const Rgbww80Color& other, uint16_t epsilon = 256)
int32_t CompareTo(const Rgbww80Color& other, ElementType epsilon = 256)
{
return _Compare<Rgbww80Color, int32_t>(*this, other, epsilon);
}
@@ -155,7 +156,7 @@ struct Rgbww80Color : RgbColorBase
// negative - left is less than right
// positive - left is greater than right
// ------------------------------------------------------------------------
static int32_t Compare(const Rgbww80Color& left, const Rgbww80Color& right, uint16_t epsilon = 256)
static int32_t Compare(const Rgbww80Color& left, const Rgbww80Color& right, ElementType epsilon = 256)
{
return _Compare<Rgbww80Color, int32_t>(left, right, epsilon);
}
@@ -165,7 +166,7 @@ struct Rgbww80Color : RgbColorBase
// access elements in order by index rather than R,G,B,WW,CW
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint16_t operator[](size_t idx) const
ElementType operator[](size_t idx) const
{
switch (idx)
{
@@ -187,7 +188,7 @@ struct Rgbww80Color : RgbColorBase
// access elements in order by index rather than R,G,B,WW,CW
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint16_t& operator[](size_t idx)
ElementType& operator[](size_t idx)
{
switch (idx)
{
@@ -225,7 +226,7 @@ struct Rgbww80Color : RgbColorBase
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint16_t CalculateBrightness() const;
ElementType CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@@ -233,7 +234,7 @@ struct Rgbww80Color : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
Rgbww80Color Dim(uint16_t ratio) const;
Rgbww80Color Dim(ElementType ratio) const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@@ -243,7 +244,7 @@ struct Rgbww80Color : RgbColorBase
// ------------------------------------------------------------------------
Rgbww80Color Dim(uint8_t ratio) const
{
uint16_t expanded = ratio << 8;
ElementType expanded = ratio << 8;
return Dim(expanded);
}
@@ -253,7 +254,7 @@ struct Rgbww80Color : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
Rgbww80Color Brighten(uint16_t ratio) const;
Rgbww80Color Brighten(ElementType ratio) const;
// ------------------------------------------------------------------------
// Brighten will return a new color that is blended to white with the given ratio
@@ -263,7 +264,7 @@ struct Rgbww80Color : RgbColorBase
// ------------------------------------------------------------------------
Rgbww80Color Brighten(uint8_t ratio) const
{
uint16_t expanded = ratio << 8;
ElementType expanded = ratio << 8;
return Brighten(expanded);
}
@@ -272,14 +273,14 @@ struct Rgbww80Color : RgbColorBase
// NOTE: This is a simple linear change
// delta - (0-65535) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint16_t delta);
void Darken(ElementType delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-65535) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint16_t delta);
void Lighten(ElementType delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@@ -331,22 +332,23 @@ struct Rgbww80Color : RgbColorBase
// (0,0,0,0,65535) is cool white and
// Note (65535,65535,65535,65535,65535) is extreme bright white
// ------------------------------------------------------------------------
uint16_t R;
uint16_t G;
uint16_t B;
uint16_t WW;
uint16_t CW;
ElementType R;
ElementType G;
ElementType B;
ElementType WW;
ElementType CW;
const static uint16_t Max = 65535;
const static ElementType Max = 65535;
const static size_t Count = 5; // five elements in []
const static size_t Size = Count * sizeof(ElementType);
private:
inline static uint16_t _elementDim(uint16_t value, uint16_t ratio)
inline static ElementType _elementDim(ElementType value, ElementType ratio)
{
return (static_cast<uint32_t>(value) * (static_cast<uint32_t>(ratio) + 1)) >> 16;
}
inline static uint16_t _elementBrighten(uint16_t value, uint16_t ratio)
inline static ElementType _elementBrighten(ElementType value, ElementType ratio)
{
uint32_t element = ((static_cast<uint32_t>(value) + 1) << 16) / (static_cast<uint32_t>(ratio) + 1);

View File

@@ -61,10 +61,10 @@ RgbwwColor::RgbwwColor(const HsbColor& color)
*this = rgbColor;
}
uint8_t RgbwwColor::CalculateBrightness() const
ElementType RgbwwColor::CalculateBrightness() const
{
uint8_t colorB = static_cast<uint8_t>((static_cast<uint16_t>(R) + static_cast<uint16_t>(G) + static_cast<uint16_t>(B)) / 3);
uint8_t whiteB = static_cast<uint8_t>((static_cast<uint16_t>(WW) + static_cast<uint16_t>(CW)) / 2);
ElementType colorB = static_cast<ElementType>((static_cast<uint16_t>(R) + static_cast<uint16_t>(G) + static_cast<uint16_t>(B)) / 3);
ElementType whiteB = static_cast<ElementType>((static_cast<uint16_t>(WW) + static_cast<uint16_t>(CW)) / 2);
return (whiteB > colorB) ? whiteB : colorB;
}
@@ -89,7 +89,7 @@ RgbwwColor RgbwwColor::Brighten(uint8_t ratio) const
_elementBrighten(CW, ratio));
}
void RgbwwColor::Darken(uint8_t delta)
void RgbwwColor::Darken(ElementType delta)
{
if (R > delta)
{
@@ -137,7 +137,7 @@ void RgbwwColor::Darken(uint8_t delta)
}
}
void RgbwwColor::Lighten(uint8_t delta)
void RgbwwColor::Lighten(ElementType delta)
{
if (IsColorLess())
{

View File

@@ -39,12 +39,13 @@ struct HsbColor;
// ------------------------------------------------------------------------
struct RgbwwColor : RgbColorBase
{
typedef uint8_t ElementType;
typedef NeoRgbwwCurrentSettings SettingsObject;
// ------------------------------------------------------------------------
// Construct a RgbwwColor using R, G, B, WW, CW values (0-255)
// ------------------------------------------------------------------------
RgbwwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t warmW = 0, uint8_t coolW = 0) :
RgbwwColor(ElementType r, ElementType g, ElementType b, ElementType warmW = 0, ElementType coolW = 0) :
R(r), G(g), B(b), WW(warmW), CW(coolW)
{
};
@@ -54,7 +55,7 @@ struct RgbwwColor : RgbColorBase
// This works well for creating gray tone colors
// (0) = black, (255) = white, (128) = gray
// ------------------------------------------------------------------------
RgbwwColor(uint8_t brightness) :
RgbwwColor(ElementType brightness) :
R(0), G(0), B(0), WW(brightness), CW(brightness)
{
};
@@ -127,7 +128,7 @@ struct RgbwwColor : RgbColorBase
// negative - this is less than other
// positive - this is greater than other
// ------------------------------------------------------------------------
int16_t CompareTo(const RgbwwColor& other, uint8_t epsilon = 1)
int16_t CompareTo(const RgbwwColor& other, ElementType epsilon = 1)
{
return _Compare<RgbwwColor, int16_t>(*this, other, epsilon);
}
@@ -140,7 +141,7 @@ struct RgbwwColor : RgbColorBase
// negative - left is less than right
// positive - left is greater than right
// ------------------------------------------------------------------------
static int16_t Compare(const RgbwwColor& left, const RgbwwColor& right, uint8_t epsilon = 1)
static int16_t Compare(const RgbwwColor& left, const RgbwwColor& right, ElementType epsilon = 1)
{
return _Compare<RgbwwColor, int16_t>(left, right, epsilon);
}
@@ -150,7 +151,7 @@ struct RgbwwColor : RgbColorBase
// access elements in order by index rather than R,G,B,WW,CW
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t operator[](size_t idx) const
ElementType operator[](size_t idx) const
{
switch (idx)
{
@@ -172,7 +173,7 @@ struct RgbwwColor : RgbColorBase
// access elements in order by index rather than R,G,B,WW,CW
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t& operator[](size_t idx)
ElementType& operator[](size_t idx)
{
switch (idx)
{
@@ -210,7 +211,7 @@ struct RgbwwColor : RgbColorBase
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint8_t CalculateBrightness() const;
ElementType CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@@ -233,14 +234,14 @@ struct RgbwwColor : RgbColorBase
// NOTE: This is a simple linear change
// delta - (0-255) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint8_t delta);
void Darken(ElementType delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-255) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint8_t delta);
void Lighten(ElementType delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@@ -292,22 +293,23 @@ struct RgbwwColor : RgbColorBase
// (0,0,0,0,255) is cool white and
// Note (255,255,255,255,255) is extreme bright white
// ------------------------------------------------------------------------
uint8_t R;
uint8_t G;
uint8_t B;
uint8_t WW;
uint8_t CW;
ElementType R;
ElementType G;
ElementType B;
ElementType WW;
ElementType CW;
const static uint8_t Max = 255;
const static ElementType Max = 255;
const static size_t Count = 5; // five elements in []
const static size_t Size = Count * sizeof(ElementType);
private:
inline static uint8_t _elementDim(uint8_t value, uint8_t ratio)
inline static ElementType _elementDim(ElementType value, ElementType ratio)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
}
inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio)
inline static ElementType _elementBrighten(ElementType value, ElementType ratio)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);

View File

@@ -62,15 +62,15 @@ RgbwwwColor::RgbwwwColor(const HsbColor& color)
*this = rgbColor;
}
uint8_t RgbwwwColor::CalculateBrightness() const
ElementType RgbwwwColor::CalculateBrightness() const
{
uint8_t colorB = static_cast<uint8_t>((static_cast<uint16_t>(R) + static_cast<uint16_t>(G) + static_cast<uint16_t>(B)) / 3);
uint8_t whiteB = static_cast<uint8_t>((static_cast<uint16_t>(W1) + static_cast<uint16_t>(W2) + static_cast<uint16_t>(W3)) / 3);
ElementType colorB = static_cast<ElementType>((static_cast<uint16_t>(R) + static_cast<uint16_t>(G) + static_cast<uint16_t>(B)) / 3);
ElementType whiteB = static_cast<ElementType>((static_cast<uint16_t>(W1) + static_cast<uint16_t>(W2) + static_cast<uint16_t>(W3)) / 3);
return (whiteB > colorB) ? whiteB : colorB;
}
RgbwwwColor RgbwwwColor::Dim(uint8_t ratio) const
RgbwwwColor RgbwwwColor::Dim(ElementType ratio) const
{
// specifically avoids float math
return RgbwwwColor(_elementDim(R, ratio),
@@ -81,7 +81,7 @@ RgbwwwColor RgbwwwColor::Dim(uint8_t ratio) const
_elementDim(W3, ratio));
}
RgbwwwColor RgbwwwColor::Brighten(uint8_t ratio) const
RgbwwwColor RgbwwwColor::Brighten(ElementType ratio) const
{
// specifically avoids float math
return RgbwwwColor(_elementBrighten(R, ratio),
@@ -92,7 +92,7 @@ RgbwwwColor RgbwwwColor::Brighten(uint8_t ratio) const
_elementBrighten(W3, ratio));
}
void RgbwwwColor::Darken(uint8_t delta)
void RgbwwwColor::Darken(ElementType delta)
{
if (R > delta)
{
@@ -149,7 +149,7 @@ void RgbwwwColor::Darken(uint8_t delta)
}
}
void RgbwwwColor::Lighten(uint8_t delta)
void RgbwwwColor::Lighten(ElementType delta)
{
if (IsColorLess())
{

View File

@@ -36,12 +36,13 @@ struct HsbColor;
// ------------------------------------------------------------------------
struct RgbwwwColor : RgbColorBase
{
typedef uint8_t ElementType;
typedef NeoRgbwwwCurrentSettings SettingsObject;
// ------------------------------------------------------------------------
// Construct a RgbwwwColor using R, G, B, W1, W2, W3 values (0-255)
// ------------------------------------------------------------------------
RgbwwwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t w1, uint8_t w2, uint8_t w3) :
RgbwwwColor(ElementType r, ElementType g, ElementType b, ElementType w1, ElementType w2, ElementType w3) :
R(r), G(g), B(b), W1(w1), W2(w2), W3(w3)
{
};
@@ -51,7 +52,7 @@ struct RgbwwwColor : RgbColorBase
// White is set incrementally across the three whites,
// where 1 = (0,0,1), 2 = (0,1,1), 3 = (1,1,1), 4 = (1,1,2)
// ------------------------------------------------------------------------
RgbwwwColor(uint8_t r, uint8_t g, uint8_t b, uint16_t w) :
RgbwwwColor(ElementType r, ElementType g, ElementType b, uint16_t w) :
R(r), G(g), B(b)
{
ApplyAsIncrementalWhite(w);
@@ -62,7 +63,7 @@ struct RgbwwwColor : RgbColorBase
// This works well for creating gray tone colors
// (0) = black, (255) = white, (128) = gray
// ------------------------------------------------------------------------
RgbwwwColor(uint8_t brightness) :
RgbwwwColor(ElementType brightness) :
R(0), G(0), B(0), W1(brightness), W2(brightness), W3(brightness)
{
};
@@ -137,7 +138,7 @@ struct RgbwwwColor : RgbColorBase
// negative - this is less than other
// positive - this is greater than other
// ------------------------------------------------------------------------
int16_t CompareTo(const RgbwwwColor& other, uint8_t epsilon = 1)
int16_t CompareTo(const RgbwwwColor& other, ElementType epsilon = 1)
{
return _Compare<RgbwwwColor, int16_t>(*this, other, epsilon);
}
@@ -150,7 +151,7 @@ struct RgbwwwColor : RgbColorBase
// negative - left is less than right
// positive - left is greater than right
// ------------------------------------------------------------------------
static int16_t Compare(const RgbwwwColor& left, const RgbwwwColor& right, uint8_t epsilon = 1)
static int16_t Compare(const RgbwwwColor& left, const RgbwwwColor& right, ElementType epsilon = 1)
{
return _Compare<RgbwwwColor, int16_t>(left, right, epsilon);
}
@@ -160,7 +161,7 @@ struct RgbwwwColor : RgbColorBase
// access elements in order by index rather than R,G,B,W1,W2,W3
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t operator[](size_t idx) const
ElementType operator[](size_t idx) const
{
switch (idx)
{
@@ -184,7 +185,7 @@ struct RgbwwwColor : RgbColorBase
// access elements in order by index rather than R,G,B,W1,W2
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t& operator[](size_t idx)
ElementType& operator[](size_t idx)
{
switch (idx)
{
@@ -224,7 +225,7 @@ struct RgbwwwColor : RgbColorBase
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint8_t CalculateBrightness() const;
ElementType CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new color that is blended to black with the given ratio
@@ -232,7 +233,7 @@ struct RgbwwwColor : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbwwwColor Dim(uint8_t ratio) const;
RgbwwwColor Dim(ElementType ratio) const;
// ------------------------------------------------------------------------
// Brighten will return a new color that is blended to white with the given ratio
@@ -240,21 +241,21 @@ struct RgbwwwColor : RgbColorBase
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
RgbwwwColor Brighten(uint8_t ratio) const;
RgbwwwColor Brighten(ElementType ratio) const;
// ------------------------------------------------------------------------
// Darken will adjust the color by the given delta toward black
// NOTE: This is a simple linear change
// delta - (0-255) the amount to dim the color
// ------------------------------------------------------------------------
void Darken(uint8_t delta);
void Darken(ElementType delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-255) the amount to lighten the color
// ------------------------------------------------------------------------
void Lighten(uint8_t delta);
void Lighten(ElementType delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@@ -306,8 +307,8 @@ struct RgbwwwColor : RgbColorBase
// ------------------------------------------------------------------------
void ApplyAsIncrementalWhite(uint16_t white)
{
uint8_t value = white / 3;
uint8_t remainder = white % 3;
ElementType value = white / 3;
ElementType remainder = white % 3;
W1 = value;
W2 = value;
@@ -331,24 +332,25 @@ struct RgbwwwColor : RgbColorBase
// (0,0,0, 0,255,0) is white2 and
// Note (255,255,255, 255,255,255) is extreme bright white
// ------------------------------------------------------------------------
uint8_t R;
uint8_t G;
uint8_t B;
uint8_t W1;
uint8_t W2;
uint8_t W3;
ElementType R;
ElementType G;
ElementType B;
ElementType W1;
ElementType W2;
ElementType W3;
const static uint8_t Max = 255;
const static ElementType Max = 255;
const static size_t Count = 6; // six elements in []
const static size_t Size = Count * sizeof(ElementType);
const static uint16_t MaxIncrementalWhite = 765;
private:
inline static uint8_t _elementDim(uint8_t value, uint8_t ratio)
inline static ElementType _elementDim(ElementType value, ElementType ratio)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
}
inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio)
inline static ElementType _elementBrighten(ElementType value, ElementType ratio)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);

View File

@@ -58,7 +58,7 @@ const uint8_t SevenSegDigit::DecodeSpecial[] = {
// , - . /
0x80, 0x40, 0x80, 0x40 };
void SevenSegDigit::init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness)
void SevenSegDigit::init(uint8_t bitmask, ElementType brightness, ElementType defaultBrightness)
{
for (uint8_t iSegment = 0; iSegment < Count; iSegment++)
{
@@ -67,12 +67,12 @@ void SevenSegDigit::init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBri
}
}
SevenSegDigit::SevenSegDigit(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness)
SevenSegDigit::SevenSegDigit(uint8_t bitmask, ElementType brightness, ElementType defaultBrightness)
{
init(bitmask, brightness, defaultBrightness);
};
SevenSegDigit::SevenSegDigit(char letter, uint8_t brightness, uint8_t defaultBrightness, bool maintainCase)
SevenSegDigit::SevenSegDigit(char letter, ElementType brightness, ElementType defaultBrightness, bool maintainCase)
{
if (letter >= '0' && letter <= '9')
{
@@ -108,7 +108,7 @@ SevenSegDigit::SevenSegDigit(char letter, uint8_t brightness, uint8_t defaultBri
}
};
uint8_t SevenSegDigit::CalculateBrightness() const
ElementType SevenSegDigit::CalculateBrightness() const
{
uint16_t sum = 0;
@@ -117,10 +117,10 @@ uint8_t SevenSegDigit::CalculateBrightness() const
sum += Segment[iSegment];
}
return static_cast<uint8_t>(sum / Count);
return static_cast<ElementType>(sum / Count);
}
SevenSegDigit SevenSegDigit::Dim(uint8_t ratio) const
SevenSegDigit SevenSegDigit::Dim(ElementType ratio) const
{
SevenSegDigit result;
@@ -131,7 +131,7 @@ SevenSegDigit SevenSegDigit::Dim(uint8_t ratio) const
return result;
}
SevenSegDigit SevenSegDigit::Brighten(uint8_t ratio) const
SevenSegDigit SevenSegDigit::Brighten(ElementType ratio) const
{
SevenSegDigit result;
@@ -142,11 +142,11 @@ SevenSegDigit SevenSegDigit::Brighten(uint8_t ratio) const
return result;
}
void SevenSegDigit::Darken(uint8_t delta)
void SevenSegDigit::Darken(ElementType delta)
{
for (uint8_t iSegment = 0; iSegment < Count; iSegment++)
{
uint8_t element = Segment[iSegment];
ElementType element = Segment[iSegment];
if (element > delta)
{
element -= delta;
@@ -159,11 +159,11 @@ void SevenSegDigit::Darken(uint8_t delta)
}
}
void SevenSegDigit::Lighten(uint8_t delta)
void SevenSegDigit::Lighten(ElementType delta)
{
for (uint8_t iSegment = 0; iSegment < Count; iSegment++)
{
uint8_t element = Segment[iSegment];
ElementType element = Segment[iSegment];
if (element < 255 - delta)
{
element += delta;
@@ -187,7 +187,7 @@ SevenSegDigit SevenSegDigit::LinearBlend(const SevenSegDigit& left, const SevenS
return result;
}
SevenSegDigit SevenSegDigit::LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, uint8_t progress)
SevenSegDigit SevenSegDigit::LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, ElementType progress)
{
SevenSegDigit result;

View File

@@ -65,13 +65,14 @@ public:
// ------------------------------------------------------------------------
struct SevenSegDigit
{
typedef uint8_t ElementType;
typedef NeoSevenSegCurrentSettings SettingsObject;
// ------------------------------------------------------------------------
// Construct a SevenSegDigit using
// the default brightness to apply to all segments
// ------------------------------------------------------------------------
SevenSegDigit(uint8_t defaultBrightness)
SevenSegDigit(ElementType defaultBrightness)
{
memset(Segment, defaultBrightness, sizeof(Segment));
}
@@ -82,7 +83,7 @@ struct SevenSegDigit
// the brightness to apply to them, (0-255)
// the default brightness to apply to those not set in the bitmask (0-255)
// ------------------------------------------------------------------------
SevenSegDigit(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness = 0);
SevenSegDigit(uint8_t bitmask, ElementType brightness, ElementType defaultBrightness = 0);
// ------------------------------------------------------------------------
// Construct a SevenSegDigit using
@@ -90,7 +91,7 @@ struct SevenSegDigit
// the brightness to apply to them, (0-255)
// the default brightness to apply to those not set in the bitmask (0-255)
// ------------------------------------------------------------------------
SevenSegDigit(char letter, uint8_t brightness, uint8_t defaultBrightness = 0, bool maintainCase = false);
SevenSegDigit(char letter, ElementType brightness, ElementType defaultBrightness = 0, bool maintainCase = false);
// ------------------------------------------------------------------------
// Construct a SevenSegDigit that will have its values set in latter operations
@@ -125,7 +126,7 @@ struct SevenSegDigit
// access elements in order of the Segments
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t operator[](size_t idx) const
ElementType operator[](size_t idx) const
{
return Segment[idx];
}
@@ -135,7 +136,7 @@ struct SevenSegDigit
// access elements in order by index rather than R,G,B
// see static Count for the number of elements
// ------------------------------------------------------------------------
uint8_t& operator[](size_t idx)
ElementType& operator[](size_t idx)
{
return Segment[idx];
}
@@ -144,7 +145,7 @@ struct SevenSegDigit
// CalculateBrightness will calculate the overall brightness
// NOTE: This is a simple linear brightness
// ------------------------------------------------------------------------
uint8_t CalculateBrightness() const;
ElementType CalculateBrightness() const;
// ------------------------------------------------------------------------
// Dim will return a new SevenSegDigit that is blended to off with the given ratio
@@ -152,7 +153,7 @@ struct SevenSegDigit
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
SevenSegDigit Dim(uint8_t ratio) const;
SevenSegDigit Dim(ElementType ratio) const;
// ------------------------------------------------------------------------
// Brighten will return a new SevenSegDigit that is blended to full bright with the given ratio
@@ -160,21 +161,21 @@ struct SevenSegDigit
//
// NOTE: This is a simple linear blend
// ------------------------------------------------------------------------
SevenSegDigit Brighten(uint8_t ratio) const;
SevenSegDigit Brighten(ElementType ratio) const;
// ------------------------------------------------------------------------
// Darken will adjust the color by the given delta toward black
// NOTE: This is a simple linear change
// delta - (0-255) the amount to dim the segment
// ------------------------------------------------------------------------
void Darken(uint8_t delta);
void Darken(ElementType delta);
// ------------------------------------------------------------------------
// Lighten will adjust the color by the given delta toward white
// NOTE: This is a simple linear change
// delta - (0-255) the amount to lighten the segment
// ------------------------------------------------------------------------
void Lighten(uint8_t delta);
void Lighten(ElementType delta);
// ------------------------------------------------------------------------
// LinearBlend between two colors by the amount defined by progress variable
@@ -210,8 +211,8 @@ struct SevenSegDigit
static void SetString(T_SET_TARGET& target,
uint16_t indexDigit,
const char* str,
uint8_t brightness,
uint8_t defaultBrightness = 0)
ElementType brightness,
ElementType defaultBrightness = 0)
{
if (str == nullptr)
{
@@ -287,10 +288,13 @@ struct SevenSegDigit
// segment members (0-255) where each represents the segment location
// and the value defines the brightnes (0) is off and (255) is full brightness
// ------------------------------------------------------------------------
static const uint8_t Count = 9;
uint8_t Segment[Count];
const static ElementType Max = 255;
const static uint8_t Count = 9;
const static size_t Size = Count * sizeof(ElementType);
ElementType Segment[Count];
const static uint8_t Max = 255;
// segment decode maps from ascii relative first char in map to a bitmask of segments
//
@@ -300,14 +304,14 @@ struct SevenSegDigit
static const uint8_t DecodeSpecial[4]; // , - . /
protected:
void init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness);
void init(uint8_t bitmask, ElementType brightness, ElementType defaultBrightness);
inline static uint8_t _elementDim(uint8_t value, uint8_t ratio)
inline static ElementType _elementDim(ElementType value, ElementType ratio)
{
return (static_cast<uint16_t>(value) * (static_cast<uint16_t>(ratio) + 1)) >> 8;
}
inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio)
inline static ElementType _elementBrighten(ElementType value, ElementType ratio)
{
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);

View File

@@ -28,43 +28,19 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
class DotStarL4Feature :
public NeoByteElements<4, RgbwColor, uint32_t>
public NeoElementsBase<4, RgbwColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111
*p++ = color[V_IC_1];
*p++ = color[V_IC_2];
*p = color[V_IC_3];
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color.W = (*p++) & 0x1F; // mask out upper three bits
color[V_IC_1] = *p++;
color[V_IC_2] = *p++;
color[V_IC_3] = *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[V_IC_1] = pgm_read_byte(p++);
color[V_IC_2] = pgm_read_byte(p++);
color[V_IC_3] = pgm_read_byte(p);
return color;
}
};

View File

@@ -28,43 +28,19 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
class DotStarX4Feature :
public NeoByteElements<4, RgbColor, uint32_t>
public NeoElementsBase<4, RgbColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = 0xff; // upper three bits are always 111 and brightness at max
*p++ = color[V_IC_1];
*p++ = color[V_IC_2];
*p = color[V_IC_3];
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
p++; // ignore the first byte
color[V_IC_1] = *p++;
color[V_IC_2] = *p++;
color[V_IC_3] = *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);
p++; // ignore the first byte
color[V_IC_1] = pgm_read_byte(p++);
color[V_IC_2] = pgm_read_byte(p++);
color[V_IC_3] = pgm_read_byte(p);
return color;
}
};

View File

@@ -28,47 +28,20 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
class Neo2Byte555Feature :
public NeoByteElements<2, RgbColor, uint16_t>
public NeoElementsBase<2, RgbColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
uint16_t color555;
encodePixel(&color555, color);
*p++ = color555 >> 8;
*p = color555 & 0xff;
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
uint16_t color555;
color555 = ((*p++) << 8);
color555 |= (*p);
decodePixel(&color, color555);
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);
uint16_t color555;
color555 = (pgm_read_byte(p++) << 8);
color555 |= pgm_read_byte(p);
decodePixel(&color, color555);
return color;
}
protected:

View File

@@ -28,40 +28,18 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
class Neo3Byte777Feature :
public NeoByteElements<3, RgbColor, uint8_t>
public NeoElementsBase<3, RgbColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = (color[V_IC_1] >> 1) | 0x80;
*p++ = (color[V_IC_2] >> 1) | 0x80;
*p = (color[V_IC_3] >> 1) | 0x80;
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color[V_IC_1] = (*p++) << 1;
color[V_IC_2] = (*p++) << 1;
color[V_IC_3] = (*p) << 1;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel);
color[V_IC_1] = (pgm_read_byte(p++)) << 1;
color[V_IC_2] = (pgm_read_byte(p++)) << 1;
color[V_IC_3] = (pgm_read_byte(p)) << 1;
return color;
}
};

View File

@@ -28,7 +28,7 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
class Neo3ByteFeature :
public NeoByteElements<3, RgbColor, uint8_t>
public NeoElementsBase<3, RgbColor>
{
public:
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)

View File

@@ -28,7 +28,7 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
class Neo3WordFeature :
public NeoWordElements<6, Rgb48Color, uint16_t>
public NeoElementsBase<6, Rgb48Color>
{
public:
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)

View File

@@ -28,42 +28,19 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4>
class Neo4ByteFeature :
public NeoByteElements<4, RgbwColor, uint32_t>
public NeoElementsBase<4, RgbwColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = color[V_IC_1];
*p++ = color[V_IC_2];
*p++ = color[V_IC_3];
*p = color[V_IC_4];
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color[V_IC_1] = *p++;
color[V_IC_2] = *p++;
color[V_IC_3] = *p++;
color[V_IC_4] = *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel);
color[V_IC_1] = pgm_read_byte(p++);
color[V_IC_2] = pgm_read_byte(p++);
color[V_IC_3] = pgm_read_byte(p++);
color[V_IC_4] = pgm_read_byte(p);
return color;
}
};

View File

@@ -28,10 +28,10 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4>
class Neo4WordFeature :
public NeoWordElements<8, Rgbw64Color, uint32_t>
public NeoElementsBase<8, Rgbw64Color>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
@@ -45,38 +45,4 @@ public:
*p++ = color[V_IC_4] >> 8;
*p = color[V_IC_4] & 0xff;
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
// due to endianness the byte order must be copied to output
color[V_IC_1] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_1] |= *p++;
color[V_IC_2] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_2] |= *p++;
color[V_IC_3] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_3] |= *p++;
color[V_IC_4] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_4] |= *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel));
// PROGMEM unit of storage expected to be the same size as color element
// so no endianness issues to worry about
color[V_IC_1] = pgm_read_word(p++);
color[V_IC_2] = pgm_read_word(p++);
color[V_IC_3] = pgm_read_word(p++);
color[V_IC_4] = pgm_read_word(p);
return color;
}
};

View File

@@ -28,12 +28,14 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4, uint8_t V_IC_5>
class Neo5ByteFeature :
public NeoByteElements<5, RgbwwColor, uint8_t>
public NeoElementsBase<5, RgbwwColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = color[V_IC_1];
*p++ = color[V_IC_2];
@@ -41,32 +43,5 @@ public:
*p++ = color[V_IC_4];
*p = color[V_IC_5];
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color[V_IC_1] = *p++;
color[V_IC_2] = *p++;
color[V_IC_3] = *p++;
color[V_IC_4] = *p++;
color[V_IC_5] = *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel);
color[V_IC_1] = pgm_read_byte(p++);
color[V_IC_2] = pgm_read_byte(p++);
color[V_IC_3] = pgm_read_byte(p++);
color[V_IC_4] = pgm_read_byte(p++);
color[V_IC_5] = pgm_read_byte(p);
return color;
}
};

View File

@@ -28,12 +28,14 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4, uint8_t V_IC_5>
class Neo5WordFeature :
public NeoWordElements<10, Rgbww80Color, uint16_t>
public NeoElementsBase<10, Rgbww80Color>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
// due to endianness the byte order must be copied to output
*p++ = color[V_IC_1] >> 8;
@@ -47,41 +49,5 @@ public:
*p++ = color[V_IC_5] >> 8;
*p = color[V_IC_5] & 0xff;
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
// due to endianness the byte order must be copied to output
color[V_IC_1] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_1] |= *p++;
color[V_IC_2] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_2] |= *p++;
color[V_IC_3] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_3] |= *p++;
color[V_IC_4] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_4] |= *p++;
color[V_IC_5] = (static_cast<uint16_t>(*p++) << 8);
color[V_IC_5] |= *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel));
// PROGMEM unit of storage expected to be the same size as color element
// so no endianness issues to worry about
color[V_IC_1] = pgm_read_word(p++);
color[V_IC_2] = pgm_read_word(p++);
color[V_IC_3] = pgm_read_word(p++);
color[V_IC_4] = pgm_read_word(p++);
color[V_IC_5] = pgm_read_word(p);
return color;
}
};

View File

@@ -28,12 +28,14 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4, uint8_t V_IC_5, uint8_t V_IC_6>
class Neo6ByteFeature :
public NeoByteElements<6, RgbwwwColor, uint16_t>
public NeoElementsBase<6, RgbwwwColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = color[V_IC_1];
*p++ = color[V_IC_2];
@@ -42,34 +44,5 @@ public:
*p++ = color[V_IC_5];
*p = color[V_IC_6];
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color[V_IC_1] = *p++;
color[V_IC_2] = *p++;
color[V_IC_3] = *p++;
color[V_IC_4] = *p++;
color[V_IC_5] = *p++;
color[V_IC_6] = *p;
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel);
color[V_IC_1] = pgm_read_byte(p++);
color[V_IC_2] = pgm_read_byte(p++);
color[V_IC_3] = pgm_read_byte(p++);
color[V_IC_4] = pgm_read_byte(p++);
color[V_IC_5] = pgm_read_byte(p++);
color[V_IC_6] = pgm_read_byte(p);
return color;
}
};

View File

@@ -28,12 +28,14 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4, uint8_t V_IC_5>
class Neo6xByteFeature :
public NeoByteElements<6, RgbwwColor, uint16_t>
public NeoElementsBase<6, RgbwwColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = color[V_IC_1];
*p++ = color[V_IC_2];
@@ -43,34 +45,5 @@ public:
*p = 0x00; // X
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color[V_IC_1] = *p++;
color[V_IC_2] = *p++;
color[V_IC_3] = *p++;
color[V_IC_4] = *p++;
color[V_IC_5] = *p;
// ignore the x
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel);
color[V_IC_1] = pgm_read_byte(p++);
color[V_IC_2] = pgm_read_byte(p++);
color[V_IC_3] = pgm_read_byte(p++);
color[V_IC_4] = pgm_read_byte(p++);
color[V_IC_5] = pgm_read_byte(p);
// ignore the x
return color;
}
};

View File

@@ -28,12 +28,14 @@ License along with NeoPixel. If not, see
template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4>
class Neo6xxByteFeature :
public NeoByteElements<6, RgbwColor, uint16_t>
public NeoElementsBase<6, RgbwColor>
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = color[V_IC_1];
*p++ = color[V_IC_2];
@@ -43,31 +45,5 @@ public:
*p++ = 0x00;
*p = 0x00; // X
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color[V_IC_1] = *p++;
color[V_IC_2] = *p++;
color[V_IC_3] = *p++;
color[V_IC_4] = *p;
// ignore the xx
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel);
color[V_IC_1] = pgm_read_byte(p++);
color[V_IC_2] = pgm_read_byte(p++);
color[V_IC_3] = pgm_read_byte(p++);
color[V_IC_4] = pgm_read_byte(p);
// ignore the xx
return color;
}
};

View File

@@ -28,45 +28,21 @@ License along with NeoPixel. If not, see
// Abcdefgps byte order
class NeoAbcdefgpsSegmentFeature :
public NeoByteElements<9, SevenSegDigit, uint8_t>,
public NeoElementsBase<9, SevenSegDigit>,
public NeoElementsNoSettings
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count;
for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++)
{
*p++ = color.Segment[iSegment];
}
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count;
for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++)
{
color.Segment[iSegment] = *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);
uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count;
for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++)
{
color.Segment[iSegment] = pgm_read_byte(p++);
}
return color;
}
};

View File

@@ -28,13 +28,15 @@ License along with NeoPixel. If not, see
// BACEDF.G+ byte order
class NeoBacedfpgsSegmentFeature :
public NeoByteElements<9, SevenSegDigit, uint8_t>,
public NeoElementsBase<9, SevenSegDigit>,
public NeoElementsNoSettings
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
// Segment Digit is Abcdefgps order
*p++ = color.Segment[LedSegment_B];
@@ -49,45 +51,5 @@ public:
*p++ = color.Segment[LedSegment_G];
*p++ = color.Segment[LedSegment_Custom];
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color.Segment[LedSegment_B] = *p++;
color.Segment[LedSegment_A] = *p++;
color.Segment[LedSegment_C] = *p++;
color.Segment[LedSegment_E] = *p++;
color.Segment[LedSegment_D] = *p++;
color.Segment[LedSegment_F] = *p++;
color.Segment[LedSegment_Decimal] = *p++;
color.Segment[LedSegment_G] = *p++;
color.Segment[LedSegment_Custom] = *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.Segment[LedSegment_B] = pgm_read_byte(p++);
color.Segment[LedSegment_A] = pgm_read_byte(p++);
color.Segment[LedSegment_C] = pgm_read_byte(p++);
color.Segment[LedSegment_E] = pgm_read_byte(p++);
color.Segment[LedSegment_D] = pgm_read_byte(p++);
color.Segment[LedSegment_F] = pgm_read_byte(p++);
color.Segment[LedSegment_Decimal] = pgm_read_byte(p++);
color.Segment[LedSegment_G] = pgm_read_byte(p++);
color.Segment[LedSegment_Custom] = pgm_read_byte(p++);
return color;
}
};

View File

@@ -32,108 +32,14 @@ License along with NeoPixel. If not, see
//
// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream
// T_COLOR_OBJECT - the primary color object used to represent a pixel
// T_COPY - (uint8_t/uint16_t/uint32_t) the base type to use when copying/moving
template<size_t V_PIXEL_SIZE, typename T_COLOR_OBJECT, typename T_COPY>
template<size_t V_PIXEL_SIZE, typename T_COLOR_OBJECT>
class NeoElementsBase
{
public:
static const size_t PixelSize = V_PIXEL_SIZE;
typedef T_COLOR_OBJECT ColorObject;
static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel)
{
return pPixels + indexPixel * PixelSize;
}
static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel)
{
return pPixels + indexPixel * PixelSize;
}
static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
T_COPY* pDest = reinterpret_cast<T_COPY*>(pPixelDest);
T_COPY* pEnd = pDest + (count * PixelSize / sizeof(T_COPY));
const T_COPY* pEndSrc = reinterpret_cast<const T_COPY*>(pPixelSrc) + PixelSize / sizeof(T_COPY);
while (pDest < pEnd)
{
const T_COPY* pSrc = reinterpret_cast<const T_COPY*>(pPixelSrc);
while (pSrc < pEndSrc)
{
*pDest++ = *pSrc++;
}
}
}
static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
const T_COPY* pSrc = reinterpret_cast<const T_COPY*>(pPixelSrc);
T_COPY* pDest = reinterpret_cast<T_COPY*>(pPixelDest);
T_COPY* pEnd = pDest + (count * PixelSize / sizeof(T_COPY));
while (pDest < pEnd)
{
*pDest++ = *pSrc++;
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
const T_COPY* pSrc = reinterpret_cast<const T_COPY*>(pPixelSrc);
const T_COPY* pSrcBack = pSrc + (count * PixelSize / sizeof(T_COPY));
T_COPY* pDest = reinterpret_cast<T_COPY*>(pPixelDest);
T_COPY* pDestBack = pDest + (count * PixelSize / sizeof(T_COPY));
while (pDestBack > pDest)
{
*--pDestBack = *--pSrcBack;
}
}
};
// NeoByteElements is used for 8bit color element types and less
//
// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream
// T_COLOR_OBJECT - the primary color object used to represent a pixel
// T_COPY - (uint8_t/uint16_t/uint32_t) the base type to use when copying/moving
template<size_t V_PIXEL_SIZE, typename T_COLOR_OBJECT, typename T_COPY>
class NeoByteElements : public NeoElementsBase<V_PIXEL_SIZE, T_COLOR_OBJECT, T_COPY>
{
public:
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint8_t* pEnd = pPixelDest + (count * NeoElementsBase<V_PIXEL_SIZE, T_COLOR_OBJECT, T_COPY>::PixelSize);
const uint8_t* pSrc = reinterpret_cast<const uint8_t*>(pPixelSrc);
while (pPixelDest < pEnd)
{
*pPixelDest++ = pgm_read_byte(pSrc++);
}
}
};
// NeoWordElements is used for 16bit color element types
//
// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream
// T_COLOR_OBJECT - the primary color object used to represent a pixel
// T_COPY - (uint16_t/uint32_t) the base type to use when copying/moving
template<size_t V_PIXEL_SIZE, typename T_COLOR_OBJECT, typename T_COPY>
class NeoWordElements : public NeoElementsBase<V_PIXEL_SIZE, T_COLOR_OBJECT, T_COPY>
{
public:
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint16_t* pDest = reinterpret_cast<uint16_t*>(pPixelDest);
uint16_t* pEnd = pDest + (count * NeoElementsBase<V_PIXEL_SIZE, T_COLOR_OBJECT, T_COPY>::PixelSize / sizeof(uint16_t));
const uint16_t* pSrc = reinterpret_cast<const uint16_t*>(pPixelSrc);
while (pDest < pEnd)
{
*pDest++ = pgm_read_word(pSrc++);
}
}
};

View File

@@ -135,22 +135,19 @@ public:
typedef T_SETTINGS SettingsObject;
static const size_t SettingsSize = 2;
static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
static bool applyFrontSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
return false;
}
static bool applyBackSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// settings are at the end of the data stream
uint8_t* pDest = pData + sizeData - SettingsSize;
settings.Encode(pDest);
}
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
if (SettingsSize <= sizeData)
{
return pData;
settings.Encode(pData);
}
static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
{
return pData;
return true;
}
};

View File

@@ -149,23 +149,21 @@ public:
typedef T_SETTINGS SettingsObject;
static const size_t SettingsSize = 2;
static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
static bool applyFrontSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
return false;
}
static bool applyBackSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// settings are at the end of the data stream
uint8_t* pDest = pData + sizeData - SettingsSize;
settings.Encode(pDest);
}
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
if (SettingsSize <= sizeData)
{
return pData;
settings.Encode(pData);
}
return true;
}
static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
{
return pData;
}
};
typedef NeoRgbwSm168x4Elements<NeoSm16804ebSettings<ColorIndexR, ColorIndexG, ColorIndexB, ColorIndexW>> NeoRgbwSm16804ebFeature;

View File

@@ -61,9 +61,11 @@ public:
typedef NeoTm1814Settings SettingsObject;
static const size_t SettingsSize = 8;
static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
static bool applyFrontSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// settings are at the front of the data stream
if (SettingsSize <= sizeData)
{
uint8_t* pSet = pData;
// C1
@@ -80,17 +82,12 @@ public:
*pSet++ = ~(*pC1++);
}
}
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
{
// settings are at the front of the data stream
return pData + SettingsSize;
return true;
}
static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
static bool applyBackSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// settings are at the front of the data stream
return pData + SettingsSize;
return false;
}
};

View File

@@ -50,9 +50,11 @@ public:
typedef NeoTm1914Settings SettingsObject;
static const size_t SettingsSize = 6;
static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
static bool applyFrontSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// settings are at the front of the data stream
if (SettingsSize <= sizeData)
{
uint8_t* pSet = pData;
uint8_t mode = 0xff;
@@ -84,17 +86,12 @@ public:
*pSet++ = ~(*pC1++);
}
}
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
{
// settings are at the front of the data stream
return pData + SettingsSize;
return true;
}
static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
static bool applyBackSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// settings are at the front of the data stream
return pData + SettingsSize;
return false;
}
};

View File

@@ -28,46 +28,22 @@ License along with NeoPixel. If not, see
class P9813BgrFeature :
public NeoByteElements<4, RgbColor, uint32_t>,
public NeoElementsBase<4, RgbColor>,
public NeoElementsNoSettings
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
if (PixelSize <= pixelSize)
{
uint8_t* p = pixel;
*p++ = 0xC0 | ((~color.B & 0xC0) >> 2) | ((~color.G & 0xC0) >> 4) | ((~color.R & 0xC0) >> 6);
*p++ = color.B;
*p++ = color.G;
*p = color.R;
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
p++; // ignore the first byte
color.B = *p++;
color.G = *p++;
color.R = *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);
p++; // ignore the first byte
color.B = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p);
return color;
}
};

View File

@@ -97,8 +97,6 @@ class Tlc59711ElementsSettings
{
public:
typedef Tlc69711Settings SettingsObject;
static constexpr size_t SettingsSize = Tlc69711Settings::c_settingsPerChipSize;
static void Encode(uint8_t* encoded, const SettingsObject& settings)
@@ -111,7 +109,7 @@ public:
*encoded = settings.GreenGroupBrightness << 7 | settings.RedGroupBrightness;
}
static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
static bool applyFrontSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// how the hell do we store the setting that doesn't go into the data stream'
// Thought A:
@@ -139,20 +137,17 @@ public:
// have the method know details how to duplicate it if needed for emi
// as it already neeeds to interleaving settings per chip with data
if (SettingsSize <= sizeData)
{
// settings are at the front of the data stream
Encode(pData, settings);
}
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
{
// settings are at the front of the data stream
return pData + SettingsSize;
return true;
}
static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
static bool applyBackSettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
// settings are at the front of the data stream
return pData + SettingsSize;
return false;
}
private: