Bluetooth Connected TOF Sensor

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Committer:
hux
Date:
Wed Feb 01 22:35:28 2017 +0000
Revision:
29:cf61a5826426
Small modification to reduce display flickering

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 29:cf61a5826426 1 // trace.cpp - trace a message depending on verbose level
hux 29:cf61a5826426 2 //
hux 29:cf61a5826426 3
hux 29:cf61a5826426 4 #include <stdio.h>
hux 29:cf61a5826426 5 #include "bricks/trace.h"
hux 29:cf61a5826426 6
hux 29:cf61a5826426 7 static Serial pc(USBTX, USBRX); // serial port to PC terminal
hux 29:cf61a5826426 8
hux 29:cf61a5826426 9 //==============================================================================
hux 29:cf61a5826426 10 // Managing the Verbose Lewvel
hux 29:cf61a5826426 11 //==============================================================================
hux 29:cf61a5826426 12
hux 29:cf61a5826426 13 static int threshold = 0; // verbose threshold, no verbose messages
hux 29:cf61a5826426 14
hux 29:cf61a5826426 15 void verbose(O&o, int level) // setup verbose level
hux 29:cf61a5826426 16 {
hux 29:cf61a5826426 17 threshold = level; // update verbose threshold
hux 29:cf61a5826426 18 }
hux 29:cf61a5826426 19
hux 29:cf61a5826426 20 //==============================================================================
hux 29:cf61a5826426 21 // Printing Trace Messages
hux 29:cf61a5826426 22 //==============================================================================
hux 29:cf61a5826426 23
hux 29:cf61a5826426 24 void trace(O&o, int level, const char *msg) // trace a message
hux 29:cf61a5826426 25 {
hux 29:cf61a5826426 26 if (level <= threshold) // update verbose threshold
hux 29:cf61a5826426 27 { char buf[2] = " "; // must be terminated
hux 29:cf61a5826426 28
hux 29:cf61a5826426 29 for (; *msg; msg++)
hux 29:cf61a5826426 30 { buf[0] = *msg;
hux 29:cf61a5826426 31 printf(buf);
hux 29:cf61a5826426 32 if (*msg == '\n')
hux 29:cf61a5826426 33 { buf[0] = '\r'; // auto adding carriage return
hux 29:cf61a5826426 34 printf(buf);
hux 29:cf61a5826426 35 }
hux 29:cf61a5826426 36 }
hux 29:cf61a5826426 37 }
hux 29:cf61a5826426 38 }
hux 29:cf61a5826426 39
hux 29:cf61a5826426 40 void trace(O&o, int level, const char*format, int value)
hux 29:cf61a5826426 41 {
hux 29:cf61a5826426 42 char buf[80];
hux 29:cf61a5826426 43 if (strlen(format) > 70)
hux 29:cf61a5826426 44 trace(o,level," *** buffer overflow *** ");
hux 29:cf61a5826426 45 else
hux 29:cf61a5826426 46 { sprintf(buf,format,value);
hux 29:cf61a5826426 47 trace(o,level,buf);
hux 29:cf61a5826426 48 }
hux 29:cf61a5826426 49 }
hux 29:cf61a5826426 50
hux 29:cf61a5826426 51 void traceln(O&o, int level, const char*msg) // trace with CR & LF
hux 29:cf61a5826426 52 {
hux 29:cf61a5826426 53 trace(o,level,msg); trace(o,level,"\r\n");
hux 29:cf61a5826426 54 }