From 40bb97215f73153a5e5fb97ede0e4316d0759ff5 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 13 May 2023 10:34:21 -0500 Subject: [PATCH] Added homeSpan methods setSerialInputDisable() and getSerialInputDisable() Provides ability to disable HomeSpan from reading from Serial port (which is otherwise normally enabled) --- src/HomeSpan.cpp | 12 +++++++----- src/HomeSpan.h | 3 +++ src/Utils.cpp | 6 ++++++ src/src.ino | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index ce3b823..3b1ada5 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -206,7 +206,7 @@ void Span::pollTask() { char cBuf[65]="?"; - if(Serial.available()){ + if(!serialInputDisabled && Serial.available()){ readSerial(cBuf,64); processSerialCommand(cBuf); } @@ -708,6 +708,9 @@ void Span::processSerialCommand(const char *c){ case 'W': { + if(serialInputDisabled || logLevel<0) // do not proceed if serial input/output is not fully enabled + return; + if(strlen(network.wifiData.ssid)>0){ LOG0("*** Stopping all current WiFi services...\n\n"); hapServer->end(); @@ -817,14 +820,13 @@ void Span::processSerialCommand(const char *c){ int level=0; sscanf(c+1,"%d",&level); - if(level<0) - level=0; + if(level<-1) + level=-1; if(level>2) level=2; - LOG0("\n*** Log Level set to %d\n\n",level); - delay(1000); setLogLevel(level); + LOG0("\n*** Log Level set to %d\n\n",level); } break; diff --git a/src/HomeSpan.h b/src/HomeSpan.h index ff99ca3..5a22b59 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -216,6 +216,7 @@ class Span{ char pairingCodeCommand[12]=""; // user-specified Pairing Code - only needed if Pairing Setup Code is specified in sketch using setPairingCode() String lastClientIP="0.0.0.0"; // IP address of last client accessing device through encrypted channel boolean newCode; // flag indicating new application code has been loaded (based on keeping track of app SHA256) + boolean serialInputDisabled=false; // flag indiating that serial input is disabled int connected=0; // WiFi connection status (increments upon each connect and disconnect) unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts @@ -309,6 +310,8 @@ class Span{ void setCommandTimeout(uint16_t nSec){comModeLife=nSec*1000;} // sets Command Mode Timeout (seconds) void setLogLevel(int level){logLevel=level;} // sets Log Level for log messages (0=baseline, 1=intermediate, 2=all, -1=disable all serial input/output) int getLogLevel(){return(logLevel);} // get Log Level + void setSerialInputDisable(boolean val){serialInputDisabled=val;} // sets whether serial input is disabled (true) or enabled (false) + boolean getSerialInputDisable(){return(serialInputDisabled);} // returns true if serial input is disabled, or false if serial input in enabled void reserveSocketConnections(uint8_t n){maxConnections-=n;} // reserves n socket connections *not* to be used for HAP void setHostNameSuffix(const char *suffix){hostNameSuffix=suffix;} // sets the hostName suffix to be used instead of the 6-byte AccessoryID void setPortNum(uint16_t port){tcpPortNum=port;} // sets the TCP port number to use for communications between HomeKit and HomeSpan diff --git a/src/Utils.cpp b/src/Utils.cpp index 7645405..7af158e 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -40,6 +40,12 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// char *Utils::readSerial(char *c, int max){ + + if(homeSpan.getSerialInputDisable()){ + c[0]='\0'; + return(c); + } + int i=0; char buf; diff --git a/src/src.ino b/src/src.ino index 03d1a50..10995ba 100644 --- a/src/src.ino +++ b/src/src.ino @@ -53,6 +53,7 @@ void setup() { Serial.begin(115200); // homeSpan.setLogLevel(-1); + homeSpan.setSerialInputDisable(true); homeSpan.enableOTA(); homeSpan.setStatusPin(13);