starting update of ControlPin logic to make it more generic
This commit is contained in:
parent
d3ef339e1a
commit
57d791178c
|
|
@ -59,7 +59,6 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
|||
|
||||
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(0)); // required to avoid watchdog timeout messages from ESP32-C3
|
||||
|
||||
controlButton.init(controlPin);
|
||||
statusLED.init(statusPin,0,autoOffLED);
|
||||
|
||||
if(requestedMaxCon<maxConnections) // if specific request for max connections is less than computed max connections
|
||||
|
|
@ -105,8 +104,8 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
|||
else
|
||||
Serial.print("- *** WARNING: Status LED Pin is UNDEFINED");
|
||||
Serial.print("\nDevice Control: Pin ");
|
||||
if(controlPin>=0)
|
||||
Serial.print(controlPin);
|
||||
if(getControlPin()>=0)
|
||||
Serial.print(getControlPin());
|
||||
else
|
||||
Serial.print("- *** WARNING: Device Control Pin is UNDEFINED");
|
||||
Serial.print("\nSketch Version: ");
|
||||
|
|
@ -196,7 +195,8 @@ void Span::pollTask() {
|
|||
homeSpan.statusLED.start(LED_WIFI_CONNECTING);
|
||||
}
|
||||
|
||||
controlButton.reset();
|
||||
if(controlButton)
|
||||
controlButton->reset();
|
||||
|
||||
Serial.print(displayName);
|
||||
Serial.print(" is READY!\n\n");
|
||||
|
|
@ -290,14 +290,14 @@ void Span::pollTask() {
|
|||
if(spanOTA.enabled)
|
||||
ArduinoOTA.handle();
|
||||
|
||||
if(controlButton.primed()){
|
||||
if(controlButton && controlButton->primed()){
|
||||
statusLED.start(LED_ALERT);
|
||||
}
|
||||
|
||||
if(controlButton.triggered(3000,10000)){
|
||||
if(controlButton && controlButton->triggered(3000,10000)){
|
||||
statusLED.off();
|
||||
if(controlButton.type()==PushButton::LONG){
|
||||
controlButton.wait();
|
||||
if(controlButton->type()==PushButton::LONG){
|
||||
controlButton->wait();
|
||||
processSerialCommand("F"); // FACTORY RESET
|
||||
} else {
|
||||
commandMode(); // COMMAND MODE
|
||||
|
|
@ -341,8 +341,8 @@ void Span::commandMode(){
|
|||
statusLED.start(LED_ALERT);
|
||||
delay(2000);
|
||||
} else
|
||||
if(controlButton.triggered(10,3000)){
|
||||
if(controlButton.type()==PushButton::SINGLE){
|
||||
if(controlButton->triggered(10,3000)){
|
||||
if(controlButton->type()==PushButton::SINGLE){
|
||||
mode++;
|
||||
if(mode==6)
|
||||
mode=1;
|
||||
|
|
@ -354,7 +354,7 @@ void Span::commandMode(){
|
|||
} // while
|
||||
|
||||
statusLED.start(LED_ALERT);
|
||||
controlButton.wait();
|
||||
controlButton->wait();
|
||||
|
||||
switch(mode){
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ class Span{
|
|||
const char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
|
||||
int statusPin=DEFAULT_STATUS_PIN; // pin for Status LED
|
||||
uint16_t autoOffLED=0; // automatic turn-off duration (in seconds) for Status LED
|
||||
int 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 maxConnections=CONFIG_LWIP_MAX_SOCKETS-2; // maximum number of allowed simultaneous HAP connections
|
||||
uint8_t requestedMaxCon=CONFIG_LWIP_MAX_SOCKETS-2; // requested maximum number of simultaneous HAP connections
|
||||
|
|
@ -205,7 +205,7 @@ class Span{
|
|||
|
||||
WiFiServer *hapServer; // pointer to the HAP Server connection
|
||||
Blinker statusLED; // indicates HomeSpan status
|
||||
PushButton controlButton; // 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
|
||||
SpanWebLog webLog; // optional web status/log
|
||||
TaskHandle_t pollTaskHandle = NULL; // optional task handle to use for poll() function
|
||||
|
|
@ -255,10 +255,11 @@ 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){controlPin=pin;} // sets Control Pin
|
||||
void setControlPin(uint8_t pin){controlButton=new PushButton(pin);} // sets Control Pin
|
||||
void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin
|
||||
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
||||
int getStatusPin(){return(statusPin);} // get Status Pin
|
||||
int getControlPin(){return(controlButton?controlButton->getPin():-1);} // get Control Pin (returns -1 if undefined)
|
||||
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 setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds)
|
||||
|
|
|
|||
|
|
@ -152,10 +152,10 @@ void Network::apConfigure(){
|
|||
|
||||
while(1){ // loop until we get timed out (which will be accelerated if save/cancel selected)
|
||||
|
||||
if(homeSpan.controlButton.triggered(9999,3000)){
|
||||
if(homeSpan.controlButton && homeSpan.controlButton->triggered(9999,3000)){
|
||||
Serial.print("\n*** Access Point Terminated.");
|
||||
homeSpan.statusLED.start(LED_ALERT);
|
||||
homeSpan.controlButton.wait();
|
||||
homeSpan.controlButton->wait();
|
||||
Serial.print(" Restarting... \n\n");
|
||||
homeSpan.statusLED.off();
|
||||
ESP.restart();
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
#define DEFAULT_QR_ID "HSPN" // change with homeSpan.setQRID(qrID);
|
||||
|
||||
#define DEFAULT_CONTROL_PIN -1 // change with homeSpan.setControlPin(pin)
|
||||
//#define DEFAULT_CONTROL_PIN -1 // change with homeSpan.setControlPin(pin)
|
||||
#define DEFAULT_STATUS_PIN -1 // change with homeSpan.setStatusPin(pin)
|
||||
|
||||
#define DEFAULT_AP_SSID "HomeSpan-Setup" // change with homeSpan.setApSSID(ssid)
|
||||
|
|
|
|||
|
|
@ -148,6 +148,10 @@ class PushButton{
|
|||
|
||||
// Waits for button to be released. Use after Long Press if button release confirmation is desired
|
||||
|
||||
int getPin(){return(pin);}
|
||||
|
||||
// Returns pin number
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ void setup() {
|
|||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setLogLevel(2);
|
||||
// homeSpan.setLogLevel(2);
|
||||
// homeSpan.setStatusPin(13);
|
||||
// homeSpan.setControlPin(33);
|
||||
homeSpan.setControlPin(33);
|
||||
|
||||
homeSpan.setHostNameSuffix("-lamp1");
|
||||
homeSpan.setPortNum(1201);
|
||||
|
|
|
|||
Loading…
Reference in New Issue