Removed use of LED_BUILTIN in library and all examples

LED_BUILTIN is NOT defined for all ESP32 boards - some do not have a built-in LED!  Instead, Status LED now defaults to Pin 13, as opposed to LED_BUILTIN.  Also, added a new method, homeSpan.getStatusPin(), to return the pin number used for the Status LED, whether or not it remains the default (13) or is changed by user with homeSpan.setStatusPin(pin).  This method is now used in the DEV_Identify.h file for each example, instead of using LED_BUILTIN (which otherwise won't compile for boards without a built-in LED)
This commit is contained in:
Gregg 2021-01-09 12:51:35 -06:00
parent 8d55d0a60e
commit b8d4940772
13 changed files with 51 additions and 52 deletions

View File

@ -23,9 +23,9 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
// How HomeKit Identifies Devices:
@ -39,20 +39,22 @@ struct DEV_Identify : Service::AccessoryInformation {
// There are many ways to implement some form of identification. For an LED, you could blink it one or more times.
// For a LightBulb, you can flash it on and off. For window shade, you could raise and lower it.
// Most commerical devices don't do anything. Because HomeSpan can be used to control many different types of
// device, below we implement a very generic routine that simply blinks the internal LED of the ESP32 the
// number of times specified above. In principle, this code could call a user-defined routine that is different
// for each physcially-attached device (light, shade, fan, etc), but in practice this is overkill.
// device, below we implement a very generic routine that simply blinks the Status LED the number of times specified above.
// In principle, this code could call a user-defined routine that is different for each physcially-attached device (light, shade, fan, etc),
// but in practice this is overkill.
// Note that the blink routine below starts by turning off the built-in LED and then leaves it on once it has blinked
// Note that the blink routine below starts by turning off the Status LED and then leaves it on once it has blinked
// the specified number of times. This is because when HomeSpan starts up if confirms to user that it has connected
// to the WiFi network by turning on the built-in LED. Thus we want to leave it on when blinking is completed.
// to the WiFi network by turning on the Status LED. Thus we want to leave it on when blinking is completed.
// Also note we use the homeSpan.getStatusPin() method to find the pin number associated with the Status LED
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -17,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -17,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -17,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -17,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -8,8 +8,6 @@ struct DEV_Identify : Service::AccessoryInformation {
int nBlinks; // number of times to blink built-in LED in identify routine
SpanCharacteristic *identify; // reference to the Identify Characteristic
// NEW! modified constructor() method to include optional ServiceType argument
DEV_Identify(const char *name, const char *manu, const char *sn, const char *model, const char *version, int nBlinks) : Service::AccessoryInformation(){
new Characteristic::Name(name); // create all the required Characteristics with values set based on above arguments
@ -19,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -8,8 +8,6 @@ struct DEV_Identify : Service::AccessoryInformation {
int nBlinks; // number of times to blink built-in LED in identify routine
SpanCharacteristic *identify; // reference to the Identify Characteristic
// NEW! modified constructor() method to include optional ServiceType argument
DEV_Identify(const char *name, const char *manu, const char *sn, const char *model, const char *version, int nBlinks) : Service::AccessoryInformation(){
new Characteristic::Name(name); // create all the required Characteristics with values set based on above arguments
@ -19,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -17,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -17,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -17,17 +17,17 @@ struct DEV_Identify : Service::AccessoryInformation {
new Characteristic::FirmwareRevision(version);
identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below
this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
this->nBlinks=nBlinks; // store the number of times to blink the LED
pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(LED_BUILTIN,HIGH);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}

View File

@ -67,7 +67,7 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
"** Please ensure serial monitor is set to transmit <newlines>\n\n");
Serial.print("Message Logs: Level ");
Serial.print(homeSpan.logLevel);
Serial.print(logLevel);
Serial.print("\nStatus LED: Pin ");
Serial.print(statusPin);
Serial.print("\nDevice Control: Pin ");
@ -82,7 +82,7 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
Serial.print(__TIME__);
Serial.print("\n\nDevice Name: ");
Serial.print(homeSpan.displayName);
Serial.print(displayName);
Serial.print("\n\n");
} // begin

View File

@ -134,6 +134,7 @@ struct Span{
void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin
void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin
int getStatusPin(){return(statusPin);} // gets Status Pin
void setApSSID(char *ssid){network.apSSID=ssid;} // sets Access Point SSID
void setApPassword(char *pwd){network.apPassword=pwd;} // sets Access Point Password
void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds)

View File

@ -62,7 +62,7 @@
#define DEFAULT_SETUP_CODE "46637726" // changed during network setup or with 'S' command
#define DEFAULT_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin)
#define DEFAULT_STATUS_PIN LED_BUILTIN // change with homeSpan.setStatusPin(pin)
#define DEFAULT_STATUS_PIN 13 // change with homeSpan.setStatusPin(pin)
#define DEFAULT_AP_SSID "HomeSpan-Setup" // change with homeSpan.setApSSID(pwd)
#define DEFAULT_AP_PASSWORD "homespan" // change with homeSpan.setApPassword(pwd)