FastLED 3.9.12
Loading...
Searching...
No Matches
dbg.h
1#pragma once
2
3#include "fl/strstream.h"
4
5namespace fl {
6// ".build/src/fl/dbg.h" -> "src/fl/dbg.h"
7// "blah/blah/blah.h" -> "blah.h"
8inline const char* fastled_file_offset(const char* file) {
9 const char* p = file;
10 const char* last_slash = nullptr;
11
12 while (*p) {
13 if (p[0] == 's' && p[1] == 'r' && p[2] == 'c' && p[3] == '/') {
14 return p; // Skip past "src/"
15 }
16 if (*p == '/') { // fallback to using last slash
17 last_slash = p;
18 }
19 p++;
20 }
21 // If "src/" not found but we found at least one slash, return after the last slash
22 if (last_slash) {
23 return last_slash + 1;
24 }
25 return file; // If no slashes found at all, return original path
26}
27} // namespace fl
28
29#ifdef __EMSCRIPTEN__
30#define FASTLED_DBG_USE_PRINTF 1
31#endif
32
33#ifndef FASTLED_DBG_USE_PRINTF
34#if defined(DEBUG) && (defined(__IMXRT1062__) || defined(ESP32))
35#define FASTLED_DBG_USE_PRINTF 1
36#else
37#define FASTLED_DBG_USE_PRINTF 0
38#endif
39#endif
40
41
42#if FASTLED_DBG_USE_PRINTF
43#define FASTLED_HAS_DBG 1
44#include <stdio.h> // ok include
45namespace fl {
46
47} // namespace fl
48#define _FASTLED_DGB(X) \
49 printf("%s", \
50 (fl::StrStream() << \
51 (fl::fastled_file_offset(__FILE__)) << "(" << __LINE__ << "): " << X << "\n") \
52 .c_str())
53
54#define FASTLED_DBG(X) _FASTLED_DGB(X)
55#endif
56
57
58#ifndef FASTLED_HAS_DBG
59// FASTLED_DBG is a macro that can be defined to enable debug printing.
60#define FASTLED_DBG(X) (fl::FakeStrStream() << X)
61#endif
62
63#ifndef FASTLED_DBG_IF
64#ifdef FASTLED_HAS_DBG
65#define FASTLED_DBG_IF(COND, MSG) if (COND) FASTLED_DBG(MSG)
66#else
67#define FASTLED_DBG_IF(COND, MSG) while(false && (COND)) { FASTLED_DBG(MSG); }
68#endif // FASTLED_HAS_DBG
69#endif // FASTLED_DBG_IF
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16