Move nextStatusMillis to be a global so it can be reset within the status function so it can be called from multiple places (i.e. from a UDP CMD)

This commit is contained in:
Junior 2026-01-10 16:38:04 -05:00
parent aca3b506ab
commit 2e5d8a9eec

View File

@ -51,6 +51,9 @@ extern const uint8_t gamma8[];
volatile bool blueInitState = false; volatile bool blueInitState = false;
volatile unsigned long blueToggleCount; volatile unsigned long blueToggleCount;
// nextStatusMillis is global so we can reset it inside the process message function if needed
unsigned long nextStatusMillis = 0;
// Struct for storing color value sets // Struct for storing color value sets
// Colors are obvious. restDuration is how long to rest on this color. // Colors are obvious. restDuration is how long to rest on this color.
struct colorTriplet { struct colorTriplet {
@ -126,7 +129,7 @@ void inline blueBlinkISR(void) {
#endif #endif
} }
unsigned long sendDeviceStatus() { void sendDeviceStatus() {
if ( DEBUG ) Serial.println("Sending device status"); if ( DEBUG ) Serial.println("Sending device status");
WiFiClient client; WiFiClient client;
HTTPClient http; HTTPClient http;
@ -145,7 +148,7 @@ unsigned long sendDeviceStatus() {
} }
} }
http.end(); http.end();
return millis(); nextStatusMillis = millis() + 600000; // 10 minutes
} }
// Set up our initial states and WiFi // Set up our initial states and WiFi
@ -190,6 +193,7 @@ void setup() {
#endif #endif
analogWrite(GPIO_BLUE, 0); analogWrite(GPIO_BLUE, 0);
sendDeviceStatus(); sendDeviceStatus();
nextStatusMillis = millis() + 600000; // 10 minutes
ArduinoOTA.onStart([]() { ArduinoOTA.onStart([]() {
analogWrite(GPIO_RED, 0); analogWrite(GPIO_RED, 0);
analogWrite(GPIO_GREEN, 0); analogWrite(GPIO_GREEN, 0);
@ -273,7 +277,7 @@ bool processMessage() {
memcpy(&messageTargetID, (char*)buff + 13, 4); memcpy(&messageTargetID, (char*)buff + 13, 4);
// If this packet isn't destined for ID=0 (all targets) or ID=TARGET_ID (our ID) then stop processing // If this packet isn't destined for ID=0 (all targets) or ID=TARGET_ID (our ID) then stop processing
if ( (myTargetID != 0 ) && (messageTargetID != 0) && (messageTargetID != myTargetID) ) { if ( (myTargetID != 0 ) && (messageTargetID != 0) && ((messageTargetID & myTargetID) == 0) ) {
if ( DEBUG ) Serial.println("Got packet for different ID! Mine=" + String(myTargetID) + " Target=" + String(messageTargetID)); if ( DEBUG ) Serial.println("Got packet for different ID! Mine=" + String(myTargetID) + " Target=" + String(messageTargetID));
return false; return false;
} }
@ -397,7 +401,7 @@ bool processMessage() {
if ( command == CMD_UPDATESTATUS ) { if ( command == CMD_UPDATESTATUS ) {
sendDeviceStatus(); sendDeviceStatus();
if ( DEBUG ) Serial.println("Status update requested"); if ( DEBUG ) Serial.println("Status update requested");
return true; return false;
} }
return false; return false;
@ -410,7 +414,6 @@ void loop() {
static short redLevel = 0, greenLevel = 0, blueLevel = 0; static short redLevel = 0, greenLevel = 0, blueLevel = 0;
static bool newColor = false; static bool newColor = false;
unsigned long nowMillis = millis(); unsigned long nowMillis = millis();
static unsigned long nextStatusMillis = millis() + 600000; // 10 minutes
static unsigned long nextRampMillis; static unsigned long nextRampMillis;
static unsigned long rampStartMillis; static unsigned long rampStartMillis;
static unsigned long restingEndMillis; static unsigned long restingEndMillis;
@ -431,7 +434,7 @@ void loop() {
} }
if ( nowMillis >= nextStatusMillis ) { if ( nowMillis >= nextStatusMillis ) {
nextStatusMillis = sendDeviceStatus() + 600000; // 10 minutes sendDeviceStatus();
} }
// Check to see if we have a new packet waiting and parse it out if we do // Check to see if we have a new packet waiting and parse it out if we do