Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Garcia <danielgarcia@gmail.com>2015-10-19 05:38:09 +0300
committerDaniel Garcia <danielgarcia@gmail.com>2015-10-19 05:38:09 +0300
commit720f339e3ca5d60ccc1217c0aa8c70e4f3314852 (patch)
tree78e606c539270a3c55f54d2d5ad3fc3444008735 /controller.h
parent43888147be354a8e55cf603d60b4957dc1de8798 (diff)
Add a templated CPixelLEDController, which templates on RGB_ORDER. This is a precursor to having the output classes template on RGB vs RGBW.
Diffstat (limited to 'controller.h')
-rw-r--r--controller.h43
1 files changed, 36 insertions, 7 deletions
diff --git a/controller.h b/controller.h
index 87767ae4..93ebddd5 100644
--- a/controller.h
+++ b/controller.h
@@ -354,7 +354,7 @@ struct PixelController {
template<int LANES,int MASK, EOrder RGB_ORDER>
struct MultiPixelController {
const uint8_t *mData;
- int mLen;
+ int mLen,mLenRemaining;
uint8_t d[3];
uint8_t e[3];
CRGB mScale;
@@ -371,7 +371,7 @@ struct MultiPixelController {
mData = other.mData;
mScale = other.mScale;
mAdvance = other.mAdvance;
- mLen = other.mLen;
+ mLenRemaining = mLen = other.mLen;
for(int i = 0; i < LANES; i++) { mOffsets[i] = other.mOffsets[i]; }
}
@@ -384,20 +384,20 @@ struct MultiPixelController {
}
}
- MultiPixelController(const uint8_t *d, int len, CRGB & s, EDitherMode dither = BINARY_DITHER, bool advance=true, uint8_t skip=0) : mData(d), mLen(len), mScale(s) {
+ MultiPixelController(const uint8_t *d, int len, CRGB & s, EDitherMode dither = BINARY_DITHER, bool advance=true, uint8_t skip=0) : mData(d), mLen(len), mLenRemaining(len), mScale(s) {
enable_dithering(dither);
mData += skip;
mAdvance = (advance) ? 3+skip : 0;
initOffsets(len);
}
- MultiPixelController(const CRGB *d, int len, CRGB & s, EDitherMode dither = BINARY_DITHER) : mData((const uint8_t*)d), mLen(len), mScale(s) {
+ MultiPixelController(const CRGB *d, int len, CRGB & s, EDitherMode dither = BINARY_DITHER) : mData((const uint8_t*)d), mLen(len), mLenRemaining(len), mScale(s) {
enable_dithering(dither);
mAdvance = 3;
initOffsets(len);
}
- MultiPixelController(const CRGB &d, int len, CRGB & s, EDitherMode dither = BINARY_DITHER) : mData((const uint8_t*)&d), mLen(len), mScale(s) {
+ MultiPixelController(const CRGB &d, int len, CRGB & s, EDitherMode dither = BINARY_DITHER) : mData((const uint8_t*)&d), mLen(len), mLenRemaining(len), mScale(s) {
enable_dithering(dither);
mAdvance = 0;
initOffsets(len);
@@ -481,7 +481,7 @@ struct MultiPixelController {
// Do we have n pixels left to process?
__attribute__((always_inline)) inline bool has(int n) {
- return mLen >= n;
+ return mLenRemaining >= n;
}
// toggle dithering enable
@@ -492,11 +492,13 @@ struct MultiPixelController {
}
}
+ __attribute__((always_inline)) inline int size() { return mLen; }
+
// get the amount to advance the pointer by
__attribute__((always_inline)) inline int advanceBy() { return mAdvance; }
// advance the data pointer forward, adjust position counter
- __attribute__((always_inline)) inline void advanceData() { mData += mAdvance; mLen--;}
+ __attribute__((always_inline)) inline void advanceData() { mData += mAdvance; mLenRemaining--;}
// step the dithering forward
__attribute__((always_inline)) inline void stepDithering() {
@@ -538,6 +540,33 @@ struct MultiPixelController {
__attribute__((always_inline)) inline uint8_t stepAdvanceAndLoadAndScale0(int lane) { stepDithering(); return advanceAndLoadAndScale<0>(*this, lane); }
};
+template<EOrder RGB_ORDER> class CPixelLEDController : public CLEDController {
+protected:
+ virtual void showPixels(PixelController<RGB_ORDER> & pixels) = 0;
+
+ /// set all the leds on the controller to a given color
+ ///@param data the crgb color to set the leds to
+ ///@param nLeds the numner of leds to set to this color
+ ///@param scale the rgb scaling value for outputting color
+ virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) {
+ PixelController<RGB_ORDER> pixels(data, nLeds, scale, getDither());
+ showPixels(pixels);
+ }
+
+/// write the passed in rgb data out to the leds managed by this controller
+///@param data the rgb data to write out to the strip
+///@param nLeds the number of leds being written out
+///@param scale the rgb scaling to apply to each led before writing it out
+ virtual void show(const struct CRGB *data, int nLeds, CRGB scale) {
+ PixelController<RGB_ORDER> pixels(data, nLeds, scale, getDither());
+ showPixels(pixels);
+ }
+
+public:
+ CPixelLEDController() : CLEDController() {}
+};
+
+
FASTLED_NAMESPACE_END
#endif