Skip to content

Commit d6c0edc

Browse files
committed
Refactoring assert support
1 parent 566ad3d commit d6c0edc

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

examples/BMP085/BMP085.ino

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "TWI.h"
22
#include "Driver/BMP085.h"
3+
#include "assert.h"
34

45
// Configure: TWI bus manager (software or hardware)
56
// #define USE_SOFTWARE_TWI
@@ -23,10 +24,7 @@ void setup()
2324
while (!Serial);
2425

2526
// Start the digital pressure sensor
26-
while (!bmp.begin(BMP085::ULTRA_LOW_POWER)) {
27-
Serial.println(F("bmp.begin:error"));
28-
delay(5000);
29-
}
27+
ASSERT(bmp.begin(BMP085::ULTRA_LOW_POWER));
3028
}
3129

3230
void loop()
@@ -37,15 +35,11 @@ void loop()
3735
Serial.print(':');
3836

3937
// Sample, calculate and print temperature and pressure
40-
if (bmp.sample()) {
41-
Serial.print(bmp.temperature() / 10.0);
42-
Serial.print(F(" C, "));
43-
Serial.print(bmp.pressure() / 100.0);
44-
Serial.println(F(" hPa"));
45-
}
46-
else {
47-
Serial.println(F("bmp.sample:error"));
48-
}
38+
ASSERT(bmp.sample());
39+
Serial.print(bmp.temperature() / 10.0);
40+
Serial.print(F(" C, "));
41+
Serial.print(bmp.pressure() / 100.0);
42+
Serial.println(F(" hPa"));
4943

5044
// Periodic execute every two seconds
5145
delay(2000 - (millis() - start));

examples/DS2482/DS2482.ino

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "GPIO.h"
22
#include "TWI.h"
33
#include "Driver/DS2482.h"
4+
#include "assert.h"
45

56
// Configure: Software or Hardware TWI
67
// #define USE_SOFTWARE_TWI
@@ -55,26 +56,6 @@ uint8_t one_wire_crc_update(uint8_t crc, uint8_t data)
5556
return (crc);
5657
}
5758

58-
// Check assertion to be true, otherwise print line and expression
59-
#define ASSERT(expr) \
60-
do { \
61-
if (!(expr)) { \
62-
Serial.print(__LINE__); \
63-
Serial.println(F(":assert:" #expr)); \
64-
Serial.flush(); \
65-
exit(0); \
66-
} \
67-
} while (0)
68-
69-
70-
// Print and evaluate expression
71-
#define TRACE(expr) \
72-
do { \
73-
Serial.print(#expr "="); \
74-
Serial.println(expr); \
75-
} while (0)
76-
77-
7859
void setup()
7960
{
8061
Serial.begin(57600);

0 commit comments

Comments
 (0)