Converted LOG1() and LOG2() to variadic macros!
If LOG1() or LOG2() is only provided with a SINGLE argument, then Serial.print() is called. This allows you to continue using LOG1() and LOG2() to directly print any variable or object that is handled by Serial.print(), such as an int, double, or even an IPAddress. If LOG1() or LOG2() is provided with multiple arguments, the first is considered the format and Serial.printf(format...) is called. This allows you to use printf-like functionality within LOG1() and LOG2().
This commit is contained in:
parent
682e65129d
commit
1be40ad6fc
|
|
@ -1,7 +1,7 @@
|
|||
/*********************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Gregg E. Berman
|
||||
* Copyright (c) 2022 Gregg E. Berman
|
||||
*
|
||||
* https://github.com/HomeSpan/HomeSpan
|
||||
*
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ struct DEV_LED : Service::LightBulb { // First we create a derived
|
|||
|
||||
digitalWrite(ledPin,power->getNewVal()); // use a standard Arduino function to turn on/off ledPin based on the return of a call to power->getNewVal() (see below for more info)
|
||||
WEBLOG("LED on Pin %d: %s",ledPin,power->getNewVal()?"ON":"OFF");
|
||||
LOG1("LOG1: LED on Pin %d: %s",ledPin,power->getNewVal()?"ON":"OFF");
|
||||
LOG2("LOG2: LED on Pin %d: %s",ledPin,power->getNewVal()?"ON":"OFF");
|
||||
|
||||
return(true); // return true to indicate the update was successful (otherwise create code to return false if some reason you could not turn on the LED)
|
||||
|
||||
|
|
|
|||
|
|
@ -98,8 +98,8 @@
|
|||
// Message Log Level Control Macros //
|
||||
// 0=Minimal, 1=Informative, 2=All //
|
||||
|
||||
#define LOG1(x) if(homeSpan.logLevel>0)Serial.print(x)
|
||||
#define LOG2(x) if(homeSpan.logLevel>1)Serial.print(x)
|
||||
#define LOG1(format,...) if(homeSpan.logLevel>0)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__)
|
||||
#define LOG2(format,...) if(homeSpan.logLevel>1)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
#define WEBLOG(format,...) homeSpan.webLog.addLog(format __VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue