From a8271c8724fb36c81b666919861f0baa98962171 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 7 Jan 2023 17:09:22 -0600 Subject: [PATCH] Added homeSpan.refreshStatusDevice() Provides for additional control over Status LED when a generic device has been used. If the color of the device is changed, the change will only take effect when the LED is next turned on. If the LED is blinking, the color changes upon the next blink. But if the LED is ON, there is no next blink and color will not change. This method check the status of the LED, and if it is ON, is calls the on() function again, which will result in an update of the color. The method does nothing if the LED is OFF or BLINKING. --- src/HomeSpan.h | 1 + src/src/extras/Blinker.cpp | 4 ++++ src/src/extras/Blinker.h | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 5d76818..40d3dc8 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -301,6 +301,7 @@ class Span{ } void setStatusDevice(Blinkable *sDev){statusDevice=sDev;} + void refreshStatusDevice(){if(statusLED)statusLED->refresh();} void setApSSID(const char *ssid){network.apSSID=ssid;} // sets Access Point SSID void setApPassword(const char *pwd){network.apPassword=pwd;} // sets Access Point Password diff --git a/src/src/extras/Blinker.cpp b/src/src/extras/Blinker.cpp index e97ee34..ede2a26 100644 --- a/src/src/extras/Blinker.cpp +++ b/src/src/extras/Blinker.cpp @@ -78,6 +78,7 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){ pauseTime=millis(); isPaused=false; + status=STATUS::BLINKING; } ////////////////////////////////////// @@ -93,6 +94,7 @@ void Blinker::stop(){ } isPaused=true; + status=STATUS::OFF; } ////////////////////////////////////// @@ -107,6 +109,7 @@ void Blinker::on(){ pauseTime=millis(); isPaused=false; + status=STATUS::ON; } ////////////////////////////////////// @@ -118,6 +121,7 @@ void Blinker::off(){ stop(); led->off(); + status=STATUS::OFF; } ////////////////////////////////////// diff --git a/src/src/extras/Blinker.h b/src/src/extras/Blinker.h index 633bc19..1484a86 100644 --- a/src/src/extras/Blinker.h +++ b/src/src/extras/Blinker.h @@ -47,6 +47,8 @@ class Blinkable { //////////////////////////////// class Blinker { + + enum STATUS {OFF, BLINKING, ON}; TaskHandle_t blinkHandle = NULL; Blinkable *led; @@ -55,6 +57,7 @@ class Blinker { int onTime; int offTime; int delayTime; + STATUS status=STATUS::OFF; unsigned long pauseDuration; unsigned long pauseTime; @@ -102,6 +105,10 @@ class Blinker { // Stops current blinking pattern and turns off LED + void refresh(){if(status==STATUS::ON)on();} + +// Refreshes LED color by turning device ON if status=ON (if status=BLINKING, new color is automatically used at next blink) + void check(); // Optional check to see if LED output should be paused (check is bypassed if pauseDuration=0)