forked from Makuna/NeoPixelBus
1 parent
6e276ec337
commit
cf298d4096
10 files changed
+443
-105
No files matched your search
+42
-14
@@ -48,6 +48,8 @@ License along with NeoPixel. If not, see
|
||||
|
||||
#include "internal/NeoHueBlend.h"
|
||||
|
||||
#include "internal/NeoSettings.h"
|
||||
|
||||
#include "internal/RgbColor.h"
|
||||
#include "internal/HslColor.h"
|
||||
#include "internal/HsbColor.h"
|
||||
@@ -56,6 +58,7 @@ License along with NeoPixel. If not, see
|
||||
#include "internal/SegmentDigit.h"
|
||||
|
||||
#include "internal/NeoColorFeatures.h"
|
||||
#include "internal/NeoTm1814ColorFeatures.h"
|
||||
#include "internal/DotStarColorFeatures.h"
|
||||
#include "internal/Lpd8806ColorFeatures.h"
|
||||
#include "internal/NeoSegmentFeatures.h"
|
||||
@@ -120,21 +123,21 @@ public:
|
||||
NeoPixelBus(uint16_t countPixels, uint8_t pin) :
|
||||
_countPixels(countPixels),
|
||||
_state(0),
|
||||
_method(pin, countPixels, T_COLOR_FEATURE::PixelSize)
|
||||
_method(pin, countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize)
|
||||
{
|
||||
}
|
||||
|
||||
NeoPixelBus(uint16_t countPixels, uint8_t pinClock, uint8_t pinData) :
|
||||
_countPixels(countPixels),
|
||||
_state(0),
|
||||
_method(pinClock, pinData, countPixels, T_COLOR_FEATURE::PixelSize)
|
||||
_method(pinClock, pinData, countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize)
|
||||
{
|
||||
}
|
||||
|
||||
NeoPixelBus(uint16_t countPixels) :
|
||||
_countPixels(countPixels),
|
||||
_state(0),
|
||||
_method(countPixels, T_COLOR_FEATURE::PixelSize)
|
||||
_method(countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -145,7 +148,7 @@ public:
|
||||
operator NeoBufferContext<T_COLOR_FEATURE>()
|
||||
{
|
||||
Dirty(); // we assume you are playing with bits
|
||||
return NeoBufferContext<T_COLOR_FEATURE>(_method.getPixels(), _method.getPixelsSize());
|
||||
return NeoBufferContext<T_COLOR_FEATURE>(_pixels(), _method.getDataSize());
|
||||
}
|
||||
|
||||
void Begin()
|
||||
@@ -195,12 +198,12 @@ public:
|
||||
|
||||
uint8_t* Pixels()
|
||||
{
|
||||
return _method.getPixels();
|
||||
return _pixels();
|
||||
};
|
||||
|
||||
size_t PixelsSize() const
|
||||
{
|
||||
return _method.getPixelsSize();
|
||||
return _method.getDataSize() - T_COLOR_FEATURE::SettingsSize;
|
||||
};
|
||||
|
||||
size_t PixelSize() const
|
||||
@@ -217,7 +220,7 @@ public:
|
||||
{
|
||||
if (indexPixel < _countPixels)
|
||||
{
|
||||
T_COLOR_FEATURE::applyPixelColor(_method.getPixels(), indexPixel, color);
|
||||
T_COLOR_FEATURE::applyPixelColor(_pixels(), indexPixel, color);
|
||||
Dirty();
|
||||
}
|
||||
};
|
||||
@@ -226,7 +229,7 @@ public:
|
||||
{
|
||||
if (indexPixel < _countPixels)
|
||||
{
|
||||
return T_COLOR_FEATURE::retrievePixelColor(_method.getPixels(), indexPixel);
|
||||
return T_COLOR_FEATURE::retrievePixelColor(_pixels(), indexPixel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -239,7 +242,7 @@ public:
|
||||
void ClearTo(typename T_COLOR_FEATURE::ColorObject color)
|
||||
{
|
||||
uint8_t temp[T_COLOR_FEATURE::PixelSize];
|
||||
uint8_t* pixels = _method.getPixels();
|
||||
uint8_t* pixels = _pixels();
|
||||
|
||||
T_COLOR_FEATURE::applyPixelColor(temp, 0, color);
|
||||
|
||||
@@ -255,7 +258,7 @@ public:
|
||||
first <= last)
|
||||
{
|
||||
uint8_t temp[T_COLOR_FEATURE::PixelSize];
|
||||
uint8_t* pixels = _method.getPixels();
|
||||
uint8_t* pixels = _pixels();
|
||||
uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, first);
|
||||
|
||||
T_COLOR_FEATURE::applyPixelColor(temp, 0, color);
|
||||
@@ -354,18 +357,43 @@ public:
|
||||
SetPixelColor(indexPixelOne, colorTwo);
|
||||
SetPixelColor(indexPixelTwo, colorOne);
|
||||
};
|
||||
|
||||
void SetPixelSettings(const typename T_COLOR_FEATURE::SettingsObject& settings)
|
||||
{
|
||||
T_COLOR_FEATURE::applySettings(_method.getData(), settings);
|
||||
Dirty();
|
||||
};
|
||||
|
||||
uint32_t CalcTotalMilliAmpere(const typename T_COLOR_FEATURE::ColorObject::SettingsObject& settings)
|
||||
{
|
||||
uint32_t total = 0; // in 1/10th milliamps
|
||||
|
||||
for (uint16_t index = 0; index < _countPixels; index++)
|
||||
{
|
||||
auto color = GetPixelColor(index);
|
||||
total += color.CalcTotalTenthMilliAmpere(settings);
|
||||
}
|
||||
|
||||
return total / 10; // return millamps
|
||||
}
|
||||
|
||||
protected:
|
||||
const uint16_t _countPixels; // Number of RGB LEDs in strip
|
||||
|
||||
uint8_t _state; // internal state
|
||||
T_METHOD _method;
|
||||
|
||||
uint8_t* _pixels()
|
||||
{
|
||||
// get pixels data within the data stream
|
||||
return T_COLOR_FEATURE::pixels(_method.getData());
|
||||
}
|
||||
|
||||
void _rotateLeft(uint16_t rotationCount, uint16_t first, uint16_t last)
|
||||
{
|
||||
// store in temp
|
||||
uint8_t temp[rotationCount * T_COLOR_FEATURE::PixelSize];
|
||||
uint8_t* pixels = _method.getPixels();
|
||||
uint8_t* pixels = _pixels();
|
||||
|
||||
uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, first);
|
||||
|
||||
@@ -386,7 +414,7 @@ protected:
|
||||
uint16_t front = first + shiftCount;
|
||||
uint16_t count = last - front + 1;
|
||||
|
||||
uint8_t* pixels = _method.getPixels();
|
||||
uint8_t* pixels = _pixels();
|
||||
uint8_t* pFirst = T_COLOR_FEATURE::getPixelAddress(pixels, first);
|
||||
uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, front);
|
||||
|
||||
@@ -399,7 +427,7 @@ protected:
|
||||
{
|
||||
// store in temp
|
||||
uint8_t temp[rotationCount * T_COLOR_FEATURE::PixelSize];
|
||||
uint8_t* pixels = _method.getPixels();
|
||||
uint8_t* pixels = _pixels();
|
||||
|
||||
uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, last - (rotationCount - 1));
|
||||
|
||||
@@ -420,7 +448,7 @@ protected:
|
||||
uint16_t front = first + shiftCount;
|
||||
uint16_t count = last - front + 1;
|
||||
|
||||
uint8_t* pixels = _method.getPixels();
|
||||
uint8_t* pixels = _pixels();
|
||||
uint8_t* pFirst = T_COLOR_FEATURE::getPixelAddress(pixels, first);
|
||||
uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, front);
|
||||
|
||||
|
||||
Reference in new issue
Block a user