diff --git a/src/HAP.cpp b/src/HAP.cpp index 9b1c90d..76b3155 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -1418,7 +1418,7 @@ Controller *HAPClient::findController(uint8_t *id){ if(controllers[i].allocated && !memcmp(controllers[i].ID,id,36)){ // found matching ID LOG2("Found Controller: "); - if(VERBOSITY>1) + if(homeSpan.logLevel>1) charPrintRow(id,36); LOG2(controllers[i].admin?" (admin)\n":" (regular)\n"); return(controllers+i); // return with pointer to matching controller @@ -1451,7 +1451,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){ memcpy(slot->LTPK,ltpk,32); slot->admin=admin; LOG2("\n*** Updated Controller: "); - if(VERBOSITY>1) + if(homeSpan.logLevel>1) charPrintRow(id,36); LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n"); return(slot); @@ -1463,7 +1463,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){ memcpy(slot->LTPK,ltpk,32); slot->admin=admin; LOG2("\n*** Added Controller: "); - if(VERBOSITY>1) + if(homeSpan.logLevel>1) charPrintRow(id,36); LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n"); return(slot); @@ -1504,7 +1504,7 @@ void HAPClient::removeController(uint8_t *id){ if(slot=findController(id)){ // remove controller if found LOG2("\n***Removed Controller: "); - if(VERBOSITY>1) + if(homeSpan.logLevel>1) charPrintRow(id,36); LOG2(slot->admin?" (admin)\n":" (regular)\n"); slot->allocated=false; diff --git a/src/HAP.h b/src/HAP.h index 64287d5..c49b6d5 100644 --- a/src/HAP.h +++ b/src/HAP.h @@ -1,4 +1,6 @@ +#pragma once + #include #include diff --git a/src/HAPConstants.h b/src/HAPConstants.h index 37aa57b..3de8557 100644 --- a/src/HAPConstants.h +++ b/src/HAPConstants.h @@ -1,4 +1,6 @@ +#pragma once + // HAP TLV Types (HAP Table 5-6) typedef enum { diff --git a/src/HKDF.h b/src/HKDF.h index 7a5335e..4ab2c2f 100644 --- a/src/HKDF.h +++ b/src/HKDF.h @@ -1,4 +1,6 @@ +#pragma once + #include ///////////////////////////////////////////////// diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 792ecd2..0b236ed 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -34,7 +34,9 @@ void Span::begin(Category catID, char *displayName, char *hostNameBase, char *mo "************************************************************\n\n" "** Please ensure serial monitor is set to transmit \n\n"); - Serial.print("Status LED: Pin "); + Serial.print("Message Logs: Level "); + Serial.print(homeSpan.logLevel); + Serial.print("\nStatus LED: Pin "); Serial.print(statusPin); Serial.print("\nDevice Control: Pin "); Serial.print(controlPin); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index d7bdc68..987ca1c 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -1,4 +1,6 @@ +#pragma once + #ifndef ARDUINO_ARCH_ESP32 #error ERROR: HOMESPAN IS ONLY AVAILABLE FOR ESP32 MICROCONTROLLERS! #endif @@ -53,6 +55,7 @@ struct Span{ char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing uint8_t statusPin=DEFAULT_STATUS_PIN; // pin for status LED uint8_t controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton + uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor Blinker statusLED; // indicates HomeSpan status PushButton controlButton; // controls HomeSpan configuration and resets @@ -91,6 +94,7 @@ struct Span{ void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin 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) + void setLogLevel(uint8_t level){logLevel=level;} // sets Log Level for log messages (0=baseline, 1=intermediate, 2=all) }; /////////////////////////////// diff --git a/src/Network.h b/src/Network.h index 64abfff..d374762 100644 --- a/src/Network.h +++ b/src/Network.h @@ -1,4 +1,6 @@ +#pragma once + #include #include #include "Settings.h" diff --git a/src/SRP.h b/src/SRP.h index f61aba3..dd78a62 100644 --- a/src/SRP.h +++ b/src/SRP.h @@ -1,4 +1,6 @@ +#pragma once + #include #include diff --git a/src/Settings.h b/src/Settings.h index 339a4c2..e25a928 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -24,6 +24,8 @@ #define DEFAULT_AP_TIMEOUT 120 // change with homeSpan.setApTimeout(nSeconds) +#define DEFAULT_LOG_LEVEL 0 // change with homeSpan.setLogLevel(level) + ////////////////////////////////////////////////////// // Maximum number of simultaenous IP connections // // HAP requires at least 8 // @@ -37,24 +39,11 @@ const int MAX_SSID=32; const int MAX_PWD=64; ///////////////////////////////////////////////////// -// Verbosity -- controls message output // +// Message Log Level Control Macros // // 0=Minimal, 1=Informative, 2=All // -#define VERBOSITY 2 - -//-------------------------------------------------// - -#if VERBOSITY>1 - #define LOG2(x) Serial.print(x) -#else - #define LOG2(x) -#endif - -#if VERBOSITY>0 - #define LOG1(x) Serial.print(x) -#else - #define LOG1(x) -#endif +#define LOG1(x) if(homeSpan.logLevel>0)Serial.print(x) +#define LOG2(x) if(homeSpan.logLevel>1)Serial.print(x) ////////////////////////////////////////////////////// // Types of Accessory Categories // diff --git a/src/TLV.h b/src/TLV.h index cec36e1..f210e45 100644 --- a/src/TLV.h +++ b/src/TLV.h @@ -1,5 +1,7 @@ -#include "Settings.h" +#pragma once + +#include "HomeSpan.h" template class TLV { @@ -166,7 +168,7 @@ uint8_t *TLV::buf(tagType tag, int len){ template void TLV::print(){ - if(VERBOSITY<2) + if(homeSpan.logLevel<2) return; char buf[3]; diff --git a/src/Utils.h b/src/Utils.h index dc54710..6b29827 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -1,4 +1,6 @@ +#pragma once + #include #include diff --git a/src/src.ino b/src/src.ino index 542dd5d..1d66932 100644 --- a/src/src.ino +++ b/src/src.ino @@ -7,6 +7,8 @@ void setup() { Serial.begin(115200); + + homeSpan.setLogLevel(2); homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");