Skip to content

Commit 4be60e8

Browse files
committed
Remove the global 'c' variable
Cleaner to pass the value of the current byte around rather than saving it persistently
1 parent 3285373 commit 4be60e8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Arduino/LEDstream_FastLED/LEDstream_FastLED.ino

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ const uint8_t magic[] = {
7979

8080
enum processModes_t {Header, Data} mode = Header;
8181

82-
int16_t c; // current byte, must support -1 if no data available
8382
uint16_t outPos; // current byte index in the LED array
8483
uint32_t bytesRemaining; // count of bytes yet received, set by checksum
8584

@@ -89,8 +88,8 @@ unsigned long lastAckTime; // ms timestamp, lask acknowledge to the host
8988
unsigned long (*const now)(void) = millis; // timing function
9089
const unsigned long Timebase = 1000; // time units per second
9190

92-
void headerMode();
93-
void dataMode();
91+
void headerMode(uint8_t c);
92+
void dataMode(uint8_t c);
9493
void timeouts();
9594

9695
// Macros initialized
@@ -144,16 +143,18 @@ void setup(){
144143
}
145144

146145
void loop(){
147-
// If there is new serial data
148-
if((c = Serial.read()) >= 0){
146+
const int c = Serial.read(); // read one byte
147+
148+
// if there is data available
149+
if(c >= 0){
149150
lastByteTime = lastAckTime = now(); // Reset timeout counters
150151

151152
switch(mode) {
152153
case Header:
153-
headerMode();
154+
headerMode(c);
154155
break;
155156
case Data:
156-
dataMode();
157+
dataMode(c);
157158
break;
158159
}
159160
}
@@ -163,7 +164,7 @@ void loop(){
163164
}
164165
}
165166

166-
void headerMode(){
167+
void headerMode(uint8_t c){
167168
static uint8_t
168169
headPos,
169170
hi, lo, chk;
@@ -201,7 +202,7 @@ void headerMode(){
201202
}
202203
}
203204

204-
void dataMode(){
205+
void dataMode(uint8_t c){
205206
// If LED data is not full
206207
if (outPos < sizeof(leds)){
207208
ledsRaw[outPos++] = c; // Issue next byte

0 commit comments

Comments
 (0)