#include <stdio.h>
#include <stdarg.h>

#define config_ENABLE_DEBUG_MAIN 		1

static char txBuffer[100];

void PrintDebug(char * fileName, int lineNumber, char * msg, ...) {

	// NOTE: Replace all printf() calls in here with whatever is appropriate for
	// the microcontroller you are using, e.g. Uart_PutString(txBuffer);
	
	// Create "header" of debug message and send to UART peripheral
	snprintf(txBuffer, sizeof(txBuffer), "%s, %i: ", fileName, lineNumber);
	printf(txBuffer);
	
	// Format the "guts" of the debug message into a string
	va_list args;
	va_start(args, msg);
	vsnprintf(txBuffer, sizeof(txBuffer), msg, args);
	
	// Send formatted "guts" to the UART peripheral
	printf(txBuffer);
	printf("\r\n");
	
}

#if(config_ENABLE_DEBUG_MAIN == 1)
	#define DEBUG(...) PrintDebug(__FILE__, __LINE__, __VA_ARGS__)
#else
	#define DEBUG(...)
#endif


int main(void) {
	DEBUG("Testing debug print capabilities...");
	
	DEBUG("This should print both the filename and line number!");
	
	int x = 5;
	DEBUG("We can also use this like printf()! x = %i", x);
	
	return 0;
}
