-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLedPattern_FastLed.cpp
More file actions
73 lines (66 loc) · 1.73 KB
/
LedPattern_FastLed.cpp
File metadata and controls
73 lines (66 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "LedPattern_FastLed.h"
#include <Arduino.h>
#define NODEBUG
#ifndef NODEBUG
#define debug(x) Serial.print(x)
#define debugln(x) Serial.println(x); Serial.flush();
#else
#define debug(x)
#define debugln(x)
#endif
LedPattern_FastLed::LedPattern_FastLed( CFastLED& fastled, const uint16_t idx )
: m_fastled(fastled),
m_idx(idx)
{
m_fastled.clear(true);
ledOff();
}
void LedPattern_FastLed::ledOff( void )
{
const uint8_t patternOff[] = { 0, 0, 0};
pattern off = patternOff;
ledSet(off);
}
void LedPattern_FastLed::ledSet(pattern& p)
{
uint8_t rgb[3];
for (uint8_t i = 0; i < 3; ++i)
{
rgb[i] = *p++;
#ifndef LED_PATTERN_FADE_UNSUPPORTED
m_state[i] = rgb[i]<<7;
m_step[i] = 0;
#endif
}
m_fastled.leds()[m_idx].setRGB( rgb[0], rgb[1], rgb[2] );
}
#ifndef LED_PATTERN_FADE_UNSUPPORTED
void LedPattern_FastLed::ledFadeStop(void)
{
for (uint8_t i = 0; i < 3; ++i)
{
m_step[i] = 0;
}
}
void LedPattern_FastLed::ledFadeTo(pattern& p, const uint8_t steps)
{
for (uint8_t i = 0; i < 3; ++i)
{
uint8_t target = *p++;
m_step[i] = ((int16_t(target)<<7) - m_state[i])/steps;
debug("FADE "); debug(m_state[i]); debug("->"); debug(target); debug(", step "); debugln(m_step[i]);
}
ledUpdate();
}
void LedPattern_FastLed::ledUpdate(void)
{
uint8_t rgb[3];
for (uint8_t i = 0; i < 3; ++i)
{
m_state[i] += m_step[i];
rgb[i] = int16_t(m_state[i])>>7;
debug("STATE "); debugln(m_state[i]);
}
m_fastled.leds()[m_idx].setRGB( rgb[0], rgb[1], rgb[2] );
}
#endif