-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.cpp
54 lines (41 loc) · 1.02 KB
/
Common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdlib.h>
#include "Common.h"
#ifdef WIN32
static char FormatBuffer[4096];
static CRITICAL_SECTION CriticalSection;
static bool CriticalSectionInitialized = false;
void DbgPrint(const char* fmt, ...)
{
va_list args;
if (!CriticalSectionInitialized)
{
InitializeCriticalSection(&CriticalSection);
CriticalSectionInitialized = true;
}
EnterCriticalSection(&CriticalSection);
va_start(args, fmt);
vsprintf_s(FormatBuffer, 4096, fmt, args);
OutputDebugStringA(FormatBuffer);
LeaveCriticalSection(&CriticalSection);
}
#else
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdlib.h>
#include <string.h>
#include <util/delay.h>
#include <Arduino.h>
void DbgPrint(const char* fmt, ...)
{
char FormatBuffer[128];
va_list args;
va_start(args, fmt);
vsprintf(FormatBuffer, fmt, args);
char c;
char* addr = FormatBuffer;
while ((c = *addr++))
{
Serial.print(c);
}
}
#endif