FastLED 3.9.15
Loading...
Searching...
No Matches
dbg.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/strstream.h"
4#include "fl/sketch_macros.h"
5#include "fl/int.h"
6#include "fl/stdint.h"
7
8// Forward declaration to avoid pulling in fl/io.h and causing fl/io.cpp to be compiled
9// This prevents ~5KB memory bloat for simple applications
10#ifndef FL_DBG_PRINTLN_DECLARED
11#define FL_DBG_PRINTLN_DECLARED
12namespace fl {
13 void println(const char* str);
14}
15#endif
16
17namespace fl {
18// ".build/src/fl/dbg.h" -> "src/fl/dbg.h"
19// "blah/blah/blah.h" -> "blah.h"
20inline const char *fastled_file_offset(const char *file) {
21 const char *p = file;
22 const char *last_slash = nullptr;
23
24 while (*p) {
25 if (p[0] == 's' && p[1] == 'r' && p[2] == 'c' && p[3] == '/') {
26 return p; // Skip past "src/"
27 }
28 if (*p == '/') { // fallback to using last slash
29 last_slash = p;
30 }
31 p++;
32 }
33 // If "src/" not found but we found at least one slash, return after the
34 // last slash
35 if (last_slash) {
36 return last_slash + 1;
37 }
38 return file; // If no slashes found at all, return original path
39}
40} // namespace fl
41
42#if __EMSCRIPTEN__ || !defined(RELEASE) || defined(FASTLED_TESTING)
43#define FASTLED_FORCE_DBG 1
44#endif
45
46// Debug printing: Enable only when explicitly requested to avoid ~5KB memory bloat
47#ifndef FASTLED_FORCE_DBG
48// By default, debug printing is disabled to prevent memory bloat in simple applications
49#define FASTLED_HAS_DBG 0
50#define _FASTLED_DGB(X) do { if (false) { fl::println(""); } } while(0) // No-op that handles << operator
51#else
52// Explicit debug mode enabled - uses fl::println()
53#define FASTLED_HAS_DBG 1
54#define _FASTLED_DGB(X) \
55 fl::println( \
56 (fl::StrStream() << (fl::fastled_file_offset(__FILE__)) \
57 << "(" << int(__LINE__) << "): " << X) \
58 .c_str())
59#endif
60
61#define FASTLED_DBG(X) _FASTLED_DGB(X)
62
63#ifndef FASTLED_DBG_IF
64#define FASTLED_DBG_IF(COND, MSG) \
65 if (COND) \
66 FASTLED_DBG(MSG)
67#endif // FASTLED_DBG_IF
void println(const char *str)
Definition io.cpp:83
const char * fastled_file_offset(const char *file)
Definition dbg.h:20
IMPORTANT!
Definition crgb.h:20