|
| 1 | +/** |
| 2 | + * @brief Auxiliary functions for debugging over Serial |
| 3 | + * |
| 4 | + * Format used on debug functions is the same as `printf()`. Check source code for usage examples |
| 5 | + * Debug calls will be enabled or disabled automatically before compiling according defined `DEBUG_LEVEL`. |
| 6 | + * |
| 7 | + * If `DEBUG_ESP_PORT` is not defined library will give no debug output at all |
| 8 | + * |
| 9 | + * @file EnigmaIOTdebug.h |
| 10 | + * @version 0.9.8 |
| 11 | + * @date 15/07/2021 |
| 12 | + * @author German Martin |
| 13 | + */ |
| 14 | + |
| 15 | +#ifndef _DEBUG_h |
| 16 | +#define _DEBUG_h |
| 17 | + |
| 18 | +#include <Arduino.h> |
| 19 | +#ifdef ESP32 |
| 20 | +#include <esp_log.h> |
| 21 | +#endif |
| 22 | + |
| 23 | +#define DEBUG_ESP_PORT Serial |
| 24 | + |
| 25 | +#define NO_DEBUG 0 ///< @brief Debug level that will give no debug output |
| 26 | +#define ERROR 1 ///< @brief Debug level that will give error messages |
| 27 | +#define WARN 2 ///< @brief Debug level that will give error and warning messages |
| 28 | +#define INFO 3 ///< @brief Debug level that will give error, warning and info messages |
| 29 | +#define DBG 4 ///< @brief Debug level that will give error, warning,info AND dbg messages |
| 30 | +#define VERBOSE 5 ///< @brief Debug level that will give all defined messages |
| 31 | + |
| 32 | +#ifdef ESP8266 |
| 33 | +const char* extractFileName (const char* path); |
| 34 | +#define DEBUG_LINE_PREFIX() DEBUG_ESP_PORT.printf_P (PSTR("[%lu][H:%5lu][%s:%d] %s() | "),millis(),(unsigned long)ESP.getFreeHeap(),extractFileName(__FILE__),__LINE__,__FUNCTION__) |
| 35 | +#endif |
| 36 | + |
| 37 | +#ifdef DEBUG_ESP_PORT |
| 38 | + |
| 39 | +#ifdef ESP8266 |
| 40 | +#if DEBUG_LEVEL >= VERBOSE |
| 41 | +#define DEBUG_VERBOSE(text,...) DEBUG_ESP_PORT.print("V ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println() |
| 42 | +#else |
| 43 | +#define DEBUG_VERBOSE(...) |
| 44 | +#endif |
| 45 | + |
| 46 | +#if DEBUG_LEVEL >= DBG |
| 47 | +#define DEBUG_DBG(text,...) DEBUG_ESP_PORT.print("D ");DEBUG_LINE_PREFIX(); DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println() |
| 48 | +#else |
| 49 | +#define DEBUG_DBG(...) |
| 50 | +#endif |
| 51 | + |
| 52 | +#if DEBUG_LEVEL >= INFO |
| 53 | +#define DEBUG_INFO(text,...) DEBUG_ESP_PORT.print("I ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println() |
| 54 | +#else |
| 55 | +#define DEBUG_INFO(...) |
| 56 | +#endif |
| 57 | + |
| 58 | +#if DEBUG_LEVEL >= WARN |
| 59 | +#define DEBUG_WARN(text,...) DEBUG_ESP_PORT.print("W ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println() |
| 60 | +#else |
| 61 | +#define DEBUG_WARN(...) |
| 62 | +#endif |
| 63 | + |
| 64 | +#if DEBUG_LEVEL >= ERROR |
| 65 | +#define DEBUG_ERROR(text,...) DEBUG_ESP_PORT.print("E ");DEBUG_LINE_PREFIX();DEBUG_ESP_PORT.printf_P(PSTR(text),##__VA_ARGS__);DEBUG_ESP_PORT.println() |
| 66 | +#else |
| 67 | +#define DEBUG_ERROR(...) |
| 68 | +#endif |
| 69 | +#elif defined ESP32 |
| 70 | +#define DEFAULT_LOG_TAG "QuickDebug" |
| 71 | +#define DEBUG_VERBOSE(format,...) ESP_LOGV (DEFAULT_LOG_TAG,"%d Heap: %6d. " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__) |
| 72 | +#define DEBUG_DBG(format,...) ESP_LOGD (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__) |
| 73 | +#define DEBUG_INFO(format,...) ESP_LOGI (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__) |
| 74 | +#define DEBUG_WARN(format,...) ESP_LOGW (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__) |
| 75 | +#define DEBUG_ERROR(format,...) ESP_LOGE (DEFAULT_LOG_TAG,"%d Heap: %6d " format, millis(), ESP.getFreeHeap(), ##__VA_ARGS__) |
| 76 | +#endif |
| 77 | +#else |
| 78 | +#define DEBUG_VERBOSE(...) |
| 79 | +#define DEBUG_DBG(...) |
| 80 | +#define DEBUG_INFO(...) |
| 81 | +#define DEBUG_WARN(...) |
| 82 | +#define DEBUG_ERROR(...) |
| 83 | +#endif |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +#endif |
| 88 | + |
0 commit comments