Updated Blinker Class to allow for NULL Blinkable Device
If NULL, all functions are ignored and getPin() returns -1
This commit is contained in:
parent
6fecf2c29f
commit
f2e1f5bc70
|
|
@ -57,6 +57,8 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
|||
this->modelName=modelName;
|
||||
sprintf(this->category,"%d",(int)catID);
|
||||
|
||||
statusLED=new Blinker(statusDevice,autoOffLED);
|
||||
|
||||
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(0)); // required to avoid watchdog timeout messages from ESP32-C3
|
||||
|
||||
if(requestedMaxCon<maxConnections) // if specific request for max connections is less than computed max connections
|
||||
|
|
|
|||
|
|
@ -204,7 +204,8 @@ class Span{
|
|||
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
|
||||
|
||||
WiFiServer *hapServer; // pointer to the HAP Server connection
|
||||
Blinker *statusLED = NULL; // indicates HomeSpan status
|
||||
Blinker *statusLED; // indicates HomeSpan status
|
||||
Blinkable *statusDevice = NULL; // the device used for the Blinker
|
||||
PushButton *controlButton = NULL; // controls HomeSpan configuration and resets
|
||||
Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point
|
||||
SpanWebLog webLog; // optional web status/log
|
||||
|
|
@ -255,11 +256,9 @@ class Span{
|
|||
boolean updateDatabase(boolean updateMDNS=true); // updates HAP Configuration Number and Loop vector; if updateMDNS=true and config number has changed, re-broadcasts MDNS 'c#' record; returns true if config number changed
|
||||
boolean deleteAccessory(uint32_t aid); // deletes Accessory with matching aid; returns true if found, else returns false
|
||||
|
||||
void setControlPin(uint8_t pin){controlButton=new PushButton(pin);} // sets Control Pin
|
||||
// void setStatusPin(uint8_t pin){statusLED=new Blinker(new LED(pin),autoOffLED);} // sets Status Pin
|
||||
void setStatusPin(uint8_t pin){statusLED=new Blinker(new Pixel(8),autoOffLED);} // sets Status Pin
|
||||
// void setStatusPin(Blinkable *led){statusLED=new Blinker(led,autoOffLED);} // sets Status Blinkable LED
|
||||
|
||||
void setControlPin(uint8_t pin){controlButton=new PushButton(pin);} // sets Control Pin
|
||||
void setStatusPin(uint8_t pin){statusDevice=new LED(pin);} // sets Status Device to a simple LED on specified pin
|
||||
void setStatusDevice(Blinkable *dev){statusDevice=dev;} // sets Status Device to generic Blinkable object
|
||||
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
||||
int getStatusPin(){return(statusLED?statusLED->getPin():-1);} // get Status Pin (returns -1 if undefined)
|
||||
int getControlPin(){return(controlButton?controlButton->getPin():-1);} // get Control Pin (returns -1 if undefined)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,10 @@ void Blinker::start(int period, float dutyCycle){
|
|||
//////////////////////////////////////
|
||||
|
||||
void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
||||
|
||||
|
||||
if(!led)
|
||||
return;
|
||||
|
||||
onTime=dutyCycle*period;
|
||||
offTime=period-onTime;
|
||||
this->delayTime=delayTime+offTime;
|
||||
|
|
@ -81,6 +84,9 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
|||
//////////////////////////////////////
|
||||
|
||||
void Blinker::stop(){
|
||||
|
||||
if(!led)
|
||||
return;
|
||||
|
||||
if(blinkHandle!=NULL){
|
||||
Serial.printf("Deleting Blink Task\n");
|
||||
|
|
@ -95,6 +101,9 @@ void Blinker::stop(){
|
|||
|
||||
void Blinker::on(){
|
||||
|
||||
if(!led)
|
||||
return;
|
||||
|
||||
stop();
|
||||
led->on();
|
||||
|
||||
|
|
@ -106,6 +115,9 @@ void Blinker::on(){
|
|||
|
||||
void Blinker::off(){
|
||||
|
||||
if(!led)
|
||||
return;
|
||||
|
||||
stop();
|
||||
led->off();
|
||||
}
|
||||
|
|
@ -114,6 +126,9 @@ void Blinker::off(){
|
|||
|
||||
void Blinker::check(){
|
||||
|
||||
if(!led)
|
||||
return;
|
||||
|
||||
if(pauseDuration==0 || isPaused || (millis()-pauseTime)<pauseDuration)
|
||||
return;
|
||||
|
||||
|
|
@ -124,5 +139,9 @@ void Blinker::check(){
|
|||
//////////////////////////////////////
|
||||
|
||||
int Blinker::getPin(){
|
||||
|
||||
if(!led)
|
||||
return(-1);
|
||||
|
||||
return(led->getPin());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
|
||||
#include "Blinker.h"
|
||||
#include "Pixel.h"
|
||||
#include <Wire.h>
|
||||
|
||||
//Blinker p(new LED(26));
|
||||
Blinker p(new Pixel(8));
|
||||
Blinker p(new Pixel(2),10);
|
||||
//Blinker p(NULL,10);
|
||||
|
||||
void setup() {
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ void setup() {
|
|||
delay(1000); // wait for interface to flush
|
||||
|
||||
Serial.println("\n\nHomeSpan Blinker Example\n");
|
||||
// Serial.printf("Pins = %d %d\n",b.getPin(),p.getPin());
|
||||
Serial.printf("Pins = %d\n",p.getPin());
|
||||
|
||||
p.on();
|
||||
delay(2000);
|
||||
|
|
@ -24,8 +25,6 @@ void setup() {
|
|||
delay(5000);
|
||||
Serial.printf("New Pattern\n");
|
||||
p.start(200,0.2,2,200);
|
||||
delay(3000);
|
||||
p.off();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
|
|
|||
Loading…
Reference in New Issue