CHANGED default settings for StatusPin and ControlPin

Re-worked code to allow for NO Status LED Pin and NO Control Pin.  If Control Pin is not set explicitly with homeSpan.setControlPin(), there will be no Control Pin.  There is no longer a default since there are too many board variations with S2 and C3 chips now supported.  Same for Status Pin - it will not be defined unless set explicitly with homeSpan.setStatusPin(), with the exception that if LED_BUILTIN is defined (i.e. there is a built-in LED), then the Status LED Pin will default to LED_BUILTIN if not explicitly defined.  MUST UPDATE DOCUMENTATION - THIS CHANGES DEFAULT BEHAVIOR OF HOMESPAN AND MAY REQUIRE UPDATES TO EXISTING SKETCHES
This commit is contained in:
Gregg 2021-10-05 21:10:24 -05:00
parent b95ebcb4fa
commit 6de645216c
5 changed files with 60 additions and 17 deletions

View File

@ -95,14 +95,20 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
Serial.print("Message Logs: Level "); Serial.print("Message Logs: Level ");
Serial.print(logLevel); Serial.print(logLevel);
Serial.print("\nStatus LED: Pin "); Serial.print("\nStatus LED: Pin ");
if(statusPin>=0)
Serial.print(statusPin); Serial.print(statusPin);
else
Serial.print("- *** WARNING: Status LED Pin is UNDEFINED");
Serial.print("\nDevice Control: Pin "); Serial.print("\nDevice Control: Pin ");
if(controlPin>=0)
Serial.print(controlPin); Serial.print(controlPin);
else
Serial.print("- *** WARNING: Device Control Pin is UNDEFINED");
Serial.print("\nSketch Version: "); Serial.print("\nSketch Version: ");
Serial.print(getSketchVersion()); Serial.print(getSketchVersion());
Serial.print("\nHomeSpan Version: "); Serial.print("\nHomeSpan Version: ");
Serial.print(HOMESPAN_VERSION); Serial.print(HOMESPAN_VERSION);
Serial.print("\nArduino-ESP Ver: "); Serial.print("\nArduino-ESP Ver.: ");
Serial.print(ARDUINO_ESP_VERSION); Serial.print(ARDUINO_ESP_VERSION);
Serial.printf("\nESP-IDF Version: %d.%d.%d",ESP_IDF_VERSION_MAJOR,ESP_IDF_VERSION_MINOR,ESP_IDF_VERSION_PATCH); Serial.printf("\nESP-IDF Version: %d.%d.%d",ESP_IDF_VERSION_MAJOR,ESP_IDF_VERSION_MINOR,ESP_IDF_VERSION_PATCH);
Serial.printf("\nESP32 Chip: %s Rev %d %s-core %dMB Flash", ESP.getChipModel(),ESP.getChipRevision(), Serial.printf("\nESP32 Chip: %s Rev %d %s-core %dMB Flash", ESP.getChipModel(),ESP.getChipRevision(),

View File

@ -118,8 +118,8 @@ struct Span{
unsigned long alarmConnect=0; // time after which WiFi connection attempt should be tried again unsigned long alarmConnect=0; // time after which WiFi connection attempt should be tried again
const char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing const char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
uint8_t statusPin=DEFAULT_STATUS_PIN; // pin for status LED int statusPin=DEFAULT_STATUS_PIN; // pin for status LED
uint8_t controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton int controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton
uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor
uint8_t maxConnections=DEFAULT_MAX_CONNECTIONS; // number of simultaneous HAP connections uint8_t maxConnections=DEFAULT_MAX_CONNECTIONS; // number of simultaneous HAP connections
unsigned long comModeLife=DEFAULT_COMMAND_TIMEOUT*1000; // length of time (in milliseconds) to keep Command Mode alive before resuming normal operations unsigned long comModeLife=DEFAULT_COMMAND_TIMEOUT*1000; // length of time (in milliseconds) to keep Command Mode alive before resuming normal operations
@ -171,7 +171,7 @@ struct Span{
void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin void setControlPin(uint8_t pin){controlPin=pin;} // sets Control Pin
void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin
int getStatusPin(){return(statusPin);} // gets Status Pin int getStatusPin(){return(statusPin);} // get Status Pin
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
void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds) void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds)

View File

@ -67,8 +67,13 @@
#define DEFAULT_QR_ID "HSPN" // change with homeSpan.setQRID(qrID); #define DEFAULT_QR_ID "HSPN" // change with homeSpan.setQRID(qrID);
#define DEFAULT_CONTROL_PIN 21 // change with homeSpan.setControlPin(pin) #define DEFAULT_CONTROL_PIN -1 // change with homeSpan.setControlPin(pin)
#define DEFAULT_STATUS_PIN 13 // change with homeSpan.setStatusPin(pin)
#ifdef LED_BUILTIN
#define DEFAULT_STATUS_PIN LED_BUILTIN // change with homeSpan.setStatusPin(pin)
#else
#define DEFAULT_STATUS_PIN -1 // change with homeSpan.setStatusPin(pin)
#endif
#define DEFAULT_AP_SSID "HomeSpan-Setup" // change with homeSpan.setApSSID(ssid) #define DEFAULT_AP_SSID "HomeSpan-Setup" // change with homeSpan.setApSSID(ssid)
#define DEFAULT_AP_PASSWORD "homespan" // change with homeSpan.setApPassword(pwd) #define DEFAULT_AP_PASSWORD "homespan" // change with homeSpan.setApPassword(pwd)
@ -82,7 +87,6 @@
#define DEFAULT_MAX_CONNECTIONS 8 // change with homeSpan.setMaxConnections(num); #define DEFAULT_MAX_CONNECTIONS 8 // change with homeSpan.setMaxConnections(num);
#define DEFAULT_TCP_PORT 80 // change with homeSpan.setPort(port); #define DEFAULT_TCP_PORT 80 // change with homeSpan.setPort(port);
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// STATUS LED SETTINGS // // STATUS LED SETTINGS //

View File

@ -89,13 +89,17 @@ PushButton::PushButton(){}
////////////////////////////////////// //////////////////////////////////////
PushButton::PushButton(uint8_t pin){ PushButton::PushButton(int pin){
init(pin); init(pin);
} }
////////////////////////////////////// //////////////////////////////////////
void PushButton::init(uint8_t pin){ void PushButton::init(int pin){
if(pin<0)
return;
status=0; status=0;
doubleCheck=false; doubleCheck=false;
this->pin=pin; this->pin=pin;
@ -106,6 +110,9 @@ void PushButton::init(uint8_t pin){
boolean PushButton::triggered(uint16_t singleTime, uint16_t longTime, uint16_t doubleTime){ boolean PushButton::triggered(uint16_t singleTime, uint16_t longTime, uint16_t doubleTime){
if(pin<0)
return(false);
unsigned long cTime=millis(); unsigned long cTime=millis();
switch(status){ switch(status){
@ -183,6 +190,9 @@ boolean PushButton::triggered(uint16_t singleTime, uint16_t longTime, uint16_t d
boolean PushButton::primed(){ boolean PushButton::primed(){
if(pin<0)
return(false);
if(millis()>singleAlarm && status==1){ if(millis()>singleAlarm && status==1){
status=2; status=2;
return(true); return(true);
@ -200,6 +210,10 @@ int PushButton::type(){
////////////////////////////////////// //////////////////////////////////////
void PushButton::wait(){ void PushButton::wait(){
if(pin<0)
return;
while(!digitalRead(pin)); while(!digitalRead(pin));
} }
@ -225,7 +239,11 @@ Blinker::Blinker(int pin, int timerNum){
////////////////////////////////////// //////////////////////////////////////
void Blinker::init(int pin, int timerNum){ void Blinker::init(int pin, int timerNum){
this->pin=pin; this->pin=pin;
if(pin<0)
return;
pinMode(pin,OUTPUT); pinMode(pin,OUTPUT);
digitalWrite(pin,0); digitalWrite(pin,0);
@ -322,6 +340,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(pin<0)
return;
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT_OUTPUT); // needed to ensure digitalRead() functions correctly on ESP32-C3 gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT_OUTPUT); // needed to ensure digitalRead() functions correctly on ESP32-C3
period*=10; period*=10;
@ -338,12 +359,20 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
////////////////////////////////////// //////////////////////////////////////
void Blinker::stop(){ void Blinker::stop(){
if(pin<0)
return;
timer_pause(group,idx); timer_pause(group,idx);
} }
////////////////////////////////////// //////////////////////////////////////
void Blinker::on(){ void Blinker::on(){
if(pin<0)
return;
stop(); stop();
digitalWrite(pin,1); digitalWrite(pin,1);
} }
@ -351,6 +380,10 @@ void Blinker::on(){
////////////////////////////////////// //////////////////////////////////////
void Blinker::off(){ void Blinker::off(){
if(pin<0)
return;
stop(); stop();
digitalWrite(pin,0); digitalWrite(pin,0);
} }

View File

@ -74,7 +74,7 @@ struct TempBuffer {
class PushButton{ class PushButton{
int status; int status;
uint8_t pin; int pin;
boolean doubleCheck; boolean doubleCheck;
uint32_t singleAlarm; uint32_t singleAlarm;
uint32_t doubleAlarm; uint32_t doubleAlarm;
@ -90,7 +90,7 @@ class PushButton{
}; };
PushButton(); PushButton();
PushButton(uint8_t pin); PushButton(int pin);
// Creates generic pushbutton functionality on specified pin // Creates generic pushbutton functionality on specified pin
// that is wired to connect to ground when the button is pressed. // that is wired to connect to ground when the button is pressed.
@ -104,7 +104,7 @@ class PushButton{
// //
// pin: Pin mumber to which pushbutton connects to ground when pressed // pin: Pin mumber to which pushbutton connects to ground when pressed
void init(uint8_t pin); void init(int pin);
// Initializes PushButton, if not configured during instantiation. // Initializes PushButton, if not configured during instantiation.
// //