Skip to content

Commit

Permalink
debugLevel -> setDebug, introduced the settable debug device
Browse files Browse the repository at this point in the history
  • Loading branch information
ropg committed Sep 12, 2018
1 parent 10520bb commit 13c3654
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Saturday, 25-Aug-18 14:32:53.303 UTC
```
[...]
setInterval(60);
setDebugLevel(INFO);
setDebug(INFO);
}
void loop() {
Expand Down Expand Up @@ -233,7 +233,7 @@ in File -> Examples you will now see an ezTime heading down under "Examples from
* [<em>urlEncode</em>](#urlencode)
* [<em>zeropad</em>](#zeropad)
* [Errors and debug information](#errors-and-debug-information)
* [<em>debugLevel</em>](#debuglevel)
* [<em>setDebug</em>](#setdebug)
* [<em>error</em>](#error)
* [<em>errorString</em>](#errorstring)
* [Compatibility with Arduino Time library](#compatibility-with-arduino-time-library)
Expand Down Expand Up @@ -750,20 +750,25 @@ Pads `number` with zeroes to the left until the resulting string is `length` pla

## Errors and debug information

### *debugLevel*
### *setDebug*

`void debugLevel(ezDebugLevel_t level);`
`void setDebug(ezDebugLevel_t level)`<br>`void setDebug(ezDebugLevel_t level, Print &device)`

Sets the level of detail at which ezTime outputs messages on the serial port. Can be set to one of:
`level` sets the level of detail at which ezTime outputs messages on the serial port. Can be set to one of:

| debugLevel | effect |
| level | effect |
|---|---|
| `NONE` | ezTime does not output anything on the serial port |
| `ERROR` | ezTime will show when errors occur. Note that these may be transient errors that ezTime recovers from, such as NTP timeouts. |
| `INFO` | Essentially shows you what ezTime is doing in the background. Includes messages about NTP updates, initialising timezones, etc etc. |
| `DEBUG` | Detailed debugging information unlikely to be of much use unless you are trying to get to the bottom of certain internal behaviour of ezTime. |

*Note:* you can specify which level of debug information would be compiled into the library. This is especially significant for AVR Arduino users that need to limit the flash and RAM footprint of ezTtime. See the "Smaller footprint, AVR Arduinos" chapter further down.
`device` is optional and can specify a device to receive the debug messages. This defaults to the Hardwareserial object names `Serial` but can be any device that has inherited from the `Print` class. Don't worry if you don't understand that: it means you can specify not only serial ports, but also a handle to a file you have opened on the SD card as well as a lot of LCD screen devices. For instance, on my M5Stack device I can (after `#include <M5Stack.h>` and `m5.begin()`) do: `setDebug(INFO, m5.lcd)`

You cannot send debug information to multiple devices.

![](images/M5Stack-debug.jpg)

&nbsp;

Expand Down Expand Up @@ -902,7 +907,7 @@ ezTime 0.7.2 worked, eventually. But I didn't like this one. Getting online is d
```

* Test sketch complained about WiFi firmware / driver mismatch. Couldn't get the firmware update tool to work, but WiFi worked anyway.
* The WiFi object does not have the `isConnected` method so I wrote some detection for ezTime to skip the NO_NETWORK checks. This means that if you have debugLevel at ERROR or higher, waitForSync will throw some NTP TIMEOUT errors (and then continue just fine after wifi is online).
* The WiFi object does not have the `isConnected` method so I wrote some detection for ezTime to skip the NO_NETWORK checks. This means that if you have debug level at ERROR or higher, waitForSync will throw some NTP TIMEOUT errors (and then continue just fine after wifi is online).
* It doesn't have `EEPROM.h` or `Preferences.h` but some proprietary `FlashStorage.h`. So no cache for the moment. (Turn off both cache defines at the beginning of `ezTime.h`. I'll write it if the third person wants it.

&nbsp;
Expand Down
2 changes: 1 addition & 1 deletion examples/Timezones/Timezones.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void setup() {
WiFi.begin("your-ssid", "your-password");

// Uncomment the line below to see what it does behind the scenes
// ezTime.debugLevel(INFO);
// setDebug(INFO);

waitForSync();

Expand Down
2 changes: 1 addition & 1 deletion examples/milliseconds/milliseconds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void setup() {
Serial.println("And ezTime is not making those milliseconds up either.");
Serial.println();
Serial.println(" ... Stick around as we do an NTP request every minute.");
debugLevel(INFO);
setDebug(INFO);

}

Expand Down
Binary file added images/M5Stack-debug.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ezTime KEYWORD2
error KEYWORD2
errorString KEYWORD2
debugLevel KEYWORD2
setDebug KEYWORD2
timeStatus KEYWORD2
now KEYWORD2
events KEYWORD2
Expand Down
32 changes: 19 additions & 13 deletions src/ezTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@
#define debug(args...) ""
#define debugln(args...) ""
#elif defined(EZTIME_MAX_DEBUGLEVEL_ERROR)
#define err(args...) if (_debug_level >= ERROR) Serial.print(args)
#define errln(args...) if (_debug_level >= ERROR) Serial.println(args)
#define err(args...) if (_debug_level >= ERROR) _debug_device->print(args)
#define errln(args...) if (_debug_level >= ERROR) _debug_device->println(args)
#define info(args...) ""
#define infoln(args...) ""
#define debug(args...) ""
#define debugln(args...) ""
#elif defined(EZTIME_MAX_DEBUGLEVEL_INFO)
#define err(args...) if (_debug_level >= ERROR) Serial.print(args)
#define errln(args...) if (_debug_level >= ERROR) Serial.println(args)
#define info(args...) if (_debug_level >= INFO) Serial.print(args)
#define infoln(args...) if (_debug_level >= INFO) Serial.println(args)
#define err(args...) if (_debug_level >= ERROR) _debug_device->print(args)
#define errln(args...) if (_debug_level >= ERROR) _debug_device->println(args)
#define info(args...) if (_debug_level >= INFO) _debug_device->print(args)
#define infoln(args...) if (_debug_level >= INFO) _debug_device->println(args)
#define debug(args...) ""
#define debugln(args...) ""
#else // nothing specified compiles everything in.
#define err(args...) if (_debug_level >= ERROR) Serial.print(args)
#define errln(args...) if (_debug_level >= ERROR) Serial.println(args)
#define info(args...) if (_debug_level >= INFO) Serial.print(args)
#define infoln(args...) if (_debug_level >= INFO) Serial.println(args)
#define debug(args...) if (_debug_level >= DEBUG) Serial.print(args)
#define debugln(args...) if (_debug_level >= DEBUG) Serial.println(args)
#define err(args...) if (_debug_level >= ERROR) _debug_device->print(args)
#define errln(args...) if (_debug_level >= ERROR) _debug_device->println(args)
#define info(args...) if (_debug_level >= INFO) _debug_device->print(args)
#define infoln(args...) if (_debug_level >= INFO) _debug_device->println(args)
#define debug(args...) if (_debug_level >= DEBUG) _debug_device->print(args)
#define debugln(args...) if (_debug_level >= DEBUG) _debug_device->println(args)
#endif


Expand All @@ -63,6 +63,7 @@ namespace {

ezError_t _last_error = NO_ERROR;
ezDebugLevel_t _debug_level = NONE;
Print *_debug_device = (Print *)&Serial;
ezEvent_t _events[MAX_EVENTS];
time_t _last_sync_time = 0;
time_t _last_read_t = 0;
Expand Down Expand Up @@ -134,8 +135,13 @@ ezError_t error(bool reset /* = false */) {
return tmp;
}

void debugLevel(ezDebugLevel_t level) {
void setDebug(ezDebugLevel_t level) {
setDebug(level, *_debug_device);
}

void setDebug(ezDebugLevel_t level, Print &device) {
_debug_level = level;
_debug_device = &device;
info(F("\r\nezTime debug level set to "));
infoln(debugLevelString(level));
}
Expand Down
5 changes: 3 additions & 2 deletions src/ezTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// #define EZTIME_ETHERNET

// Uncomment one of the below to only put only messages up to a certain level in the compiled code
// (You still need to turn them on with debugLevel(someLevel) to see them)
// (You still need to turn them on with setDebug(someLevel) to see them)
// #define EZTIME_MAX_DEBUGLEVEL_NONE
// #define EZTIME_MAX_DEBUGLEVEL_ERROR
// #define EZTIME_MAX_DEBUGLEVEL_INFO
Expand Down Expand Up @@ -167,7 +167,6 @@ typedef struct {
void breakTime(time_t time, tmElements_t &tm);
time_t compileTime(String compile_date = __DATE__, String compile_time = __TIME__);
String dayString(uint8_t day);
void debugLevel(ezDebugLevel_t level);
void deleteEvent(uint8_t event_handle);
void deleteEvent(void (*function)());
ezError_t error(bool reset = false);
Expand All @@ -179,6 +178,8 @@ time_t makeTime(uint8_t hour, uint8_t minute, uint8_t second, uint8_t day, uint8
bool minuteChanged();
String monthString(uint8_t month);
bool secondChanged();
void setDebug(ezDebugLevel_t level);
void setDebug(ezDebugLevel_t level, Print &device);
timeStatus_t timeStatus();
String urlEncode(String str);
String zeropad(uint32_t number, uint8_t length);
Expand Down

0 comments on commit 13c3654

Please sign in to comment.