Hugo Pristauz / Mbed 2 deprecated S14_TOF_Detector

Dependencies:   BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed

Fork of BLE_HeartRate_IDB0XA1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers trace.cpp Source File

trace.cpp

00001 // trace.cpp - trace a message depending on verbose level
00002 //
00003 
00004 #include "bricks/trace.h"
00005 
00006    static Serial pc(USBTX, USBRX);     // serial port to PC terminal
00007 
00008 //==============================================================================
00009 // Managing the Verbose Lewvel
00010 //==============================================================================
00011 
00012    static int threshold = 0;           // verbose threshold, no verbose messages
00013   
00014    void verbose(O&o, int level)        // setup verbose level               
00015    {
00016       threshold = level;               // update verbose threshold
00017    }
00018    
00019 //==============================================================================
00020 // Printing Trace Messages
00021 //==============================================================================
00022 
00023    void trace(O&o, int level, const char *msg) // trace a message
00024    {
00025       if (level <= threshold)          // update verbose threshold
00026       {  char buf[2] = " ";            // must be terminated
00027          
00028          for (; *msg; msg++)
00029          {  buf[0] = *msg;  
00030             pc.printf(buf);
00031             if (*msg == '\n')
00032             {  buf[0] = '\r';          // auto adding carriage return
00033                pc.printf(buf);
00034             }
00035          }
00036       }
00037    }
00038    
00039    void trace(O&o, int level, const char*format, int value)
00040    {
00041        char buf[80];
00042        if (strlen(format) > 70)
00043           trace(o,level," *** buffer overflow *** ");
00044        else
00045        {  sprintf(buf,format,value);
00046           trace(o,level,buf);
00047        }
00048    }
00049 
00050    void traceln(O&o, int level, const char*msg)  // trace with CR & LF
00051    {
00052        trace(o,level,msg);  trace(o,level,"\r\n");
00053    }