From b8d49407724fbc794e09b5b4fc6cbafc6f51fea2 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 9 Jan 2021 12:51:35 -0600 Subject: [PATCH] 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) --- examples/07-IdentifyRoutines/DEV_Identify.h | 20 ++++++++++--------- examples/08-Bridges/DEV_Identify.h | 8 ++++---- examples/09-MessageLogging/DEV_Identify.h | 8 ++++---- examples/10-RGB_LED/DEV_Identify.h | 8 ++++---- examples/11-ServiceOptions/DEV_Identify.h | 8 ++++---- examples/12-ServiceLoops/DEV_Identify.h | 10 ++++------ examples/13-TargetStates/DEV_Identify.h | 10 ++++------ .../14-EmulatedPushButtons/DEV_Identify.h | 8 ++++---- examples/15-RealPushButtons/DEV_Identify.h | 8 ++++---- .../16-ProgrammableSwitches/DEV_Identify.h | 8 ++++---- src/HomeSpan.cpp | 4 ++-- src/HomeSpan.h | 1 + src/Settings.h | 2 +- 13 files changed, 51 insertions(+), 52 deletions(-) diff --git a/examples/07-IdentifyRoutines/DEV_Identify.h b/examples/07-IdentifyRoutines/DEV_Identify.h index 4e2c5fc..01e591b 100644 --- a/examples/07-IdentifyRoutines/DEV_Identify.h +++ b/examples/07-IdentifyRoutines/DEV_Identify.h @@ -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;inBlinks=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;inBlinks=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;inBlinks=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;inBlinks=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;inBlinks=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;inBlinks=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;inBlinks=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;inBlinks=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;inBlinks=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\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 diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 6662345..ebbf623 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -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) diff --git a/src/Settings.h b/src/Settings.h index 1419bc9..5e5638d 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -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)