forked from Open-Acidification/TankController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerial_TC.cpp
More file actions
66 lines (59 loc) · 1.43 KB
/
Serial_TC.cpp
File metadata and controls
66 lines (59 loc) · 1.43 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
#include "Devices/Serial_TC.h"
#include "DateTime_TC.h"
#include "SD_TC.h"
#include "TC_util.h"
/**
* global serial() functions
*/
void serial(const __FlashStringHelper *format...) {
va_list args;
va_start(args, format);
Serial_TC::instance()->vprintf(format, args);
va_end(args);
}
void serial(const char *buffer) {
serial(F("%s"), buffer);
}
/**
* static variable for singleton
*/
Serial_TC *Serial_TC::_instance = nullptr;
/**
* static member function to return singleton
*/
Serial_TC *Serial_TC::instance() {
if (!_instance) {
_instance = new Serial_TC();
}
return _instance;
}
/**
* constructor (private so clients use the singleton)
*/
Serial_TC::Serial_TC() {
Serial.begin(9600);
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial)
;
}
/**
* printf() uses a variant of snprintf() so supports the expected formats
*/
// void Serial_TC::vprintf(const char *format, va_list args) {
void Serial_TC::vprintf(const __FlashStringHelper *format, va_list args) {
char buffer[128];
vsnprintf_P(buffer, sizeof(buffer), (PGM_P)format, args);
Serial.println(buffer);
Serial.flush();
// need to avoid recursion since SD_TC could call serial()
if (!printIsActive) {
printIsActive = true;
SD_TC::instance()->appendToLog(buffer);
printIsActive = false;
}
#ifdef MOCK_PINS_COUNT
#if DEBUG
std::cout << "\tSERIAL: " << buffer << std::endl;
#endif
#endif
}