forked from Makuna/NeoPixelBus
minor missing methods (#670)
This commit is contained in:
@@ -66,6 +66,16 @@ struct Rgb16Color : RgbColorBase
|
||||
{
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a Rgb16Color using RgbCOlor
|
||||
// ------------------------------------------------------------------------
|
||||
Rgb16Color(const RgbColor& color)
|
||||
{
|
||||
setR(color.R);
|
||||
setG(color.G);
|
||||
setB(color.B);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a Rgb16Color using HtmlColor
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -143,6 +153,23 @@ struct Rgb16Color : RgbColorBase
|
||||
return (Color565 & 0x001f) << 3;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// operator [] - readonly
|
||||
// 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
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
return getR();
|
||||
case 1:
|
||||
return getG();
|
||||
default:
|
||||
return getB();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Comparison operators
|
||||
@@ -281,5 +308,8 @@ struct Rgb16Color : RgbColorBase
|
||||
};
|
||||
|
||||
uint16_t Color565;
|
||||
|
||||
const static uint8_t Max = 255;
|
||||
const static size_t Count = 3; // three elements in []
|
||||
};
|
||||
|
||||
|
@@ -120,6 +120,28 @@ uint8_t SevenSegDigit::CalculateBrightness() const
|
||||
return static_cast<uint8_t>(sum / Count);
|
||||
}
|
||||
|
||||
SevenSegDigit SevenSegDigit::Dim(uint8_t ratio) const
|
||||
{
|
||||
SevenSegDigit result;
|
||||
|
||||
for (uint8_t iSegment = 0; iSegment < Count; iSegment++)
|
||||
{
|
||||
result.Segment[iSegment] = _elementDim(Segment[iSegment], ratio);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SevenSegDigit SevenSegDigit::Brighten(uint8_t ratio) const
|
||||
{
|
||||
SevenSegDigit result;
|
||||
|
||||
for (uint8_t iSegment = 0; iSegment < Count; iSegment++)
|
||||
{
|
||||
result.Segment[iSegment] = _elementBrighten(Segment[iSegment], ratio);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SevenSegDigit::Darken(uint8_t delta)
|
||||
{
|
||||
for (uint8_t iSegment = 0; iSegment < Count; iSegment++)
|
||||
|
@@ -146,6 +146,22 @@ struct SevenSegDigit
|
||||
// ------------------------------------------------------------------------
|
||||
uint8_t CalculateBrightness() const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Dim will return a new SevenSegDigit that is blended to off with the given ratio
|
||||
// ratio - (0-255) where 255 will return the original brightness and 0 will return off
|
||||
//
|
||||
// NOTE: This is a simple linear blend
|
||||
// ------------------------------------------------------------------------
|
||||
SevenSegDigit Dim(uint8_t ratio) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Brighten will return a new SevenSegDigit that is blended to full bright with the given ratio
|
||||
// ratio - (0-255) where 255 will return the original brightness and 0 will return full brightness
|
||||
//
|
||||
// NOTE: This is a simple linear blend
|
||||
// ------------------------------------------------------------------------
|
||||
SevenSegDigit Brighten(uint8_t ratio) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Darken will adjust the color by the given delta toward black
|
||||
// NOTE: This is a simple linear change
|
||||
@@ -285,5 +301,25 @@ struct SevenSegDigit
|
||||
|
||||
protected:
|
||||
void init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness);
|
||||
|
||||
inline static uint8_t _elementDim(uint8_t value, uint8_t 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)
|
||||
{
|
||||
uint16_t element = ((static_cast<uint16_t>(value) + 1) << 8) / (static_cast<uint16_t>(ratio) + 1);
|
||||
|
||||
if (element > Max)
|
||||
{
|
||||
element = Max;
|
||||
}
|
||||
else
|
||||
{
|
||||
element -= 1;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user