mirror of
https://github.com/Makuna/NeoPixelBus.git
synced 2025-08-04 19:34:27 +02:00
Make BrighntessBus suppport ClearTo (#181)
* Make BrighntessBus suppport ClearTo * Match the coding style
This commit is contained in:
committed by
Michael Miller
parent
80f0812818
commit
6b1cf112d3
@@ -31,6 +31,37 @@ License along with NeoPixel. If not, see
|
|||||||
template<typename T_COLOR_FEATURE, typename T_METHOD> class NeoPixelBrightnessBus :
|
template<typename T_COLOR_FEATURE, typename T_METHOD> class NeoPixelBrightnessBus :
|
||||||
public NeoPixelBus<T_COLOR_FEATURE, T_METHOD>
|
public NeoPixelBus<T_COLOR_FEATURE, T_METHOD>
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
void ConvertColor(typename T_COLOR_FEATURE::ColorObject* color)
|
||||||
|
{
|
||||||
|
if (_brightness)
|
||||||
|
{
|
||||||
|
uint8_t* ptr = (uint8_t*) color;
|
||||||
|
uint8_t* ptrEnd = ptr + T_COLOR_FEATURE::PixelSize;
|
||||||
|
|
||||||
|
while (ptr != ptrEnd)
|
||||||
|
{
|
||||||
|
uint16_t value = *ptr;
|
||||||
|
*ptr++ = (value * _brightness) >> 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecoverColor(typename T_COLOR_FEATURE::ColorObject* color)
|
||||||
|
{
|
||||||
|
if (_brightness)
|
||||||
|
{
|
||||||
|
uint8_t* ptr = (uint8_t*) color;
|
||||||
|
uint8_t* ptrEnd = ptr + T_COLOR_FEATURE::PixelSize;
|
||||||
|
|
||||||
|
while (ptr != ptrEnd)
|
||||||
|
{
|
||||||
|
uint16_t value = *ptr;
|
||||||
|
*ptr++ = (value << 8) / _brightness;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NeoPixelBrightnessBus(uint16_t countPixels, uint8_t pin) :
|
NeoPixelBrightnessBus(uint16_t countPixels, uint8_t pin) :
|
||||||
NeoPixelBus<T_COLOR_FEATURE, T_METHOD>(countPixels, pin),
|
NeoPixelBus<T_COLOR_FEATURE, T_METHOD>(countPixels, pin),
|
||||||
@@ -99,38 +130,30 @@ public:
|
|||||||
|
|
||||||
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
|
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
|
||||||
{
|
{
|
||||||
if (_brightness)
|
ConvertColor(&color);
|
||||||
{
|
|
||||||
uint8_t* ptr = (uint8_t*)&color;
|
|
||||||
uint8_t* ptrEnd = ptr + T_COLOR_FEATURE::PixelSize;
|
|
||||||
|
|
||||||
while (ptr != ptrEnd)
|
|
||||||
{
|
|
||||||
uint16_t value = *ptr;
|
|
||||||
*ptr++ = (value * _brightness) >> 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::SetPixelColor(indexPixel, color);
|
NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::SetPixelColor(indexPixel, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
|
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
|
||||||
{
|
{
|
||||||
typename T_COLOR_FEATURE::ColorObject color = NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::GetPixelColor(indexPixel);
|
typename T_COLOR_FEATURE::ColorObject color = NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::GetPixelColor(indexPixel);
|
||||||
|
RecoverColor(&color);
|
||||||
if (_brightness)
|
|
||||||
{
|
|
||||||
uint8_t* ptr = (uint8_t*)&color;
|
|
||||||
uint8_t* ptrEnd = ptr + T_COLOR_FEATURE::PixelSize;
|
|
||||||
|
|
||||||
while (ptr != ptrEnd)
|
|
||||||
{
|
|
||||||
uint16_t value = *ptr;
|
|
||||||
*ptr++ = (value << 8) / _brightness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClearTo(typename T_COLOR_FEATURE::ColorObject color)
|
||||||
|
{
|
||||||
|
ConvertColor(&color);
|
||||||
|
NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::ClearTo(color);
|
||||||
|
};
|
||||||
|
|
||||||
|
void ClearTo(typename T_COLOR_FEATURE::ColorObject color, uint16_t first, uint16_t last)
|
||||||
|
{
|
||||||
|
ConvertColor(&color);
|
||||||
|
NeoPixelBus<T_COLOR_FEATURE, T_METHOD>::ClearTo(color, first, last);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t _brightness;
|
uint8_t _brightness;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user