-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerialOut.h
102 lines (83 loc) · 1.68 KB
/
SerialOut.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#include "BufferedOut.h"
namespace embedded
{
class PacketUart;
class SerialOut
{
public:
struct end {};
struct endl {};
using precision = embedded::BufferedOut::precision;
SerialOut(MemoryView<char> buffer, PacketUart &uart) : uartDevice(uart), bufferedOut(buffer) {}
SerialOut &operator<<(const char* str)
{
bufferedOut << str;
return *this;
}
SerialOut &operator<<(int n)
{
bufferedOut << n;
return *this;
}
SerialOut &operator<<(unsigned int n)
{
bufferedOut << n;
return *this;
}
SerialOut &operator<<(long n)
{
bufferedOut << n;
return *this;
}
SerialOut &operator<<(unsigned long n)
{
bufferedOut << n;
return *this;
}
SerialOut &operator<<(long long n)
{
bufferedOut << n;
return *this;
}
SerialOut &operator<<(unsigned long long n)
{
bufferedOut << n;
return *this;
}
SerialOut &operator<<(float f)
{
bufferedOut << f;
return *this;
}
SerialOut &operator<<(precision p)
{
bufferedOut << p;
return *this;
}
SerialOut &operator<<(embedded::BytesView span)
{
bufferedOut << span;
return *this;
}
SerialOut &operator<<(end)
{
flush();
return *this;
}
SerialOut &operator<<(endl)
{
if (bufferedOut.size() == bufferedOut.capacity())
{
flush();
}
bufferedOut.addChar('\n');
flush();
return *this;
}
private:
void flush();
PacketUart &uartDevice;
BufferedOut bufferedOut;
};
}