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.
This commit is contained in:
Gregg 2023-01-07 17:09:22 -06:00
parent 9ef9a590da
commit a8271c8724
3 changed files with 12 additions and 0 deletions

View File

@ -301,6 +301,7 @@ class Span{
} }
void setStatusDevice(Blinkable *sDev){statusDevice=sDev;} 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 setApSSID(const char *ssid){network.apSSID=ssid;} // sets Access Point SSID
void setApPassword(const char *pwd){network.apPassword=pwd;} // sets Access Point Password void setApPassword(const char *pwd){network.apPassword=pwd;} // sets Access Point Password

View File

@ -78,6 +78,7 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
pauseTime=millis(); pauseTime=millis();
isPaused=false; isPaused=false;
status=STATUS::BLINKING;
} }
////////////////////////////////////// //////////////////////////////////////
@ -93,6 +94,7 @@ void Blinker::stop(){
} }
isPaused=true; isPaused=true;
status=STATUS::OFF;
} }
////////////////////////////////////// //////////////////////////////////////
@ -107,6 +109,7 @@ void Blinker::on(){
pauseTime=millis(); pauseTime=millis();
isPaused=false; isPaused=false;
status=STATUS::ON;
} }
////////////////////////////////////// //////////////////////////////////////
@ -118,6 +121,7 @@ void Blinker::off(){
stop(); stop();
led->off(); led->off();
status=STATUS::OFF;
} }
////////////////////////////////////// //////////////////////////////////////

View File

@ -47,6 +47,8 @@ class Blinkable {
//////////////////////////////// ////////////////////////////////
class Blinker { class Blinker {
enum STATUS {OFF, BLINKING, ON};
TaskHandle_t blinkHandle = NULL; TaskHandle_t blinkHandle = NULL;
Blinkable *led; Blinkable *led;
@ -55,6 +57,7 @@ class Blinker {
int onTime; int onTime;
int offTime; int offTime;
int delayTime; int delayTime;
STATUS status=STATUS::OFF;
unsigned long pauseDuration; unsigned long pauseDuration;
unsigned long pauseTime; unsigned long pauseTime;
@ -102,6 +105,10 @@ class Blinker {
// Stops current blinking pattern and turns off LED // 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(); void check();
// Optional check to see if LED output should be paused (check is bypassed if pauseDuration=0) // Optional check to see if LED output should be paused (check is bypassed if pauseDuration=0)