#ifndef MYTYPEDEF
#define MYTYPEDEF
#include "string.h"
#define COMPILEDEBUG //dont define this if you want to remove the debug print from the compilation
char *getSourceFileName(char *filnam);
#ifdef COMPILEDEBUG
#define debugMain 0x01
#define debugDS18B20 0x02
#define DEBUGPRINTMain if (debug & debugMain)Serial.printf((char *)"\r\n%s line %d : ", getSourceFileName((char *)__FILE__), __LINE__);if (debug & 0x01) Serial.printf
#define DEBUGPRINTDS18B20 if (debug & debugDS18B20)Serial.printf((char *)"\r\n%s/%d : ", getSourceFileName((char *)__FILE__), __LINE__);if (debug & 0x02) Serial.printf
#else
#define DEBUGPRINTMain //
#define DEBUGPRINTDS18B20 //
#endif
#endif
Usage:
- In the source file
int debug = 0; //somewhere once then extern elsewhere
"DEBUGPRINTMain("this is example %d\r\n", 1);" without the quotes - The debug print will not happen until debug has the the 0-bit turne on : 0x01 or 1
- To enable the second example turn on the 1-bit: 0x02 or 2
- Debug is enabled by viewing the Serial Monitor window and clicking on the line that says "Message" then type "debug=1 " or whichever you widh to enable. Use "debug=255" to enable all.
- To remove the debug prints from the compilation just dont define "COMPILEDEBUG".
- This does not replace the debug options providd by the Arduino IDE in the tools menu, it just allows evaluation of progress/variables when no crash occurs.
- getSourceFileName(..) is not required, use FILE instead, if you want the whole path to the source file - sometimes this is a good idea.
- A version of getSourceFileName(this could be optimised but I didn't bother as the code will not be in release version0:
#include "string.h"
char filenam[100];
char *getSourceFileName(char *filnam) {
int i=0;
strcpy(filenam, filnam);
for (i=strlen(filnam); i>0; i--) {
if ((char)filnam[i] == (char)'/') {
i++;
break;
}
}
strcpy(filenam, (char *)&filnam[i]);
strcat((char *)filenam, (char*)": ");
return(filenam);
}