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:
parent
381b25860a
commit
dee954d5bd
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// HAP TLV Types (HAP Table 5-6)
|
||||
|
||||
typedef enum {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -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 <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("\nDevice Control: Pin ");
|
||||
Serial.print(controlPin);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <unordered_set>
|
||||
#include "Settings.h"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <mbedtls/sha512.h>
|
||||
#include <mbedtls/bignum.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 //
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
#include "Settings.h"
|
||||
#pragma once
|
||||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
template <class tagType, int maxTags>
|
||||
class TLV {
|
||||
|
|
@ -166,7 +168,7 @@ uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len){
|
|||
template<class tagType, int maxTags>
|
||||
void TLV<tagType, maxTags>::print(){
|
||||
|
||||
if(VERBOSITY<2)
|
||||
if(homeSpan.logLevel<2)
|
||||
return;
|
||||
|
||||
char buf[3];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <driver/timer.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setLogLevel(2);
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue