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
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
22 // last slash
23 if (last_slash) {
24 return last_slash + 1;
25 }
26 return file; // If no slashes found at all, return original path
27}
28} // namespace fl
29
30#ifdef __EMSCRIPTEN__
31#define FASTLED_DBG_USE_PRINTF 1
32#endif
33
34#ifndef FASTLED_DBG_USE_PRINTF
35#if defined(DEBUG) && \
36 (defined(__IMXRT1062__) || defined(ESP32) || defined(FASTLED_TESTING))
37#define FASTLED_DBG_USE_PRINTF 1
38#else
39#define FASTLED_DBG_USE_PRINTF 0
40#endif
41#endif
42
43#if FASTLED_DBG_USE_PRINTF
44#define FASTLED_HAS_DBG 1
45#include <stdio.h> // ok include
46namespace fl {} // namespace fl
47#define _FASTLED_DGB(X) \
48 printf("%s", (fl::StrStream() << (fl::fastled_file_offset(__FILE__)) \
49 << "(" << __LINE__ << "): " << X << "\n") \
50 .c_str())
51
52#define FASTLED_DBG(X) _FASTLED_DGB(X)
53#endif
54
55#ifndef FASTLED_HAS_DBG
56// FASTLED_DBG is a macro that can be defined to enable debug printing.
57#define FASTLED_DBG(X) (fl::FakeStrStream() << X)
58#endif
59
60#ifndef FASTLED_DBG_IF
61#ifdef FASTLED_HAS_DBG
62#define FASTLED_DBG_IF(COND, MSG) \
63 if (COND) \
64 FASTLED_DBG(MSG)
65#else
66#define FASTLED_DBG_IF(COND, MSG) \
67 while (false && (COND)) { \
68 FASTLED_DBG(MSG); \
69 }
70#endif // FASTLED_HAS_DBG
71#endif // FASTLED_DBG_IF
const char * fastled_file_offset(const char *file)
Definition dbg.h:8
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]
Definition noise.cpp:30