diff options
author | Daniel Garcia <danielgarcia@gmail.com> | 2014-10-10 09:02:09 +0400 |
---|---|---|
committer | Daniel Garcia <danielgarcia@gmail.com> | 2014-10-10 09:02:09 +0400 |
commit | 36c48066c20863716e24adfa2f9282c7e0429107 (patch) | |
tree | 59243a1a1bf2e67134605f830225b28da3471f3f | |
parent | b0225bb185b5d3350fde4f7c668de70610773add (diff) |
Bring DMX kicking and screaming into the FastLED2.1 world
-rw-r--r-- | FastLED.h | 62 | ||||
-rw-r--r-- | dmx.h | 65 |
2 files changed, 62 insertions, 65 deletions
@@ -13,6 +13,14 @@ #include<SmartMatrix.h> #endif +#ifdef DmxSimple_h +#include<DmxSimple.h> +#endif + +#ifdef DmxSerial_h +#include<DMXSerial.h> +#endif + #include "controller.h" #include "fastpin.h" #include "fastspi.h" @@ -22,7 +30,7 @@ #include "colorutils.h" #include "colorpalettes.h" #include "chipsets.h" -#include "dmx.h" +#include "./dmx.h" #include "smartmatrix_t3.h" #include "noise.h" #include "power_mgt.h" @@ -38,23 +46,6 @@ enum ESPIChipsets { enum ESM { SMART_MATRIX }; -enum EClocklessChipsets { - DMX - // TM1809, - // TM1804, - // TM1803, - // WS2811, - // WS2812, - // WS2812B, - // UCS1903, - // UCS1903B, - // WS2811_400, - // // NEOPIXEL, - // GW6205, - // GW6205_400, - // TM1829 -}; - template<uint8_t DATA_PIN> class NEOPIXEL : public WS2811Controller800Khz<DATA_PIN, GRB> {}; template<uint8_t DATA_PIN, EOrder RGB_ORDER> class TM1829 : public TM1829Controller800Khz<DATA_PIN, RGB_ORDER> {}; template<uint8_t DATA_PIN, EOrder RGB_ORDER> class TM1809 : public TM1809Controller800Khz<DATA_PIN, RGB_ORDER> {}; @@ -69,6 +60,12 @@ template<uint8_t DATA_PIN, EOrder RGB_ORDER> class WS2811_400 : public WS2811Con template<uint8_t DATA_PIN, EOrder RGB_ORDER> class GW6205 : public GW6205Controller800Khz<DATA_PIN, RGB_ORDER> {}; template<uint8_t DATA_PIN, EOrder RGB_ORDER> class GW6205_400 : public GW6205Controller400Khz<DATA_PIN, RGB_ORDER> {}; template<uint8_t DATA_PIN, EOrder RGB_ORDER> class LPD1886 : public LPD1886Controller1250Khz<DATA_PIN, RGB_ORDER> {}; +#ifdef DmxSimple_h +template<uint8_t DATA_PIN, EOrder RGB_ORDER> class DMXSIMPLE : public DMXSimpleController<DATA_PIN, RGB_ORDER> {}; +#endif +#ifdef DmxSerial_h +template<EOrder RGB_ORDER> class DMXSERIAL : public DMXSerialController<RGB_ORDER> {}; +#endif // template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = DATA_RATE_MHZ(20)> class LPD8806 : public LPD8806Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED> {}; // template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = DATA_RATE_MHZ(1)> class WS2801 : public WS2801Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED> {}; @@ -160,6 +157,18 @@ public: return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); } + template<template<EOrder RGB_ORDER> class CHIPSET> + static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) { + static CHIPSET<RGB> c; + return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); + } + + template<template<EOrder RGB_ORDER> class CHIPSET, EOrder RGB_ORDER> + static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) { + static CHIPSET<RGB_ORDER> c; + return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset); + } + #ifdef SmartMatrix_h template<ESM CHIPSET> static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) @@ -170,23 +179,6 @@ public: } #endif -#ifdef FASTSPI_USE_DMX_SIMPLE - template<EClocklessChipsets CHIPSET, uint8_t DATA_PIN> - static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) - { - switch(CHIPSET) { - case DMX: { static DMXController<DATA_PIN> controller; return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset); } - } - } - - template<EClocklessChipsets CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER> - static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) { - switch(CHIPSET) { - case DMX: {static DMXController<DATA_PIN, RGB_ORDER> controller; return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset); } - } - } -#endif - #ifdef HAS_BLOCKLESS template<EBlockChipsets CHIPSET, int NUM_LANES> static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) { @@ -1,12 +1,13 @@ #ifndef __INC_DMX_H #define __INC_DMX_H -//#ifdef DmxSimple_H -//#if USE_DMX_SIMPLE -#ifdef FASTSPI_USE_DMX_SIMPLE + +#ifdef DmxSimple_h #include<DmxSimple.h> +#define HAS_DMX_SIMPLE + // note - dmx simple must be included before FastSPI for this code to be enabled -template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> class DMXController : public CLEDController { +template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> class DMXSimpleController : public CLEDController { public: // initialize the LED controller virtual void init() { DmxSimple.usePin(DATA_PIN); } @@ -17,26 +18,27 @@ public: for(int iChannel = 1; iChannel <= count; iChannel++) { DmxSimple.write(iChannel, 0); } } +protected: // set all the leds on the controller to a given color - virtual void showColor(const struct CRGB & data, int nLeds, uint8_t scale = 255) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { int count = min(nLeds, DMX_SIZE / 3); int iChannel = 1; for(int i = 0; i < count; i++) { - DmxSimple.write(iChannel++, scale8(data[RGB_BYTE0(RGB_ORDER)], scale)); - DmxSimple.write(iChannel++, scale8(data[RGB_BYTE1(RGB_ORDER)], scale)); - DmxSimple.write(iChannel++, scale8(data[RGB_BYTE2(RGB_ORDER)], scale)); + DmxSimple.write(iChannel++, scale8(data[RGB_BYTE0(RGB_ORDER)], scale.raw[RGB_BYTE0(RGB_ORDER)])); + DmxSimple.write(iChannel++, scale8(data[RGB_BYTE1(RGB_ORDER)], scale.raw[RGB_BYTE1(RGB_ORDER)])); + DmxSimple.write(iChannel++, scale8(data[RGB_BYTE2(RGB_ORDER)], scale.raw[RGB_BYTE2(RGB_ORDER)])); } } - // note that the uint8_ts will be in the order that you want them sent out to the device. + // note that the uint8_ts will be in the order that you want them sent out to the device. // nLeds is the number of RGB leds being written to - virtual void show(const struct CRGB *data, int nLeds, uint8_t scale = 255) { + virtual void show(const struct CRGB *data, int nLeds, CRGB scale) { int count = min(nLeds, DMX_SIZE / 3); int iChannel = 1; for(int i = 0; i < count; i++) { - DmxSimple.write(iChannel++, scale8(data[i][RGB_BYTE0(RGB_ORDER)], scale)); - DmxSimple.write(iChannel++, scale8(data[i][RGB_BYTE1(RGB_ORDER)], scale)); - DmxSimple.write(iChannel++, scale8(data[i][RGB_BYTE2(RGB_ORDER)], scale)); + DmxSimple.write(iChannel++, scale8(data[i][RGB_BYTE0(RGB_ORDER)], scale.raw[RGB_BYTE0(RGB_ORDER)])); + DmxSimple.write(iChannel++, scale8(data[i][RGB_BYTE1(RGB_ORDER)], scale.raw[RGB_BYTE1(RGB_ORDER)])); + DmxSimple.write(iChannel++, scale8(data[i][RGB_BYTE2(RGB_ORDER)], scale.raw[RGB_BYTE2(RGB_ORDER)])); } } @@ -47,39 +49,42 @@ public: #endif }; -#elif defined(FASTSPI_USE_DMX_SERIAL) +#endif -template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> class DMXController : public CLEDController { +#ifdef DmxSerial_h +#include<DMXSerial.h> + +template <EOrder RGB_ORDER = RGB> class DMXSerialController : public CLEDController { public: // initialize the LED controller virtual void init() { DMXSerial.init(DMXController); } // clear out/zero out the given number of leds. virtual void clearLeds(int nLeds) { - int count = min(nLeds * 3, DMX_SIZE); - for(int iChannel = 0; iChannel < count; iChannel++) { DmxSimple.write(iChannel, 0); } + int count = min(nLeds * 3, DMXSERIAL_MAX); + for(int iChannel = 0; iChannel < count; iChannel++) { DMXSerial.write(iChannel, 0); } } // set all the leds on the controller to a given color - virtual void showColor(const struct CRGB & data, int nLeds, uint8_t scale = 255) { - int count = min(nLeds, DMX_SIZE / 3); + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { + int count = min(nLeds, DMXSERIAL_MAX / 3); int iChannel = 0; for(int i = 0; i < count; i++) { - DMXSerial.write(iChannel++, scale8(data[RGB_BYTE0(RGB_ORDER)], scale)); - DMXSerial.write(iChannel++, scale8(data[RGB_BYTE1(RGB_ORDER)], scale)); - DMXSerial.write(iChannel++, scale8(data[RGB_BYTE2(RGB_ORDER)], scale)); + DMXSerial.write(iChannel++, scale8(data[RGB_BYTE0(RGB_ORDER)], scale.raw[RGB_BYTE0(RGB_ORDER)])); + DMXSerial.write(iChannel++, scale8(data[RGB_BYTE1(RGB_ORDER)], scale.raw[RGB_BYTE1(RGB_ORDER)])); + DMXSerial.write(iChannel++, scale8(data[RGB_BYTE2(RGB_ORDER)], scale.raw[RGB_BYTE2(RGB_ORDER)])); } } - // note that the uint8_ts will be in the order that you want them sent out to the device. + // note that the uint8_ts will be in the order that you want them sent out to the device. // nLeds is the number of RGB leds being written to - virtual void show(const struct CRGB *data, int nLeds, uint8_t scale = 255) { - int count = min(nLeds, DMX_SIZE / 3); + virtual void show(const struct CRGB *data, int nLeds, CRGB scale) { + int count = min(nLeds, DMXSERIAL_MAX / 3); int iChannel = 0; for(int i = 0; i < count; i++) { - DMXSerial.write(iChannel++, scale8(data[i][RGB_BYTE0(RGB_ORDER)], scale)); - DMXSerial.write(iChannel++, scale8(data[i][RGB_BYTE1(RGB_ORDER)], scale)); - DMXSerial.write(iChannel++, scale8(data[i][RGB_BYTE2(RGB_ORDER)], scale)); + DMXSerial.write(iChannel++, scale8(data[i][RGB_BYTE0(RGB_ORDER)], scale.raw[RGB_BYTE0(RGB_ORDER)])); + DMXSerial.write(iChannel++, scale8(data[i][RGB_BYTE1(RGB_ORDER)], scale.raw[RGB_BYTE1(RGB_ORDER)])); + DMXSerial.write(iChannel++, scale8(data[i][RGB_BYTE2(RGB_ORDER)], scale.raw[RGB_BYTE2(RGB_ORDER)])); } } @@ -89,7 +94,7 @@ public: virtual void show(const struct CARGB *data, int nLeds, uint8_t scale = 255) = 0; #endif }; - +#define HAS_DMX_SERIAL #endif -#endif
\ No newline at end of file +#endif |