diff options
-rw-r--r-- | FastLED.cpp | 10 | ||||
-rw-r--r-- | FastLED.h | 11 | ||||
-rw-r--r-- | chipsets.h | 16 | ||||
-rw-r--r-- | clockless_arm_k20.h | 6 | ||||
-rw-r--r-- | clockless_arm_sam.h | 6 | ||||
-rw-r--r-- | clockless_trinket.h | 6 | ||||
-rw-r--r-- | controller.h | 75 |
7 files changed, 79 insertions, 51 deletions
diff --git a/FastLED.cpp b/FastLED.cpp index 4db607a6..ce3f9fd3 100644 --- a/FastLED.cpp +++ b/FastLED.cpp @@ -46,23 +46,21 @@ CLEDController &CFastLED::addLeds(CLEDController *pLed, return *pLed; } -void CFastLED::show(CRGB scale) { +void CFastLED::show(uint8_t scale) { for(int i = 0; i < m_nControllers; i++) { if(m_Controllers[i].pLedController != NULL) { m_Controllers[i].pLedController->show(m_Controllers[i].pLedData + m_Controllers[i].nOffset, - m_Controllers[i].nLeds, - m_Controllers[i].pLedController->getAdjustment(scale)); + m_Controllers[i].nLeds, scale); } else { return; } } } -void CFastLED::showColor(const struct CRGB & color, CRGB scale) { +void CFastLED::showColor(const struct CRGB & color, uint8_t scale) { for(int i = 0; i < m_nControllers; i++) { if(m_Controllers[i].pLedController != NULL) { - m_Controllers[i].pLedController->showColor(color, m_Controllers[i].nLeds, - m_Controllers[i].pLedController->getAdjustment(scale)); + m_Controllers[i].pLedController->showColor(color, m_Controllers[i].nLeds, scale); } else { return; } @@ -54,7 +54,7 @@ class CFastLED { CControllerInfo m_Controllers[NUM_CONTROLLERS]; int m_nControllers; - CRGB m_Scale; + uint8_t m_Scale; public: CFastLED(); @@ -155,12 +155,11 @@ public: } #endif - void setBrightness(CRGB scale) { m_Scale = scale; } - void setBrightness(uint8_t scale) { m_Scale = CRGB(scale,scale,scale); } - uint8_t getBrightness() { return m_Scale.raw[0]; } + void setBrightness(uint8_t scale) { m_Scale = scale; } + uint8_t getBrightness() { return m_Scale; } /// Update all our controllers with the current led colors, using the passed in brightness - void show(CRGB scale); + void show(uint8_t scale); /// Update all our controllers with the current led colors void show() { show(m_Scale); } @@ -169,7 +168,7 @@ public: void clearData(); - void showColor(const struct CRGB & color, CRGB scale); + void showColor(const struct CRGB & color, uint8_t scale); void showColor(const struct CRGB & color) { showColor(color, m_Scale); } @@ -7,7 +7,7 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // LPD8806 controller class - takes data/clock/select pin values (N.B. should take an SPI definition?) -// +// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = DATA_RATE_MHZ(20) > @@ -52,11 +52,11 @@ public: mSPI.release(); } - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { mSPI.template writeBytes3<LPD8806_ADJUST, RGB_ORDER>((byte*)data.raw, nLeds * 3, scale, false); } - virtual void show(const struct CRGB *data, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CRGB *data, int nLeds, CRGB scale) { // TODO rgb-ize scale mSPI.template writeBytes3<LPD8806_ADJUST, RGB_ORDER>((byte*)data, nLeds * 3, scale); } @@ -95,7 +95,7 @@ public: mWaitDelay.mark(); } - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { mWaitDelay.wait(); mSPI.template writeBytes3<RGB_ORDER>((byte*)data.raw, nLeds * 3, scale, false); mWaitDelay.mark(); @@ -145,7 +145,7 @@ public: showColor(CRGB(0,0,0), nLeds); } - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { PixelController<RGB_ORDER> pixels(data.raw, scale, true, false, 0); mSPI.select(); @@ -237,12 +237,12 @@ public: writeHeader(); } - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { mSPI.template writeBytes3<FLAG_START_BIT, RGB_ORDER>((byte*)data.raw, nLeds * 3, scale, false); writeHeader(); } - virtual void show(const struct CRGB *data, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CRGB *data, int nLeds, CRGB scale) { // Make sure the FLAG_START_BIT flag is set to ensure that an extra 1 bit is sent at the start // of each triplet of bytes for rgb data // writeHeader(); @@ -251,7 +251,7 @@ public: } #ifdef SUPPORT_ARGB - virtual void show(const struct CARGB *data, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CARGB *data, int nLeds, CRGB scale) { mSPI.writeBytesValue(0, 6); mSPI.template writeBit<0>(0); mSPI.template writeBit<0>(0); diff --git a/clockless_arm_k20.h b/clockless_arm_k20.h index 09830527..d5f5a1c0 100644 --- a/clockless_arm_k20.h +++ b/clockless_arm_k20.h @@ -24,7 +24,7 @@ public: } // set all the leds on the controller to a given color - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { mWait.wait(); cli(); @@ -37,7 +37,7 @@ public: mWait.mark(); } - virtual void show(const struct CRGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CRGB *rgbdata, int nLeds, CRGB scale) { mWait.wait(); cli(); @@ -51,7 +51,7 @@ public: } #ifdef SUPPORT_ARGB - virtual void show(const struct CARGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CARGB *rgbdata, int nLeds, CRGB scale) { mWait.wait(); cli(); diff --git a/clockless_arm_sam.h b/clockless_arm_sam.h index 28207acb..e17c902d 100644 --- a/clockless_arm_sam.h +++ b/clockless_arm_sam.h @@ -34,7 +34,7 @@ public: } // set all the leds on the controller to a given color - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { mWait.wait(); cli(); SysClockSaver savedClock(TOTAL); @@ -50,7 +50,7 @@ public: mWait.mark(); } - virtual void show(const struct CRGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CRGB *rgbdata, int nLeds, CRGB scale) { mWait.wait(); cli(); SysClockSaver savedClock(TOTAL); @@ -72,7 +72,7 @@ public: } #ifdef SUPPORT_ARGB - virtual void show(const struct CARGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CARGB *rgbdata, int nLeds, CRGB scale) { mWait.wait(); cli(); SysClockSaver savedClock(TOTAL); diff --git a/clockless_trinket.h b/clockless_trinket.h index 8024fc96..5dcecafa 100644 --- a/clockless_trinket.h +++ b/clockless_trinket.h @@ -73,16 +73,16 @@ public: } // set all the leds on the controller to a given color - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) { showRGBInternal_AdjTime(0, false, nLeds, scale, (const byte*)&data); } - virtual void show(const struct CRGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CRGB *rgbdata, int nLeds, CRGB scale) { showRGBInternal_AdjTime(0, true, nLeds, scale, (const byte*)rgbdata); } #ifdef SUPPORT_ARGB - virtual void show(const struct CARGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { + virtual void show(const struct CARGB *rgbdata, int nLeds, CRGB scale) { showRGBInternal_AdjTime(1, true, nLeds, scale, (const byte*)rgbdata); } #endif diff --git a/controller.h b/controller.h index 791b8080..131ec4a2 100644 --- a/controller.h +++ b/controller.h @@ -27,9 +27,21 @@ /// to methods, make them references to this type, keeps your code saner. However, most people won't be seeing/using these objects /// directly at all class CLEDController { +protected: CRGB m_ColorCorrection; CRGB m_ColorTemperature; + // set all the leds on the controller to a given color + virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale) = 0; + + // 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, CRGB scale) = 0; + +#ifdef SUPPORT_ARGB + // 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, CRGB scale) = 0; +#endif public: CLEDController() : m_ColorCorrection(UncorrectedColor), m_ColorTemperature(UncorrectedTemperature) {} @@ -42,38 +54,57 @@ public: // clear out/zero out the given number of leds. virtual void clearLeds(int nLeds) = 0; - // set all the leds on the controller to a given color - virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) = 0; - - // 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, CRGB scale = CRGB::White) = 0; - -#ifdef SUPPORT_ARGB - // 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, CRGB scale = CRGB::White) = 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; } - virtual CLEDController & setCorrection(CRGB correction) { m_ColorCorrection = correction; return *this; } - virtual CLEDController & setCorrection(LEDColorCorrection correction) { m_ColorCorrection = correction; return *this; } - virtual CRGB getCorrection() { return m_ColorCorrection; } + // show function w/integer brightness, will scale for color correction and temperature + void show(const struct CRGB *data, int nLeds, uint8_t brightness) { + show(data, nLeds, getAdjustment(brightness)); + } + + // show function w/integer brightness, will scale for color correction and temperature + void showColor(const struct CRGB &data, int nLeds, uint8_t brightness) { + showColor(data, nLeds, getAdjustment(brightness)); + } + + #ifdef SUPPORT_ARGB + // as above, but every 4th uint8_t is assumed to be alpha channel data, and will be skipped + void show(const struct CARGB *data, int nLeds, uint8_t brightness) { + show(data, nLeds, getAdjustment(brightness)) + } +#endif + + CLEDController & setCorrection(CRGB correction) { m_ColorCorrection = correction; return *this; } + CLEDController & setCorrection(LEDColorCorrection correction) { m_ColorCorrection = correction; return *this; } + CRGB getCorrection() { return m_ColorCorrection; } - virtual CLEDController & setTemperature(CRGB temperature) { m_ColorTemperature = temperature; return *this; } - virtual CLEDController & setTemperature(ColorTemperature temperature) { m_ColorTemperature = temperature; return *this; } - virtual CRGB getTemperature() { return m_ColorTemperature; } + CLEDController & setTemperature(CRGB temperature) { m_ColorTemperature = temperature; return *this; } + CLEDController & setTemperature(ColorTemperature temperature) { m_ColorTemperature = temperature; return *this; } + CRGB getTemperature() { return m_ColorTemperature; } - virtual CRGB getAdjustment(CRGB scale) { + CRGB getAdjustment(uint8_t scale) { // if(1) return scale; - uint32_t r = ((uint32_t)m_ColorCorrection.r * (uint32_t)m_ColorTemperature.r * (uint32_t)scale.r) / (uint32_t)0x10000L; - uint32_t g = ((uint32_t)m_ColorCorrection.g * (uint32_t)m_ColorTemperature.g * (uint32_t)scale.g) / (uint32_t)0x10000L; - uint32_t b = ((uint32_t)m_ColorCorrection.b * (uint32_t)m_ColorTemperature.b * (uint32_t)scale.b) / (uint32_t)0x10000L; + uint32_t r = 0; + uint32_t g = 0; + uint32_t b = 0; + if(m_ColorCorrection.r > 0 && m_ColorTemperature.r > 0 && scale > 0) { + r = ((uint32_t)m_ColorCorrection.r+1) * ((uint32_t)m_ColorTemperature.r+1) * scale; + r /= 0x10000L; + } + if(m_ColorCorrection.g > 0 && m_ColorTemperature.g > 0 && scale > 0) { + g = ((uint32_t)m_ColorCorrection.g+1) * ((uint32_t)m_ColorTemperature.g+1) * scale; + g /= 0x10000L; + } + + if(m_ColorCorrection.b > 0 && m_ColorTemperature.b > 0 && scale > 0) { + b = ((uint32_t)m_ColorCorrection.b+1) * ((uint32_t)m_ColorTemperature.b+1) * scale; + b /= 0x10000L; + } + // static int done = 0; // if(!done) { // done = 1; |