![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A blue button is always a nice toy ...
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Diff: bricks/trace.cpp
- Revision:
- 23:677689000369
- Child:
- 27:32267cee7cb8
diff -r d467526abc4a -r 677689000369 bricks/trace.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bricks/trace.cpp Fri Jan 06 15:28:18 2017 +0000 @@ -0,0 +1,32 @@ +// trace.cpp - trace a message depending on verbose level +// + +#include "bricks/trace.h" + + Serial pc(USBTX, USBRX); // serial port to PC terminal + + static int threshold = 0; // verbose threshold, no verbose messages + + void verbose(int level) // setup verbose level + { + threshold = level; // update verbose threshold + } + + + void trace(int level, const char *msg) // trace a message + { + if (level <= threshold) // update verbose threshold + { char buf[2] = " "; // must be terminated + + for (; *msg; msg++) + { buf[0] = *msg; + pc.printf(buf); + if (*msg == '\n') + { buf[0] = '\r'; // auto adding carriage return + pc.printf(buf); + } + } + } + } + + \ No newline at end of file