diff options
Diffstat (limited to 'dmx.h')
-rw-r--r-- | dmx.h | 85 |
1 files changed, 35 insertions, 50 deletions
@@ -1,45 +1,44 @@ #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); } - // reset any internal state to a clean point - virtual void reset() { init(); } - // clear out/zero out the given number of leds. virtual void clearLeds(int nLeds) { int count = min(nLeds * 3, DMX_SIZE); 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)])); } } @@ -48,51 +47,44 @@ public: // as above, but every 4th uint8_t is assumed to be alpha channel data, and will be skipped virtual void show(const struct CARGB *data, int nLeds, uint8_t scale = 255) = 0; #endif - - // is the controller ready to write data out - virtual bool ready() { return true; } - - // wait until the controller is ready to write data out - virtual void wait() { return; } - }; -#elif defined(FASTSPI_USE_DMX_SERIAL) +#endif + +#ifdef DmxSerial_h +#include<DMXSerial.h> -template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> class DMXController : public CLEDController { +template <EOrder RGB_ORDER = RGB> class DMXSerialController : public CLEDController { public: // initialize the LED controller virtual void init() { DMXSerial.init(DMXController); } - // reset any internal state to a clean point - virtual void reset() { init(); } - // 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)])); } } @@ -101,15 +93,8 @@ public: // as above, but every 4th uint8_t is assumed to be alpha channel data, and will be skipped virtual void show(const struct CARGB *data, int nLeds, uint8_t scale = 255) = 0; #endif - - // is the controller ready to write data out - virtual bool ready() { return true; } - - // wait until the controller is ready to write data out - virtual void wait() { return; } - }; - +#define HAS_DMX_SERIAL #endif -#endif
\ No newline at end of file +#endif |