From e9092c39fe92783e4ab4ac9b1dd35324421d25b6 Mon Sep 17 00:00:00 2001 From: David Madison Date: Fri, 5 May 2017 09:05:47 -0400 Subject: [PATCH] Removed 'loop' avoidance Cleans up the code slightly. If the compiler is smart, the functions are inlined regardless. --- .../LEDstream_FastLED/LEDstream_FastLED.ino | 49 ++++++++----------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino b/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino index f95906b..6036076 100644 --- a/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino +++ b/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino @@ -117,39 +117,35 @@ void setup(){ #endif Serial.begin(SerialSpeed); + Serial.print("Ada\n"); // Send ACK string to host + lastByteTime = lastAckTime = millis(); // Set initial counters +} + +void loop(){ adalight(); } void adalight(){ - Serial.print("Ada\n"); // Send ACK string to host + // Implementation is a simple finite-state machine. + // Regardless of mode, check for serial input each time: + t = millis(); - lastByteTime = lastAckTime = millis(); + if((c = Serial.read()) >= 0){ + lastByteTime = lastAckTime = t; // Reset timeout counters - // loop() is avoided as even that small bit of function overhead - // has a measurable impact on this code's overall throughput. - - for(;;) { - // Implementation is a simple finite-state machine. - // Regardless of mode, check for serial input each time: - t = millis(); - - if((c = Serial.read()) >= 0){ - lastByteTime = lastAckTime = t; // Reset timeout counters - - switch(mode) { - case MODE_HEADER: - headerMode(); - break; - case MODE_DATA: - dataMode(); - break; - } - } - else { - timeouts(); + switch(mode) { + case MODE_HEADER: + headerMode(); + break; + case MODE_DATA: + dataMode(); + break; } } + else { + timeouts(); + } } void headerMode(){ @@ -231,8 +227,3 @@ void timeouts(){ } } } - -void loop(){ - // loop() is avoided as even that small bit of function overhead - // has a measurable impact on this code's overall throughput. -}