Switch to a simple counter for the lights mode timeout instead of using millis() for better performance

This commit is contained in:
skogaby
2020-03-15 16:23:16 -05:00
parent fbbb992a72
commit 3b283bba4b
4 changed files with 13 additions and 11 deletions
+2 -2
View File
@@ -7,7 +7,7 @@
// *** USER EDITABLE CONFIG OPTIONS ***
// Select which board you're using (ignore if not using Teensy)
//#define TEESNY_V1_0 // Version 1.0 (No version number on board)
#define TEESNY_V1_0 // Version 1.0 (No version number on board)
//#define TEENSY_V1_1 // Version 1.1 (v1.1 on board under logo)
// Uncomment this line to force the processor to use Serial Output
@@ -21,7 +21,7 @@
// Comment this line for default Seaurchin air sensor bindings
// Uncomment this line if your IR sensors will each be mapped to separate keyboard key
//#define IR_SENSOR_KEY
#define IR_SENSOR_KEY
// Uncomment this line if your LED lights are mirrored
//#define LED_REVERSE
+9 -7
View File
@@ -19,7 +19,7 @@ CRGB leds[16];
byte serialBuffer[100];
bool updateLeds = false;
bool useSerialLeds = false;
long lastSerialLights;
int serialLightsCounter;
CRGB led_on = CRGB::Purple;
CRGB led_off = CRGB::Yellow;
@@ -77,7 +77,7 @@ void setup() {
FastLED.show();
delay(3000);
lastSerialLights = millis();
serialLightsCounter = 0;
// Initialize relevant output method / USB or serial
#ifdef USB
@@ -94,17 +94,17 @@ void loop() {
Serial.readBytes(serialBuffer, 100);
serialProcessor.processBulk(serialBuffer);
}
else
{
serialLightsCounter++;
}
// If currently paused through a config command, do not execute main loop
if (!activated)
return;
// If we're not using serial LEDs, just update the lights every loop
if (!useSerialLeds)
updateLeds = true;
// If we haven't received any serial light updates in 5 seconds, just fallback to reactive lighting
if (millis() - lastSerialLights > 5000)
if (serialLightsCounter > 300)
useSerialLeds = false;
// Scan touch keyboard and update lights
@@ -138,6 +138,8 @@ void loop() {
// If not, make it the off color
leds[index].setRGB(led_off.r / 2, led_off.g / 2, led_off.b / 2);
}
updateLeds = true;
}
// handle changing key colors for serial LED updates
else
+1 -1
View File
@@ -54,7 +54,7 @@ void SerialProcessor::processBulk(uint8_t *buf)
{
serialLeds->processBulk(buf);
useSerialLeds = true;
lastSerialLights = millis();
serialLightsCounter = 0;
}
else if (buf[0] == CONFIG_FLAG && buf[1] == CONFIG_FLAG)
{
+1 -1
View File
@@ -32,7 +32,7 @@ extern bool useSerialLeds;
extern CRGB leds[16];
extern CRGB led_on;
extern CRGB led_off;
extern long lastSerialLights;
extern int serialLightsCounter;
class SerialProcessor
{