-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacros.h
57 lines (52 loc) · 1.11 KB
/
Macros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef NEXA_NODE_MACROS_H
#define NEXA_NODE_MACROS_H
/*
* DEBUG should be #defined _before_ #including this file.
*/
#ifndef DEBUG
#define DEBUG 0
#endif
/* Arduino-friendly ASSERT() macro
*
* If DEBUG is enabled, the assertion is tested, and in case of failure,
* a helpful error message is written to the serial port and the program
* is aborted.
*
* If DEBUG is disabled, the macro resolves to nothing.
*/
#ifndef ASSERT
#if DEBUG
#define ASSERT(expr) do { \
if (!(expr)) { \
Serial.println(); \
Serial.print(__FILE__); \
Serial.print(F(":")); \
Serial.print(__LINE__); \
Serial.print(F(" in '")); \
Serial.print(__PRETTY_FUNCTION__); \
Serial.print(F("': Assertion failed: ")); \
Serial.println(#expr); \
Serial.flush(); \
abort(); \
} \
} while (0)
#else
#define ASSERT(expr)
#endif
#endif
/*
* Compute the number of elements in an array.
*/
#ifndef ARRAY_LENGTH
#define ARRAY_LENGTH(a) ((sizeof (a)) / (sizeof (a)[0]))
#endif
/*
* The usual MIN/MAX macros
*/
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#endif