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;
|
this->modelName=modelName;
|
||||||
sprintf(this->category,"%d",(int)catID);
|
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
|
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
|
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
|
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
|
||||||
|
|
||||||
WiFiServer *hapServer; // pointer to the HAP Server connection
|
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
|
PushButton *controlButton = NULL; // controls HomeSpan configuration and resets
|
||||||
Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point
|
Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point
|
||||||
SpanWebLog webLog; // optional web status/log
|
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 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
|
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 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){statusDevice=new LED(pin);} // sets Status Device to a simple LED on specified pin
|
||||||
void setStatusPin(uint8_t pin){statusLED=new Blinker(new Pixel(8),autoOffLED);} // sets Status Pin
|
void setStatusDevice(Blinkable *dev){statusDevice=dev;} // sets Status Device to generic Blinkable object
|
||||||
// void setStatusPin(Blinkable *led){statusLED=new Blinker(led,autoOffLED);} // sets Status Blinkable LED
|
|
||||||
|
|
||||||
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
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 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)
|
int getControlPin(){return(controlButton?controlButton->getPin():-1);} // get Control Pin (returns -1 if undefined)
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,9 @@ void Blinker::start(int period, float dutyCycle){
|
||||||
|
|
||||||
void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
||||||
|
|
||||||
|
if(!led)
|
||||||
|
return;
|
||||||
|
|
||||||
onTime=dutyCycle*period;
|
onTime=dutyCycle*period;
|
||||||
offTime=period-onTime;
|
offTime=period-onTime;
|
||||||
this->delayTime=delayTime+offTime;
|
this->delayTime=delayTime+offTime;
|
||||||
|
|
@ -82,6 +85,9 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
||||||
|
|
||||||
void Blinker::stop(){
|
void Blinker::stop(){
|
||||||
|
|
||||||
|
if(!led)
|
||||||
|
return;
|
||||||
|
|
||||||
if(blinkHandle!=NULL){
|
if(blinkHandle!=NULL){
|
||||||
Serial.printf("Deleting Blink Task\n");
|
Serial.printf("Deleting Blink Task\n");
|
||||||
vTaskDelete(blinkHandle);
|
vTaskDelete(blinkHandle);
|
||||||
|
|
@ -95,6 +101,9 @@ void Blinker::stop(){
|
||||||
|
|
||||||
void Blinker::on(){
|
void Blinker::on(){
|
||||||
|
|
||||||
|
if(!led)
|
||||||
|
return;
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
led->on();
|
led->on();
|
||||||
|
|
||||||
|
|
@ -106,6 +115,9 @@ void Blinker::on(){
|
||||||
|
|
||||||
void Blinker::off(){
|
void Blinker::off(){
|
||||||
|
|
||||||
|
if(!led)
|
||||||
|
return;
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
led->off();
|
led->off();
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +126,9 @@ void Blinker::off(){
|
||||||
|
|
||||||
void Blinker::check(){
|
void Blinker::check(){
|
||||||
|
|
||||||
|
if(!led)
|
||||||
|
return;
|
||||||
|
|
||||||
if(pauseDuration==0 || isPaused || (millis()-pauseTime)<pauseDuration)
|
if(pauseDuration==0 || isPaused || (millis()-pauseTime)<pauseDuration)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -124,5 +139,9 @@ void Blinker::check(){
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
int Blinker::getPin(){
|
int Blinker::getPin(){
|
||||||
|
|
||||||
|
if(!led)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
return(led->getPin());
|
return(led->getPin());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
#include "Blinker.h"
|
#include "Blinker.h"
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
//Blinker p(new LED(26));
|
Blinker p(new Pixel(2),10);
|
||||||
Blinker p(new Pixel(8));
|
//Blinker p(NULL,10);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ void setup() {
|
||||||
delay(1000); // wait for interface to flush
|
delay(1000); // wait for interface to flush
|
||||||
|
|
||||||
Serial.println("\n\nHomeSpan Blinker Example\n");
|
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();
|
p.on();
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
@ -24,8 +25,6 @@ void setup() {
|
||||||
delay(5000);
|
delay(5000);
|
||||||
Serial.printf("New Pattern\n");
|
Serial.printf("New Pattern\n");
|
||||||
p.start(200,0.2,2,200);
|
p.start(200,0.2,2,200);
|
||||||
delay(3000);
|
|
||||||
p.off();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue