summaryrefslogtreecommitdiff
path: root/src/utils/serial.cpp
blob: 11be5502921e8258bd3c0876dde072b3b146d34a (plain)
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
#include "serial.hpp"

#include "general.hpp"

SerialStream::SerialStream(Serial_ serial, unsigned long baud_rate)
{
	this->_serial = serial;

	this->_serial.begin(baud_rate);

	while (!this->_serial) {}
}

SerialStream::~SerialStream()
{
	Serial.end();
}

SerialStream &SerialStream::operator<<(const char *str)
{
	this->write(str);
	return *this;
}

SerialStream &SerialStream::operator<<(const SmartString &str)
{
	this->write(str.c_str);
	return *this;
}

SerialStream &SerialStream::operator<<(const float num)
{
	this->write(floatToStr(num)->c_str);
	return *this;
}

SerialStream &SerialStream::operator<<(void (*manipulator)(SerialStream *))
{
	manipulator(this);
	return *this;
}

void SerialStream::write(const char *str)
{
	this->_serial.write(str);
}

void SerialStream::flush()
{
	this->_serial.flush();
}

void endl(SerialStream *serial_stream)
{
	serial_stream->write("\n");
	serial_stream->flush();
}