-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial_port.hpp
More file actions
46 lines (42 loc) · 829 Bytes
/
serial_port.hpp
File metadata and controls
46 lines (42 loc) · 829 Bytes
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
#include <array>
#include <istream>
#include <ostream>
namespace serial_port
{
/**
* Output stream for characters to serial port.
*
* \pre call \ref initialize() before using
*/
extern std::ostream &cout;
extern std::istream &cin;
/**
* Configures and initializes serial port.
*/
void initialize();
} // namespace serial_port
/**
* Writes formatted bits to `ostream`.
*
* \tparam BITS number of bits
* \param os output stream to write to
* \param bitArray the bits to output
* \returns the stream
*/
template <std::size_t BITS>
std::ostream &operator<<(std::ostream &os, const std::array<bool, BITS> &bitArray)
{
os << "0b";
for (const bool bit : bitArray)
{
if (bit)
{
os << "1";
}
else
{
os << "0";
}
}
return os;
}