forked from Makuna/NeoPixelBus
Rgbwww (#756)
This commit is contained in:
@ -38,6 +38,7 @@ License along with NeoPixel. If not, see
|
||||
#include "features/Neo4ByteFeature.h"
|
||||
#include "features/DotStarX4ByteFeature.h"
|
||||
#include "features/DotStarL4ByteFeature.h"
|
||||
#include "features/Neo6ByteFeature.h"
|
||||
#include "features/Neo6xByteFeature.h"
|
||||
#include "features/Neo6xxByteFeature.h"
|
||||
#include "features/Neo3WordFeature.h"
|
||||
@ -53,6 +54,7 @@ License along with NeoPixel. If not, see
|
||||
|
||||
#include "features/NeoRgbwxxFeatures.h"
|
||||
#include "features/NeoRgbcwxFeatures.h"
|
||||
#include "features/NeoRgbwwwFeatures.h"
|
||||
#include "features/NeoSm168x3Features.h"
|
||||
#include "features/NeoSm168x4Features.h"
|
||||
#include "features/NeoSm168x5Features.h"
|
||||
|
@ -45,6 +45,8 @@ License along with NeoPixel. If not, see
|
||||
#include "colors/RgbwwColor.h"
|
||||
#include "colors/Rgbww80Color.h"
|
||||
|
||||
#include "colors/RgbwwwColor.h"
|
||||
|
||||
#include "colors/SegmentDigit.h"
|
||||
|
||||
#include "colors/NeoGamma.h"
|
||||
|
@ -135,4 +135,48 @@ public:
|
||||
const uint16_t BlueTenthMilliAmpere; // in 1/10th ma
|
||||
const uint16_t WarmWhiteTenthMilliAmpere; // in 1/10th ma
|
||||
const uint16_t CoolWhiteTenthMilliAmpere; // in 1/10th ma
|
||||
};
|
||||
|
||||
class NeoRgbwwwCurrentSettings
|
||||
{
|
||||
public:
|
||||
NeoRgbwwwCurrentSettings(uint16_t red, uint16_t green, uint16_t blue, uint16_t white1, uint16_t white2, uint16_t white3) :
|
||||
RedTenthMilliAmpere(red),
|
||||
GreenTenthMilliAmpere(green),
|
||||
BlueTenthMilliAmpere(blue),
|
||||
W1TenthMilliAmpere(white1),
|
||||
W2TenthMilliAmpere(white2),
|
||||
W3TenthMilliAmpere(white3)
|
||||
{
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// operator [] - readonly
|
||||
// access elements in order by index rather than member name
|
||||
// ------------------------------------------------------------------------
|
||||
uint16_t operator[](size_t idx) const
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
return RedTenthMilliAmpere;
|
||||
case 1:
|
||||
return GreenTenthMilliAmpere;
|
||||
case 2:
|
||||
return BlueTenthMilliAmpere;
|
||||
case 3:
|
||||
return W1TenthMilliAmpere;
|
||||
case 4:
|
||||
return W2TenthMilliAmpere;
|
||||
default:
|
||||
return W3TenthMilliAmpere;
|
||||
}
|
||||
}
|
||||
|
||||
const uint16_t RedTenthMilliAmpere; // in 1/10th ma
|
||||
const uint16_t GreenTenthMilliAmpere; // in 1/10th ma
|
||||
const uint16_t BlueTenthMilliAmpere; // in 1/10th ma
|
||||
const uint16_t W1TenthMilliAmpere; // in 1/10th ma
|
||||
const uint16_t W2TenthMilliAmpere; // in 1/10th ma
|
||||
const uint16_t W3TenthMilliAmpere; // in 1/10th ma
|
||||
};
|
@ -84,6 +84,16 @@ public:
|
||||
T_METHOD::Correct(original.WW),
|
||||
T_METHOD::Correct(original.CW));
|
||||
}
|
||||
|
||||
static RgbwwwColor Correct(const RgbwwwColor& original)
|
||||
{
|
||||
return RgbwwwColor(T_METHOD::Correct(original.R),
|
||||
T_METHOD::Correct(original.G),
|
||||
T_METHOD::Correct(original.B),
|
||||
T_METHOD::Correct(original.W1),
|
||||
T_METHOD::Correct(original.W2),
|
||||
T_METHOD::Correct(original.W3));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -33,4 +33,6 @@ const uint8_t ColorIndexB = 2;
|
||||
const uint8_t ColorIndexW = 3;
|
||||
const uint8_t ColorIndexWW = 3; // warmer white
|
||||
const uint8_t ColorIndexCW = 4; // cooler white
|
||||
const uint8_t ColorIndexY = 4;
|
||||
const uint8_t ColorIndexW1 = 3;
|
||||
const uint8_t ColorIndexW2 = 4;
|
||||
const uint8_t ColorIndexW3 = 5;
|
||||
|
253
src/internal/colors/RgbwwwColor.cpp
Normal file
253
src/internal/colors/RgbwwwColor.cpp
Normal file
@ -0,0 +1,253 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
RgbwwwColor provides a color object that can be directly consumed by NeoPixelBus
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "../NeoSettings.h"
|
||||
#include "RgbColorBase.h"
|
||||
#include "RgbColor.h"
|
||||
#include "RgbwColor.h"
|
||||
#include "Rgb48Color.h"
|
||||
#include "HslColor.h"
|
||||
#include "HsbColor.h"
|
||||
#include "HtmlColor.h"
|
||||
|
||||
#include "RgbwwwColor.h"
|
||||
|
||||
RgbwwwColor::RgbwwwColor(const HtmlColor& color)
|
||||
{
|
||||
uint32_t temp = color.Color;
|
||||
B = (temp & 0xff);
|
||||
temp = temp >> 8;
|
||||
G = (temp & 0xff);
|
||||
temp = temp >> 8;
|
||||
R = (temp & 0xff);
|
||||
temp = temp >> 8;
|
||||
W1 = (temp & 0xff);
|
||||
W2 = W1;
|
||||
W3 = W1;
|
||||
};
|
||||
|
||||
RgbwwwColor::RgbwwwColor(const HslColor& color)
|
||||
{
|
||||
RgbColor rgbColor(color);
|
||||
*this = rgbColor;
|
||||
}
|
||||
|
||||
RgbwwwColor::RgbwwwColor(const HsbColor& color)
|
||||
{
|
||||
RgbColor rgbColor(color);
|
||||
*this = rgbColor;
|
||||
}
|
||||
|
||||
uint8_t 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);
|
||||
|
||||
return (whiteB > colorB) ? whiteB : colorB;
|
||||
}
|
||||
|
||||
RgbwwwColor RgbwwwColor::Dim(uint8_t ratio) const
|
||||
{
|
||||
// specifically avoids float math
|
||||
return RgbwwwColor(_elementDim(R, ratio),
|
||||
_elementDim(G, ratio),
|
||||
_elementDim(B, ratio),
|
||||
_elementDim(W1, ratio),
|
||||
_elementDim(W2, ratio),
|
||||
_elementDim(W3, ratio));
|
||||
}
|
||||
|
||||
RgbwwwColor RgbwwwColor::Brighten(uint8_t ratio) const
|
||||
{
|
||||
// specifically avoids float math
|
||||
return RgbwwwColor(_elementBrighten(R, ratio),
|
||||
_elementBrighten(G, ratio),
|
||||
_elementBrighten(B, ratio),
|
||||
_elementBrighten(W1, ratio),
|
||||
_elementBrighten(W2, ratio),
|
||||
_elementBrighten(W3, ratio));
|
||||
}
|
||||
|
||||
void RgbwwwColor::Darken(uint8_t delta)
|
||||
{
|
||||
if (R > delta)
|
||||
{
|
||||
R -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
R = 0;
|
||||
}
|
||||
|
||||
if (G > delta)
|
||||
{
|
||||
G -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
G = 0;
|
||||
}
|
||||
|
||||
if (B > delta)
|
||||
{
|
||||
B -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = 0;
|
||||
}
|
||||
|
||||
if (W1 > delta)
|
||||
{
|
||||
W1 -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
W1 = 0;
|
||||
}
|
||||
|
||||
if (W2 > delta)
|
||||
{
|
||||
W2 -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
W2 = 0;
|
||||
}
|
||||
|
||||
if (W3 > delta)
|
||||
{
|
||||
W3 -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
W3 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RgbwwwColor::Lighten(uint8_t delta)
|
||||
{
|
||||
if (IsColorLess())
|
||||
{
|
||||
if (W1 < Max - delta)
|
||||
{
|
||||
W1 += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
W1 = Max;
|
||||
}
|
||||
|
||||
if (W2 < Max - delta)
|
||||
{
|
||||
W2 += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
W2 = Max;
|
||||
}
|
||||
|
||||
if (W3 < Max - delta)
|
||||
{
|
||||
W3 += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
W3 = Max;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (R < Max - delta)
|
||||
{
|
||||
R += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
R = Max;
|
||||
}
|
||||
|
||||
if (G < Max - delta)
|
||||
{
|
||||
G += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
G = Max;
|
||||
}
|
||||
|
||||
if (B < Max - delta)
|
||||
{
|
||||
B += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = Max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RgbwwwColor RgbwwwColor::LinearBlend(const RgbwwwColor& left, const RgbwwwColor& right, float progress)
|
||||
{
|
||||
return RgbwwwColor( left.R + ((static_cast<int16_t>(right.R) - left.R) * progress),
|
||||
left.G + ((static_cast<int16_t>(right.G) - left.G) * progress),
|
||||
left.B + ((static_cast<int16_t>(right.B) - left.B) * progress),
|
||||
left.W1 + ((static_cast<int16_t>(right.W1) - left.W1) * progress),
|
||||
left.W2 + ((static_cast<int16_t>(right.W2) - left.W2) * progress),
|
||||
left.W3 + ((static_cast<int16_t>(right.W3) - left.W3) * progress));
|
||||
}
|
||||
|
||||
RgbwwwColor RgbwwwColor::LinearBlend(const RgbwwwColor& left, const RgbwwwColor& right, uint8_t progress)
|
||||
{
|
||||
return RgbwwwColor(left.R + (((static_cast<int32_t>(right.R) - left.R) * static_cast<int32_t>(progress) + 1) >> 8),
|
||||
left.G + (((static_cast<int32_t>(right.G) - left.G) * static_cast<int32_t>(progress) + 1) >> 8),
|
||||
left.B + (((static_cast<int32_t>(right.B) - left.B) * static_cast<int32_t>(progress) + 1) >> 8),
|
||||
left.W1 + (((static_cast<int32_t>(right.W1) - left.W1) * static_cast<int32_t>(progress) + 1) >> 8),
|
||||
left.W2 + (((static_cast<int32_t>(right.W2) - left.W2) * static_cast<int32_t>(progress) + 1) >> 8),
|
||||
left.W3 + (((static_cast<int32_t>(right.W3) - left.W3) * static_cast<int32_t>(progress) + 1) >> 8));
|
||||
}
|
||||
|
||||
RgbwwwColor RgbwwwColor::BilinearBlend(const RgbwwwColor& c00,
|
||||
const RgbwwwColor& c01,
|
||||
const RgbwwwColor& c10,
|
||||
const RgbwwwColor& c11,
|
||||
float x,
|
||||
float y)
|
||||
{
|
||||
float v00 = (1.0f - x) * (1.0f - y);
|
||||
float v10 = x * (1.0f - y);
|
||||
float v01 = (1.0f - x) * y;
|
||||
float v11 = x * y;
|
||||
|
||||
return RgbwwwColor(
|
||||
c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11,
|
||||
c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11,
|
||||
c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11,
|
||||
c00.W1 * v00 + c10.W1 * v10 + c01.W1 * v01 + c11.W1 * v11,
|
||||
c00.W2 * v00 + c10.W2 * v10 + c01.W2 * v01 + c11.W2 * v11,
|
||||
c00.W3 * v00 + c10.W3 * v10 + c01.W3 * v01 + c11.W3 * v11);
|
||||
}
|
367
src/internal/colors/RgbwwwColor.h
Normal file
367
src/internal/colors/RgbwwwColor.h
Normal file
@ -0,0 +1,367 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
RgbwwwColor provides a color object that can be directly consumed by NeoPixelBus
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
struct RgbColor;
|
||||
struct HslColor;
|
||||
struct HsbColor;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// RgbwwwColor represents a color object that is represented by Red, Green, Blue
|
||||
// component values and three extra White components.
|
||||
// It contains helpful color routines to manipulate the color.
|
||||
// ------------------------------------------------------------------------
|
||||
struct RgbwwwColor : RgbColorBase
|
||||
{
|
||||
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) :
|
||||
R(r), G(g), B(b), W1(w1), W2(w2), W3(w3)
|
||||
{
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor using R, G, B, (0-255) and a single W (0-765)
|
||||
// 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) :
|
||||
R(r), G(g), B(b)
|
||||
{
|
||||
ApplyAsIncrementalWhite(w);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor using a single brightness value (0-255)
|
||||
// This works well for creating gray tone colors
|
||||
// (0) = black, (255) = white, (128) = gray
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor(uint8_t brightness) :
|
||||
R(0), G(0), B(0), W1(brightness), W2(brightness), W3(brightness)
|
||||
{
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor using RgbColor
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor(const RgbColor& color) :
|
||||
R(color.R),
|
||||
G(color.G),
|
||||
B(color.B),
|
||||
W1(0),
|
||||
W2(0),
|
||||
W3(0)
|
||||
{
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor using RgbwColor
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor(const RgbwColor& color) :
|
||||
R(color.R),
|
||||
G(color.G),
|
||||
B(color.B),
|
||||
W1(color.W),
|
||||
W2(color.W),
|
||||
W3(color.W)
|
||||
{
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor using HtmlColor
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor(const HtmlColor& color);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor using HslColor
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor(const HslColor& color);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor using HsbColor
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor(const HsbColor& color);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Construct a RgbwwwColor that will have its values set in latter operations
|
||||
// CAUTION: The R,G,B, W1, W2, W3 members are not initialized and may not be consistent
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor()
|
||||
{
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Comparison operators
|
||||
// ------------------------------------------------------------------------
|
||||
bool operator==(const RgbwwwColor& other) const
|
||||
{
|
||||
return (R == other.R && G == other.G && B == other.B && W1 == other.W1 && W2 == other.W2 && W3 == other.W3);
|
||||
};
|
||||
|
||||
bool operator!=(const RgbwwwColor& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// CompareTo method
|
||||
// compares against another color with the given epsilon (delta allowed)
|
||||
// returns the greatest difference of a set of elements,
|
||||
// 0 = equal within epsilon delta
|
||||
// negative - this is less than other
|
||||
// positive - this is greater than other
|
||||
// ------------------------------------------------------------------------
|
||||
int16_t CompareTo(const RgbwwwColor& other, uint8_t epsilon = 1)
|
||||
{
|
||||
return _Compare<RgbwwwColor, int16_t>(*this, other, epsilon);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Compare method
|
||||
// compares two colors with the given epsilon (delta allowed)
|
||||
// returns the greatest difference of a set of elements,
|
||||
// 0 = equal within epsilon delta
|
||||
// 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)
|
||||
{
|
||||
return _Compare<RgbwwwColor, int16_t>(left, right, epsilon);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// operator [] - readonly
|
||||
// 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
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
return R;
|
||||
case 1:
|
||||
return G;
|
||||
case 2:
|
||||
return B;
|
||||
case 3:
|
||||
return W1;
|
||||
case 4:
|
||||
return W2;
|
||||
default:
|
||||
return W3;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// operator [] - read write
|
||||
// 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)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
return R;
|
||||
case 1:
|
||||
return G;
|
||||
case 2:
|
||||
return B;
|
||||
case 3:
|
||||
return W1;
|
||||
case 4:
|
||||
return W2;
|
||||
default:
|
||||
return W3;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Returns if the color is grey, all values are equal other than whites
|
||||
// ------------------------------------------------------------------------
|
||||
bool IsMonotone() const
|
||||
{
|
||||
return (R == B && R == G);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Returns if the color components are all zero, the white components maybe
|
||||
// anything
|
||||
// ------------------------------------------------------------------------
|
||||
bool IsColorLess() const
|
||||
{
|
||||
return (R == 0 && B == 0 && G == 0);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// CalculateBrightness will calculate the overall brightness
|
||||
// NOTE: This is a simple linear brightness
|
||||
// ------------------------------------------------------------------------
|
||||
uint8_t CalculateBrightness() const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Dim will return a new color that is blended to black with the given ratio
|
||||
// ratio - (0-255) where 255 will return the original color and 0 will return black
|
||||
//
|
||||
// NOTE: This is a simple linear blend
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor Dim(uint8_t ratio) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Brighten will return a new color that is blended to white with the given ratio
|
||||
// ratio - (0-255) where 255 will return the original color and 0 will return white
|
||||
//
|
||||
// NOTE: This is a simple linear blend
|
||||
// ------------------------------------------------------------------------
|
||||
RgbwwwColor Brighten(uint8_t 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);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 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);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// LinearBlend between two colors by the amount defined by progress variable
|
||||
// left - the color to start the blend at
|
||||
// right - the color to end the blend at
|
||||
// progress - (0.0 - 1.0) value where 0 will return left and 1.0 will return right
|
||||
// and a value between will blend the color weighted linearly between them
|
||||
// ------------------------------------------------------------------------
|
||||
static RgbwwwColor LinearBlend(const RgbwwwColor& left, const RgbwwwColor& right, float progress);
|
||||
// progress - (0 - 255) value where 0 will return left and 255 will return right
|
||||
// and a value between will blend the color weighted linearly between them
|
||||
// ------------------------------------------------------------------------
|
||||
static RgbwwwColor LinearBlend(const RgbwwwColor& left, const RgbwwwColor& right, uint8_t progress);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// BilinearBlend between four colors by the amount defined by 2d variable
|
||||
// c00 - upper left quadrant color
|
||||
// c01 - upper right quadrant color
|
||||
// c10 - lower left quadrant color
|
||||
// c11 - lower right quadrant color
|
||||
// x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
|
||||
// y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
|
||||
// ------------------------------------------------------------------------
|
||||
static RgbwwwColor BilinearBlend(const RgbwwwColor& c00,
|
||||
const RgbwwwColor& c01,
|
||||
const RgbwwwColor& c10,
|
||||
const RgbwwwColor& c11,
|
||||
float x,
|
||||
float y);
|
||||
|
||||
uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings)
|
||||
{
|
||||
auto total = 0;
|
||||
|
||||
total += R * settings.RedTenthMilliAmpere / Max;
|
||||
total += G * settings.GreenTenthMilliAmpere / Max;
|
||||
total += B * settings.BlueTenthMilliAmpere / Max;
|
||||
total += W1 * settings.W1TenthMilliAmpere / Max;
|
||||
total += W2 * settings.W2TenthMilliAmpere / Max;
|
||||
total += W3 * settings.W3TenthMilliAmpere / Max;
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// White is set incrementally across the three whites,
|
||||
// white (0-765)
|
||||
// where 1 = (0,0,1), 2 = (0,1,1), 3 = (1,1,1), 4 = (1,1,2)
|
||||
// ------------------------------------------------------------------------
|
||||
void ApplyAsIncrementalWhite(uint16_t white)
|
||||
{
|
||||
uint8_t value = white / 3;
|
||||
uint8_t remainder = white % 3;
|
||||
|
||||
W1 = value;
|
||||
W2 = value;
|
||||
W3 = value;
|
||||
|
||||
if (remainder)
|
||||
{
|
||||
W3++;
|
||||
if (remainder == 2)
|
||||
{
|
||||
W2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Red, Green, Blue, Warm White, Cool White color members (0-255) where
|
||||
// (0,0,0, 0,0,0) is black and
|
||||
// (255,255,255, 0,0,0) is a white
|
||||
// (0,0,0, 255,0,0) is white1 and
|
||||
// (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;
|
||||
|
||||
const static uint8_t Max = 255;
|
||||
const static size_t Count = 6; // six elements in []
|
||||
const static uint16_t MaxIncrementalWhite = 765;
|
||||
|
||||
private:
|
||||
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;
|
||||
}
|
||||
|
||||
};
|
||||
|
75
src/internal/features/Neo6ByteFeature.h
Normal file
75
src/internal/features/Neo6ByteFeature.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
Neo6ByteFeature provides feature base class to describe color order for
|
||||
6 byte features that all 6 bytes are used
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
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:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 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];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
33
src/internal/features/NeoRgbwwwFeatures.h
Normal file
33
src/internal/features/NeoRgbwwwFeatures.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoRgbcnwFeature provides feature classes to describe color order and
|
||||
color depth for NeoPixelBus template class
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
class NeoGrbwwwFeature :
|
||||
public Neo6ByteFeature<ColorIndexG, ColorIndexR, ColorIndexB, ColorIndexW1, ColorIndexW2, ColorIndexW3>,
|
||||
public NeoElementsNoSettings
|
||||
{
|
||||
};
|
Reference in New Issue
Block a user