Skip to content

Commit 97eeaa1

Browse files
committed
1 parent 682074e commit 97eeaa1

File tree

122 files changed

+24130
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+24130
-0
lines changed

FastLED/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
html/
2+
*.gch

FastLED/FastLED.cpp

+270
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
#define FASTLED_INTERNAL
2+
#include "FastLED.h"
3+
4+
5+
#if defined(__SAM3X8E__)
6+
volatile uint32_t fuckit;
7+
#endif
8+
9+
FASTLED_NAMESPACE_BEGIN
10+
11+
void *pSmartMatrix = NULL;
12+
13+
CFastLED FastLED;
14+
15+
CLEDController *CLEDController::m_pHead = NULL;
16+
CLEDController *CLEDController::m_pTail = NULL;
17+
static uint32_t lastshow = 0;
18+
19+
uint32_t _frame_cnt=0;
20+
uint32_t _retry_cnt=0;
21+
22+
// uint32_t CRGB::Squant = ((uint32_t)((__TIME__[4]-'0') * 28))<<16 | ((__TIME__[6]-'0')*50)<<8 | ((__TIME__[7]-'0')*28);
23+
24+
CFastLED::CFastLED() {
25+
// clear out the array of led controllers
26+
// m_nControllers = 0;
27+
m_Scale = 255;
28+
m_nFPS = 0;
29+
m_pPowerFunc = NULL;
30+
m_nPowerData = 0xFFFFFFFF;
31+
}
32+
33+
CLEDController &CFastLED::addLeds(CLEDController *pLed,
34+
struct CRGB *data,
35+
int nLedsOrOffset, int nLedsIfOffset) {
36+
int nOffset = (nLedsIfOffset > 0) ? nLedsOrOffset : 0;
37+
int nLeds = (nLedsIfOffset > 0) ? nLedsIfOffset : nLedsOrOffset;
38+
39+
pLed->init();
40+
pLed->setLeds(data + nOffset, nLeds);
41+
FastLED.setMaxRefreshRate(pLed->getMaxRefreshRate(),true);
42+
return *pLed;
43+
}
44+
45+
void CFastLED::show(uint8_t scale) {
46+
// guard against showing too rapidly
47+
while(m_nMinMicros && ((micros()-lastshow) < m_nMinMicros));
48+
lastshow = micros();
49+
50+
// If we have a function for computing power, use it!
51+
if(m_pPowerFunc) {
52+
scale = (*m_pPowerFunc)(scale, m_nPowerData);
53+
}
54+
55+
CLEDController *pCur = CLEDController::head();
56+
while(pCur) {
57+
uint8_t d = pCur->getDither();
58+
if(m_nFPS < 100) { pCur->setDither(0); }
59+
pCur->showLeds(scale);
60+
pCur->setDither(d);
61+
pCur = pCur->next();
62+
}
63+
countFPS();
64+
}
65+
66+
int CFastLED::count() {
67+
int x = 0;
68+
CLEDController *pCur = CLEDController::head();
69+
while( pCur) {
70+
x++;
71+
pCur = pCur->next();
72+
}
73+
return x;
74+
}
75+
76+
CLEDController & CFastLED::operator[](int x) {
77+
CLEDController *pCur = CLEDController::head();
78+
while(x-- && pCur) {
79+
pCur = pCur->next();
80+
}
81+
if(pCur == NULL) {
82+
return *(CLEDController::head());
83+
} else {
84+
return *pCur;
85+
}
86+
}
87+
88+
void CFastLED::showColor(const struct CRGB & color, uint8_t scale) {
89+
while(m_nMinMicros && ((micros()-lastshow) < m_nMinMicros));
90+
lastshow = micros();
91+
92+
// If we have a function for computing power, use it!
93+
if(m_pPowerFunc) {
94+
scale = (*m_pPowerFunc)(scale, m_nPowerData);
95+
}
96+
97+
CLEDController *pCur = CLEDController::head();
98+
while(pCur) {
99+
uint8_t d = pCur->getDither();
100+
if(m_nFPS < 100) { pCur->setDither(0); }
101+
pCur->showColor(color, scale);
102+
pCur->setDither(d);
103+
pCur = pCur->next();
104+
}
105+
countFPS();
106+
}
107+
108+
void CFastLED::clear(boolean writeData) {
109+
if(writeData) {
110+
showColor(CRGB(0,0,0), 0);
111+
}
112+
clearData();
113+
}
114+
115+
void CFastLED::clearData() {
116+
CLEDController *pCur = CLEDController::head();
117+
while(pCur) {
118+
pCur->clearLedData();
119+
pCur = pCur->next();
120+
}
121+
}
122+
123+
void CFastLED::delay(unsigned long ms) {
124+
unsigned long start = millis();
125+
do {
126+
#ifndef FASTLED_ACCURATE_CLOCK
127+
// make sure to allow at least one ms to pass to ensure the clock moves
128+
// forward
129+
::delay(1);
130+
#endif
131+
show();
132+
#if defined(ARDUINO) && (ARDUINO > 150) && !defined(IS_BEAN)
133+
yield();
134+
#endif
135+
}
136+
while((millis()-start) < ms);
137+
}
138+
139+
void CFastLED::setTemperature(const struct CRGB & temp) {
140+
CLEDController *pCur = CLEDController::head();
141+
while(pCur) {
142+
pCur->setTemperature(temp);
143+
pCur = pCur->next();
144+
}
145+
}
146+
147+
void CFastLED::setCorrection(const struct CRGB & correction) {
148+
CLEDController *pCur = CLEDController::head();
149+
while(pCur) {
150+
pCur->setCorrection(correction);
151+
pCur = pCur->next();
152+
}
153+
}
154+
155+
void CFastLED::setDither(uint8_t ditherMode) {
156+
CLEDController *pCur = CLEDController::head();
157+
while(pCur) {
158+
pCur->setDither(ditherMode);
159+
pCur = pCur->next();
160+
}
161+
}
162+
163+
//
164+
// template<int m, int n> void transpose8(unsigned char A[8], unsigned char B[8]) {
165+
// uint32_t x, y, t;
166+
//
167+
// // Load the array and pack it into x and y.
168+
// y = *(unsigned int*)(A);
169+
// x = *(unsigned int*)(A+4);
170+
//
171+
// // x = (A[0]<<24) | (A[m]<<16) | (A[2*m]<<8) | A[3*m];
172+
// // y = (A[4*m]<<24) | (A[5*m]<<16) | (A[6*m]<<8) | A[7*m];
173+
//
174+
// // pre-transform x
175+
// t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
176+
// t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
177+
//
178+
// // pre-transform y
179+
// t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
180+
// t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
181+
//
182+
// // final transform
183+
// t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
184+
// y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
185+
// x = t;
186+
//
187+
// B[7*n] = y; y >>= 8;
188+
// B[6*n] = y; y >>= 8;
189+
// B[5*n] = y; y >>= 8;
190+
// B[4*n] = y;
191+
//
192+
// B[3*n] = x; x >>= 8;
193+
// B[2*n] = x; x >>= 8;
194+
// B[n] = x; x >>= 8;
195+
// B[0] = x;
196+
// // B[0]=x>>24; B[n]=x>>16; B[2*n]=x>>8; B[3*n]=x>>0;
197+
// // B[4*n]=y>>24; B[5*n]=y>>16; B[6*n]=y>>8; B[7*n]=y>>0;
198+
// }
199+
//
200+
// void transposeLines(Lines & out, Lines & in) {
201+
// transpose8<1,2>(in.bytes, out.bytes);
202+
// transpose8<1,2>(in.bytes + 8, out.bytes + 1);
203+
// }
204+
205+
extern int noise_min;
206+
extern int noise_max;
207+
208+
void CFastLED::countFPS(int nFrames) {
209+
static int br = 0;
210+
static uint32_t lastframe = 0; // millis();
211+
212+
if(br++ >= nFrames) {
213+
uint32_t now = millis();
214+
now -= lastframe;
215+
m_nFPS = (br * 1000) / now;
216+
br = 0;
217+
lastframe = millis();
218+
}
219+
}
220+
221+
void CFastLED::setMaxRefreshRate(uint16_t refresh, bool constrain) {
222+
if(constrain) {
223+
// if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
224+
// allowed to slow things down if constraining)
225+
if(refresh > 0) {
226+
m_nMinMicros = ( (1000000/refresh) > m_nMinMicros) ? (1000000/refresh) : m_nMinMicros;
227+
}
228+
} else if(refresh > 0) {
229+
m_nMinMicros = 1000000 / refresh;
230+
} else {
231+
m_nMinMicros = 0;
232+
}
233+
}
234+
235+
extern "C" int atexit(void (* /*func*/ )()) { return 0; }
236+
237+
#ifdef NEED_CXX_BITS
238+
namespace __cxxabiv1
239+
{
240+
#ifndef ESP8266
241+
extern "C" void __cxa_pure_virtual (void) {}
242+
#endif
243+
244+
/* guard variables */
245+
246+
/* The ABI requires a 64-bit type. */
247+
__extension__ typedef int __guard __attribute__((mode(__DI__)));
248+
249+
extern "C" int __cxa_guard_acquire (__guard *) __attribute__((weak));
250+
extern "C" void __cxa_guard_release (__guard *) __attribute__((weak));
251+
extern "C" void __cxa_guard_abort (__guard *) __attribute__((weak));
252+
253+
extern "C" int __cxa_guard_acquire (__guard *g)
254+
{
255+
return !*(char *)(g);
256+
}
257+
258+
extern "C" void __cxa_guard_release (__guard *g)
259+
{
260+
*(char *)g = 1;
261+
}
262+
263+
extern "C" void __cxa_guard_abort (__guard *)
264+
{
265+
266+
}
267+
}
268+
#endif
269+
270+
FASTLED_NAMESPACE_END

0 commit comments

Comments
 (0)