-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetSeqPixels.cpp
More file actions
185 lines (144 loc) · 5.62 KB
/
SetSeqPixels.cpp
File metadata and controls
185 lines (144 loc) · 5.62 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Copyright 2014 Mark Briggs
This file is part of ColorRing.
ColorRing is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
ColorRing is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
There is a copy of the GNU General Public License in the
accompanying COPYING file
*/
#include "SetSeqPixels.h"
SetSeqPixels::SetSeqPixels() {
}
SetSeqPixels::SetSeqPixels(Adafruit_NeoPixel* strip,
byte startPixelNum,
byte numPixelsEachColor,
byte colorSeriesNumIter,
byte numPixelsToSkip,
word numIter,
word animDelay,
word pauseAfter,
// boolBits
bool destructive,
bool direction,
bool isAnim,
bool clearStripBefore,
bool gradiate,
bool gradiateLastPixelFirstColor,
byte numColorsInSeries,
PixelColor *colorSeriesArr)
{
init(strip, startPixelNum, numPixelsEachColor, colorSeriesNumIter, numPixelsToSkip, numIter, animDelay, pauseAfter, destructive, direction, isAnim, clearStripBefore, gradiate, gradiateLastPixelFirstColor, numColorsInSeries, colorSeriesArr);
}
SetSeqPixels::SetSeqPixels(Adafruit_NeoPixel* strip, byte* stripCmdArray) {
byte startPixelNum = stripCmdArray[1];
byte numPixelsEachColor = stripCmdArray[2];
byte colorSeriesNumIter = stripCmdArray[3];
byte numPixelsToSkip = stripCmdArray[4];
word numIter = (stripCmdArray[5] << 8) + stripCmdArray[6];
word animDelay = (stripCmdArray[7] << 8) + stripCmdArray[8];
word pauseAfter = (stripCmdArray[9] << 8) + stripCmdArray[10];
// boolBits
byte boolBits = stripCmdArray[11];
setBoolBitVars(boolBits, destructive, direction, wrap, isAnim, clearStripBefore, gradiate, gradiateLastPixelFirstColor);
// colorSeriesArr
byte numColorsInSeries = stripCmdArray[12];
byte csaFirstBytePos = 13;
for (int i = 0; i < numColorsInSeries; i++) {
byte bOffset = csaFirstBytePos + (3*i);
colorSeriesArr[i] = PixelColor(stripCmdArray[bOffset], stripCmdArray[bOffset+1], stripCmdArray[bOffset+2]);
}
init(strip, startPixelNum, numPixelsEachColor, colorSeriesNumIter, numPixelsToSkip, numIter, animDelay, pauseAfter, destructive, direction, isAnim, clearStripBefore, gradiate, gradiateLastPixelFirstColor, numColorsInSeries, colorSeriesArr);
}
void SetSeqPixels::init(Adafruit_NeoPixel* strip,
byte startPixelNum,
byte numPixelsEachColor,
byte colorSeriesNumIter,
byte numPixelsToSkip,
word numIter,
word animDelay,
word pauseAfter,
// boolBits
bool destructive,
bool direction,
bool isAnim,
bool clearStripBefore,
bool gradiate,
bool gradiateLastPixelFirstColor,
byte numColorsInSeries,
PixelColor *colorSeriesArr)
{
this->cmdType = 0;
this->strip = strip;
this->startPixelNum = startPixelNum;
this->numPixelsEachColor = numPixelsEachColor;
this->colorSeriesNumIter = colorSeriesNumIter;
this->numPixelsToSkip = numPixelsToSkip;
this->animDelay = animDelay;
this->pauseAfter = pauseAfter;
// boolBits
this->destructive = destructive;
this->direction = direction;
this->wrap = NULL; // N/A
this->isAnim = isAnim;
this->clearStripBefore = clearStripBefore;
this->gradiate = gradiate;
this->gradiateLastPixelFirstColor = gradiateLastPixelFirstColor;
this->numColorsInSeries = numColorsInSeries;
for (int i = 0; i < numColorsInSeries; i++) {
this->colorSeriesArr[i] = colorSeriesArr[i];
}
// Gradient Stuff
multiGradient = MultiGradient(colorSeriesArr, numColorsInSeries, numPixelsEachColor, gradiateLastPixelFirstColor);
// Init other Variables
this->currIteration = 0;
this->currPixelNum = startPixelNum;
if (numIter == ITER_ENOUGH) {
this->numIter = numColorsInSeries * numPixelsEachColor * colorSeriesNumIter;
} else {
// to cut the # of iter's short.
this->numIter = numIter;
}
//this->inOutStr = strip->getPin() == OUT_STRIP_PIN ? "OUTSIDE" : "INSIDE";
}
void SetSeqPixels::step(boolean isShowStrip) {
//cout << "SetSeqPixels::step(" << (int)isShowStrip << ")" << endl;
if (!isPauseMode) {
//cout << "SetSeqPixels::step(" << (int)isShowStrip << ") [not paused]" << endl;
if (numPixelsEachColor < 1 || numColorsInSeries < 1) {
// Invalid scenarios
return;
}
lscStepPreCommon();
//cout << F("currIteration: ") << (int)currIteration << endl;
// Fix pixelNum (if necessary)
currPixelNum = fixPixelNum(currPixelNum);
//cout << F("currPixelNum: ") << (int)currPixelNum << endl;
// Set currPixelColor
if (gradiate && multiGradient.getIsValid() && numColorsInSeries > 1) {
currPixelColor = multiGradient.getTweenPixelColor(currIteration);
} else {
// Don't worry about gradients
currPixelColor = colorSeriesArr[(currIteration / numPixelsEachColor) % numColorsInSeries];
}
//cout << F("currPixelColor: "); currPixelColor.println();
// Add the Colors (if non-destructive)
if (!destructive) currPixelColor.addThisColor(PixelColor(strip->getPixelColor(currPixelNum)));
// Set Strip's Pixel Color
strip->setPixelColor(currPixelNum, currPixelColor.getLongVal());
// Next Pixel
currPixelNum = direction ? currPixelNum + numPixelsToSkip + 1 : currPixelNum - numPixelsToSkip - 1;
//cout << "next pixelNum: " << (int)currPixelNum << endl;
lscStepPostCommon(isShowStrip);
}
}
void SetSeqPixels::reset() {
//Serial.println("SSP::reset()");
lscResetCommon();
currPixelNum = startPixelNum;
}