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:
parent
aca3b506ab
commit
2e5d8a9eec
15
src/main.cpp
15
src/main.cpp
|
|
@ -51,6 +51,9 @@ extern const uint8_t gamma8[];
|
|||
volatile bool blueInitState = false;
|
||||
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
|
||||
// Colors are obvious. restDuration is how long to rest on this color.
|
||||
struct colorTriplet {
|
||||
|
|
@ -126,7 +129,7 @@ void inline blueBlinkISR(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
unsigned long sendDeviceStatus() {
|
||||
void sendDeviceStatus() {
|
||||
if ( DEBUG ) Serial.println("Sending device status");
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
|
|
@ -145,7 +148,7 @@ unsigned long sendDeviceStatus() {
|
|||
}
|
||||
}
|
||||
http.end();
|
||||
return millis();
|
||||
nextStatusMillis = millis() + 600000; // 10 minutes
|
||||
}
|
||||
|
||||
// Set up our initial states and WiFi
|
||||
|
|
@ -190,6 +193,7 @@ void setup() {
|
|||
#endif
|
||||
analogWrite(GPIO_BLUE, 0);
|
||||
sendDeviceStatus();
|
||||
nextStatusMillis = millis() + 600000; // 10 minutes
|
||||
ArduinoOTA.onStart([]() {
|
||||
analogWrite(GPIO_RED, 0);
|
||||
analogWrite(GPIO_GREEN, 0);
|
||||
|
|
@ -273,7 +277,7 @@ bool processMessage() {
|
|||
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 ( (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));
|
||||
return false;
|
||||
}
|
||||
|
|
@ -397,7 +401,7 @@ bool processMessage() {
|
|||
if ( command == CMD_UPDATESTATUS ) {
|
||||
sendDeviceStatus();
|
||||
if ( DEBUG ) Serial.println("Status update requested");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -410,7 +414,6 @@ void loop() {
|
|||
static short redLevel = 0, greenLevel = 0, blueLevel = 0;
|
||||
static bool newColor = false;
|
||||
unsigned long nowMillis = millis();
|
||||
static unsigned long nextStatusMillis = millis() + 600000; // 10 minutes
|
||||
static unsigned long nextRampMillis;
|
||||
static unsigned long rampStartMillis;
|
||||
static unsigned long restingEndMillis;
|
||||
|
|
@ -431,7 +434,7 @@ void loop() {
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user