Skip to content

Commit b97c94a

Browse files
committed
Add ASSERT() macro that provide useful error messages on serial port in DEBUG mode
1 parent 7b28ef6 commit b97c94a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

nexa_decoder/nexa_decoder.ino

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@
4444

4545
#define DEBUG 0
4646

47+
#if DEBUG
48+
#define ASSERT(expr) do { \
49+
if (!(expr)) { \
50+
Serial.print(__FILE__); \
51+
Serial.print(F(":")); \
52+
Serial.print(__LINE__); \
53+
Serial.print(F(" in '")); \
54+
Serial.print(__PRETTY_FUNCTION__); \
55+
Serial.print(F("': Assertion failed: ")); \
56+
Serial.println(#expr); \
57+
Serial.flush(); \
58+
abort(); \
59+
} \
60+
} while (0)
61+
#else
62+
#define ASSERT(expr, msg)
63+
#endif
64+
4765
#define ARRAY_LENGTH(a) ((sizeof (a)) / (sizeof (a)[0]))
4866

4967
// Adjust the following to match where the RF receiver is connected.

0 commit comments

Comments
 (0)