LSH-Core
A robust C++ framework for Arduino-based home automation nodes
Loading...
Searching...
No Matches
debug.hpp
Go to the documentation of this file.
1
21#ifndef LSHCORE_UTIL_DEBUG_DEBUG_HPP
22#define LSHCORE_UTIL_DEBUG_DEBUG_HPP
23
27
28#ifdef LSH_DEBUG
29#include <ArduinoJson.h>
30#include "util/debug/memory.hpp"
32#endif // LSH_DEBUG
33
34namespace Debug
35{
39 inline auto FPSTR(const char *const progmemString) -> const __FlashStringHelper *
40 {
41 return reinterpret_cast<const __FlashStringHelper *>(progmemString);
42 }
43
44#ifdef LSH_DEBUG // If in debug mode
45
50#define DP VaPrint::print
51
56#define DPL VaPrint::println
57
62 __attribute__((always_inline)) inline void DSB() { CONFIG_DEBUG_SERIAL->begin(constants::debugConfigs::DEBUG_SERIAL_BAUD); }
63
68#define NDSB()
69
74 template <typename T>
75 __attribute__((always_inline)) constexpr inline void DPJ(const T &json)
76 {
77 serializeJson(json, Serial);
78 DPL();
79 }
80
85 inline void DFM()
86 {
87 DPL(FPSTR(dStr::FREE_MEMORY), FPSTR(dStr::COLON_SPACE), freeMemory());
88 }
89
95#define DP_CONTEXT() DPL(__PRETTY_FUNCTION__)
96
97#else // Not in debug
98
99 namespace details
100 {
101 extern bool serialIsActive;
102 } // namespace details
103
104#define DP(...)
105#define DPL(...)
106#define DSB()
107#define DPJ(x)
108#define DP_CONTEXT()
109#define DFM()
110 // Non-Debug Serial Begin, turn on Serial when not in debug mode
111 void NDSB();
112#endif // LSH_DEBUG
113
114} // namespace Debug
115
116#endif // LSHCORE_UTIL_DEBUG_DEBUG_HPP
Defines build-time configurable parameters for serial communication.
Defines constants, strings, and configuration parameters used for debugging.
auto FPSTR(const char *const progmemString) -> const __FlashStringHelper *
Helper to cast a PROGMEM string to const __FlashStringHelper *, needed to print PROGMEM strings.
Definition debug.hpp:39
Declares functions to check for free memory on AVR devices.
__attribute__((noinline)) inline void deviceReset()
Performs a hardware reset using the watchdog timer.
Definition reset.hpp:36
Internal bridge that imports user-defined macros into the library's scope.
Declares a variadic print utility for streamlined debugging output.