diff options
author | Daniel Garcia <danielgarcia@gmail.com> | 2013-11-11 02:52:27 +0400 |
---|---|---|
committer | Daniel Garcia <danielgarcia@gmail.com> | 2013-11-11 02:52:27 +0400 |
commit | 04a2f73f448995526903a68bb9256821419d08c4 (patch) | |
tree | cdcb911791218eda0c8d77ffdbe5ddc0add54fc1 /FastLED.cpp | |
parent | e9d4489e508a99dc9e949f7762c2d6f3529524bb (diff) | |
parent | 59edcab79837185feeea2dfe6f46b2c4ad17b8d8 (diff) |
Merge branch 'FastSPI_LED2' into FastSPI_LED2.1
Diffstat (limited to 'FastLED.cpp')
-rw-r--r-- | FastLED.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/FastLED.cpp b/FastLED.cpp new file mode 100644 index 00000000..4ffa4165 --- /dev/null +++ b/FastLED.cpp @@ -0,0 +1,86 @@ +#include "FastSPI_LED2.h" + +#if defined(__SAM3X8E__) +volatile uint32_t fuckit; +#endif + +CFastLED LEDS; +CFastLED & FastSPI_LED = LEDS; +CFastLED & FastSPI_LED2 = LEDS; +CFastLED & FastLED = LEDS; + +uint32_t CRGB::Squant = ((uint32_t)((__TIME__[4]-'0') * 28))<<16 | ((__TIME__[6]-'0')*50)<<8 | ((__TIME__[7]-'0')*28); + +CFastLED::CFastLED() { + // clear out the array of led controllers + m_nControllers = NUM_CONTROLLERS; + m_nScale = 255; + memset8(m_Controllers, 0, m_nControllers * sizeof(CControllerInfo)); +} + +CLEDController *CFastLED::addLeds(CLEDController *pLed, + const struct CRGB *data, + int nLedsOrOffset, int nLedsIfOffset) { + int nOffset = (nLedsIfOffset > 0) ? nLedsOrOffset : 0; + int nLeds = (nLedsIfOffset > 0) ? nLedsIfOffset : nLedsOrOffset; + + int target = -1; + + // Figure out where to put the new led controller + for(int i = 0; i < m_nControllers; i++) { + if(m_Controllers[i].pLedController == NULL) { + target = i; + break; + } + } + + // if we have a spot, use it! + if(target != -1) { + m_Controllers[target].pLedController = pLed; + m_Controllers[target].pLedData = data; + m_Controllers[target].nOffset = nOffset; + m_Controllers[target].nLeds = nLeds; + pLed->init(); + return pLed; + } + + return NULL; +} + +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, scale); + } else { + return; + } + } +} + +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, scale); + } else { + return; + } + } +} + +void CFastLED::clear(boolean includeLedData) { + showColor(CRGB(0,0,0), 0); + if(includeLedData) { + clearData(); + } +} + +void CFastSPI_LED2::clearData() { + for(int i = 0; i < m_nControllers; i++) { + if(m_Controllers[i].pLedData != NULL) { + memset8((void*)m_Controllers[i].pLedData, 0, sizeof(struct CRGB) * m_Controllers[i].nLeds); + } else { + return; + } + } +} |