-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStatefulStrip.cpp
117 lines (102 loc) · 3.33 KB
/
StatefulStrip.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "StatefulStrip.h"
StatefulStrip::StatefulStrip(CRGBSet &leds, uint16_t density) {
this->leds = &leds;
this->density = density;
}
StatefulStrip::StatefulStrip(CRGBSet *leds, uint16_t density) {
this->leds = leds;
this->density = density;
}
StatefulStrip::StatefulStrip() {}
void StatefulStrip::setLeds(CRGBSet *leds) {
this->leds = leds;
}
Strip *StatefulStrip::overlay(double opacity) {
return this;
}
uint16_t StatefulStrip::size() {
return leds->size();
}
void StatefulStrip::_fade(int16_t indexFrom, int16_t indexTo, uint8_t amount) {
if (crop(indexFrom, indexTo, true)) {
(*leds)(indexFrom, indexTo).fadeToBlackBy(amount);
}
}
void StatefulStrip::_blur(int16_t indexFrom, int16_t indexTo, uint8_t amount) {
if (crop(indexFrom, indexTo, true)) {
(*leds)(indexFrom, indexTo).blur1d(amount);
}
}
CRGB StatefulStrip::_shiftUp(int16_t indexFrom, int16_t indexTo, CRGB in) {
if (crop(indexFrom, indexTo, true)) {
if (indexFrom == indexTo) {
return in;
} else {
CRGB out = (*leds)[indexTo];
for (uint16_t i = indexTo; i > indexFrom ; i--) {
(*leds)[i] = (*leds)[i - 1];
}
(*leds)[indexFrom] = in;
return out;
}
}
return CRGB::Black;
}
CRGB StatefulStrip::_shiftDown(int16_t indexFrom, int16_t indexTo, CRGB in) {
if (crop(indexFrom, indexTo, true)) {
if (indexFrom == indexTo) {
return in;
} else {
CRGB out = (*leds)[indexFrom];
for (uint16_t i = indexFrom; i < indexTo; i++) {
(*leds)[i] = (*leds)[i + 1];
}
(*leds)[indexTo] = in;
return out;
}
}
return CRGB::Black;
}
bool StatefulStrip::_paintSolid(int16_t indexFrom, int16_t indexTo, CRGB color, bool overlay) {
if (crop(indexFrom, indexTo, true)) {
if (overlay) {
(*leds)(indexFrom, indexTo) |= color;
} else {
(*leds)(indexFrom, indexTo) = color;
}
return true;
}
return false;
}
bool StatefulStrip::_paintGradient(int16_t indexFrom, int16_t indexTo, Gradient *gradient, double gradientFrom, double gradientTo, bool overlay) {
if (crop(indexFrom, indexTo)) {
for (uint16_t i = limitToRange(indexFrom); i < limitToRange(indexTo); i++) {
CRGB color = gradient->getColor(gradientFrom + (gradientTo - gradientFrom) * (i - indexFrom) / (indexTo - indexFrom));
if (overlay) {
(*leds)[i] |= color;
} else {
(*leds)[i] = color;
}
}
return true;
}
return false;
}
bool StatefulStrip::_paintRainbow(int16_t indexFrom, int16_t indexTo, uint8_t initialHue, uint8_t deltaHue) {
if (crop(indexFrom, indexTo, true)) {
(*leds)(indexFrom, indexTo).fill_rainbow(initialHue, deltaHue);
return true;
}
return false;
}
bool StatefulStrip::paintNormalizedSize(double positionFrom, int16_t size, CRGB color, bool overlay) {
uint16_t indexFrom = fromNormalizedPosition(positionFrom, size);
uint16_t indexTo = indexFrom + size - 1;
return paint(indexFrom, indexTo, color, overlay);
}
CRGB StatefulStrip::getIndex(int16_t index) {
if (isInRange(index)) {
return (*leds)[index];
}
return CRGB::Black;
}