8#ifndef FLUSH_ON_EVERY_DEBUG_STATEMENT
9#if !(defined(ESP32) || defined(ESP8266))
17#define FLUSH_ON_EVERY_DEBUG_STATEMENT 0
21#define FLUSH_ON_EVERY_DEBUG_STATEMENT 0
28#elif defined(ARDUINO_ARCH_MBED)
30#include <rtos/Mutex.h>
49#if FLUSH_ON_EVERY_DEBUG_STATEMENT
50#define DEBUG_ENDL endl
52#define DEBUG_ENDL "\r\n"
55#if (defined(ESP32) || defined(ESP8266)) && FLUSH_ON_EVERY_DEBUG_STATEMENT
56#error "ESP32 and ESP8266 don't support flushing `Print` objects"
61#define DEBUG_STR_HELPER(x) #x
62#define DEBUG_STR(x) DEBUG_STR_HELPER(x)
64#define DEBUG_FUNC_LOCATION \
65 '[' << __PRETTY_FUNCTION__ << F(" @ line " DEBUG_STR(__LINE__) "]:\t")
66#define DEBUG_LOCATION "[" __FILE__ ":" DEBUG_STR(__LINE__) "]:\t"
71#define DEBUG_LOCK_MUTEX std::lock_guard<std::mutex> lock(AH::debugmutex);
73extern std::mutex debugmutex;
75#elif defined(ARDUINO_ARCH_MBED)
76#define DEBUG_LOCK_MUTEX std::lock_guard<rtos::Mutex> lock(AH::debugmutex);
78extern rtos::Mutex debugmutex;
81#define DEBUG_LOCK_MUTEX
89#define NAMEDVALUE(x) F(DEBUG_STR(x) " = ") << x
98 DEBUG_OUT << x << DEBUG_ENDL; \
108 DEBUG_OUT << F(DEBUG_LOCATION) << x << DEBUG_ENDL; \
118 DEBUG_OUT << DEBUG_FUNC_LOCATION << x << DEBUG_ENDL; \
127#define DEBUGTIME(x) \
130 unsigned long t = millis(); \
131 unsigned long h = t / (60UL * 60 * 1000); \
132 unsigned long m = (t / (60UL * 1000)) % 60; \
133 unsigned long s = (t / (1000UL)) % 60; \
134 unsigned long ms = t % 1000; \
135 const char *ms_zeros = ms > 99 ? "" : (ms > 9 ? "0" : "00"); \
136 DEBUG_OUT << '[' << h << ':' << m << ':' << s << '.' << ms_zeros << ms \
137 << "]:\t" << x << DEBUG_ENDL; \
145extern const decltype(std::chrono::high_resolution_clock::now()) start_time;
148#define DEBUGTIME(x) \
150 USING_AH_NAMESPACE; \
151 using namespace std::chrono; \
152 auto now = high_resolution_clock::now(); \
154 duration_cast<milliseconds>(now - start_time).count(); \
155 unsigned long h = t / (60UL * 60 * 1000); \
156 unsigned long m = (t / (60UL * 1000)) % 60; \
157 unsigned long s = (t / (1000UL)) % 60; \
158 unsigned long ms = t % 1000; \
159 const char *ms_zeros = ms > 99 ? "" : (ms > 9 ? "0" : "00"); \
160 DEBUG_OUT << '[' << h << ':' << m << ':' << s << '.' << ms_zeros << ms \
161 << "]:\t" << x << DEBUG_ENDL; \
175#define DEBUGVAL(...) DEBUGVALN(COUNT(__VA_ARGS__))(__VA_ARGS__)
188#define DEBUGTIME(x) \
191#define DEBUGVAL(...) \
#define BEGIN_AH_NAMESPACE