8#include <AH/PrintStream/PrintStream.hpp>
11#ifndef FLUSH_ON_EVERY_DEBUG_STATEMENT
12#if !(defined(ESP32) || defined(ESP8266))
20#define FLUSH_ON_EVERY_DEBUG_STATEMENT 0
24#define FLUSH_ON_EVERY_DEBUG_STATEMENT 0
31#elif defined(ARDUINO_ARCH_MBED)
33#include <rtos/Mutex.h>
52#if FLUSH_ON_EVERY_DEBUG_STATEMENT
53#define DEBUG_ENDL endl
55#define DEBUG_ENDL "\r\n"
58#if (defined(ESP32) || defined(ESP8266)) && FLUSH_ON_EVERY_DEBUG_STATEMENT
59#error "ESP32 and ESP8266 don't support flushing `Print` objects"
64#define DEBUG_STR_HELPER(x) #x
65#define DEBUG_STR(x) DEBUG_STR_HELPER(x)
67#define DEBUG_FUNC_LOCATION \
68 '[' << __PRETTY_FUNCTION__ << F(" @ line " DEBUG_STR(__LINE__) "]:\t")
69#define DEBUG_LOCATION "[" __FILE__ ":" DEBUG_STR(__LINE__) "]:\t"
74#define DEBUG_LOCK_MUTEX std::lock_guard<std::mutex> lock(AH::debugmutex);
76extern std::mutex debugmutex;
78#elif defined(ARDUINO_ARCH_MBED)
79#define DEBUG_LOCK_MUTEX std::lock_guard<rtos::Mutex> lock(AH::debugmutex);
81extern rtos::Mutex debugmutex;
84#define DEBUG_LOCK_MUTEX
92#define NAMEDVALUE(x) F(DEBUG_STR(x) " = ") << x
101 DEBUG_OUT << x << DEBUG_ENDL; \
111 DEBUG_OUT << F(DEBUG_LOCATION) << x << DEBUG_ENDL; \
121 DEBUG_OUT << DEBUG_FUNC_LOCATION << x << DEBUG_ENDL; \
130#define DEBUGTIME(x) \
133 unsigned long t = millis(); \
134 unsigned long h = t / (60UL * 60 * 1000); \
135 unsigned long m = (t / (60UL * 1000)) % 60; \
136 unsigned long s = (t / (1000UL)) % 60; \
137 unsigned long ms = t % 1000; \
138 const char *ms_zeros = ms > 99 ? "" : (ms > 9 ? "0" : "00"); \
139 DEBUG_OUT << '[' << h << ':' << m << ':' << s << '.' << ms_zeros << ms \
140 << "]:\t" << x << DEBUG_ENDL; \
148extern const decltype(std::chrono::high_resolution_clock::now()) start_time;
151#define DEBUGTIME(x) \
153 USING_AH_NAMESPACE; \
154 using namespace std::chrono; \
155 auto now = high_resolution_clock::now(); \
157 duration_cast<milliseconds>(now - start_time).count(); \
158 unsigned long h = t / (60UL * 60 * 1000); \
159 unsigned long m = (t / (60UL * 1000)) % 60; \
160 unsigned long s = (t / (1000UL)) % 60; \
161 unsigned long ms = t % 1000; \
162 const char *ms_zeros = ms > 99 ? "" : (ms > 9 ? "0" : "00"); \
163 DEBUG_OUT << '[' << h << ':' << m << ':' << s << '.' << ms_zeros << ms \
164 << "]:\t" << x << DEBUG_ENDL; \
178#define DEBUGVAL(...) DEBUGVALN(COUNT(__VA_ARGS__))(__VA_ARGS__)
191#define DEBUGTIME(x) \
194#define DEBUGVAL(...) \
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()