Converted VERBOSE macros to LogLevel macros that use real-time if-statements.

This change allows the user to set the log-level with homeSpan.setLogLevel() instead of needing to change in Settings.h.  Next up:  Update Example that introduces VERBOSE to instead use setLogLevel().  Consider adding an interactive 'L' command to change this during run-time.

Also, added "#pragma once" to every *.h file to prevent duplication of definitions.  TO DO:  Review all #include to ensure sanity across all files.
This commit is contained in:
Gregg 2020-09-28 18:04:59 -05:00
parent 381b25860a
commit dee954d5bd
12 changed files with 34 additions and 23 deletions

View File

@ -1418,7 +1418,7 @@ Controller *HAPClient::findController(uint8_t *id){
if(controllers[i].allocated && !memcmp(controllers[i].ID,id,36)){ // found matching ID if(controllers[i].allocated && !memcmp(controllers[i].ID,id,36)){ // found matching ID
LOG2("Found Controller: "); LOG2("Found Controller: ");
if(VERBOSITY>1) if(homeSpan.logLevel>1)
charPrintRow(id,36); charPrintRow(id,36);
LOG2(controllers[i].admin?" (admin)\n":" (regular)\n"); LOG2(controllers[i].admin?" (admin)\n":" (regular)\n");
return(controllers+i); // return with pointer to matching controller 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); memcpy(slot->LTPK,ltpk,32);
slot->admin=admin; slot->admin=admin;
LOG2("\n*** Updated Controller: "); LOG2("\n*** Updated Controller: ");
if(VERBOSITY>1) if(homeSpan.logLevel>1)
charPrintRow(id,36); charPrintRow(id,36);
LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n"); LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n");
return(slot); return(slot);
@ -1463,7 +1463,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){
memcpy(slot->LTPK,ltpk,32); memcpy(slot->LTPK,ltpk,32);
slot->admin=admin; slot->admin=admin;
LOG2("\n*** Added Controller: "); LOG2("\n*** Added Controller: ");
if(VERBOSITY>1) if(homeSpan.logLevel>1)
charPrintRow(id,36); charPrintRow(id,36);
LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n"); LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n");
return(slot); return(slot);
@ -1504,7 +1504,7 @@ void HAPClient::removeController(uint8_t *id){
if(slot=findController(id)){ // remove controller if found if(slot=findController(id)){ // remove controller if found
LOG2("\n***Removed Controller: "); LOG2("\n***Removed Controller: ");
if(VERBOSITY>1) if(homeSpan.logLevel>1)
charPrintRow(id,36); charPrintRow(id,36);
LOG2(slot->admin?" (admin)\n":" (regular)\n"); LOG2(slot->admin?" (admin)\n":" (regular)\n");
slot->allocated=false; slot->allocated=false;

View File

@ -1,4 +1,6 @@
#pragma once
#include <WiFi.h> #include <WiFi.h>
#include <nvs.h> #include <nvs.h>

View File

@ -1,4 +1,6 @@
#pragma once
// HAP TLV Types (HAP Table 5-6) // HAP TLV Types (HAP Table 5-6)
typedef enum { typedef enum {

View File

@ -1,4 +1,6 @@
#pragma once
#include <Arduino.h> #include <Arduino.h>
///////////////////////////////////////////////// /////////////////////////////////////////////////

View File

@ -34,7 +34,9 @@ void Span::begin(Category catID, char *displayName, char *hostNameBase, char *mo
"************************************************************\n\n" "************************************************************\n\n"
"** Please ensure serial monitor is set to transmit <newlines>\n\n"); "** Please ensure serial monitor is set to transmit <newlines>\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(statusPin);
Serial.print("\nDevice Control: Pin "); Serial.print("\nDevice Control: Pin ");
Serial.print(controlPin); Serial.print(controlPin);

View File

@ -1,4 +1,6 @@
#pragma once
#ifndef ARDUINO_ARCH_ESP32 #ifndef ARDUINO_ARCH_ESP32
#error ERROR: HOMESPAN IS ONLY AVAILABLE FOR ESP32 MICROCONTROLLERS! #error ERROR: HOMESPAN IS ONLY AVAILABLE FOR ESP32 MICROCONTROLLERS!
#endif #endif
@ -53,6 +55,7 @@ struct Span{
char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
uint8_t statusPin=DEFAULT_STATUS_PIN; // pin for status LED uint8_t statusPin=DEFAULT_STATUS_PIN; // pin for status LED
uint8_t controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton 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 Blinker statusLED; // indicates HomeSpan status
PushButton controlButton; // controls HomeSpan configuration and resets PushButton controlButton; // controls HomeSpan configuration and resets
@ -91,6 +94,7 @@ struct Span{
void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin void setStatusPin(uint8_t pin){statusPin=pin;} // sets Status Pin
void setApPassword(char *pwd){network.apPassword=pwd;} // sets Access Point Password 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 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)
}; };
/////////////////////////////// ///////////////////////////////

View File

@ -1,4 +1,6 @@
#pragma once
#include <WiFi.h> #include <WiFi.h>
#include <unordered_set> #include <unordered_set>
#include "Settings.h" #include "Settings.h"

View File

@ -1,4 +1,6 @@
#pragma once
#include <mbedtls/sha512.h> #include <mbedtls/sha512.h>
#include <mbedtls/bignum.h> #include <mbedtls/bignum.h>

View File

@ -24,6 +24,8 @@
#define DEFAULT_AP_TIMEOUT 120 // change with homeSpan.setApTimeout(nSeconds) #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 // // Maximum number of simultaenous IP connections //
// HAP requires at least 8 // // HAP requires at least 8 //
@ -37,24 +39,11 @@ const int MAX_SSID=32;
const int MAX_PWD=64; const int MAX_PWD=64;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// Verbosity -- controls message output // // Message Log Level Control Macros //
// 0=Minimal, 1=Informative, 2=All // // 0=Minimal, 1=Informative, 2=All //
#define VERBOSITY 2 #define LOG1(x) if(homeSpan.logLevel>0)Serial.print(x)
#define LOG2(x) if(homeSpan.logLevel>1)Serial.print(x)
//-------------------------------------------------//
#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
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// Types of Accessory Categories // // Types of Accessory Categories //

View File

@ -1,5 +1,7 @@
#include "Settings.h" #pragma once
#include "HomeSpan.h"
template <class tagType, int maxTags> template <class tagType, int maxTags>
class TLV { class TLV {
@ -166,7 +168,7 @@ uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len){
template<class tagType, int maxTags> template<class tagType, int maxTags>
void TLV<tagType, maxTags>::print(){ void TLV<tagType, maxTags>::print(){
if(VERBOSITY<2) if(homeSpan.logLevel<2)
return; return;
char buf[3]; char buf[3];

View File

@ -1,4 +1,6 @@
#pragma once
#include <Arduino.h> #include <Arduino.h>
#include <driver/timer.h> #include <driver/timer.h>

View File

@ -7,6 +7,8 @@
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.setLogLevel(2);
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark"); homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");