You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#include "serialstream.h"
|
|
#include "../utils/string.h"
|
|
|
|
SerialStream::SerialStream(ComPort port, BaudRate baud_rate, DataBits data_bits,
|
|
StopBits stop_bits, Parity parity)
|
|
:Serial(port, baud_rate, data_bits, stop_bits, parity) {}
|
|
|
|
SerialStream sout = SerialStream();
|
|
|
|
void SerialStream::flush() {
|
|
print(sout.buffer, sout.pos);
|
|
sout.pos = 0;
|
|
}
|
|
|
|
void SerialStream::setForeground(Color c) {
|
|
write(0x1b);
|
|
write('[');
|
|
sout << 30+c;
|
|
flush();
|
|
write('m');
|
|
}
|
|
|
|
void SerialStream::setBackground(Color c) {
|
|
write(0x1b);
|
|
write('[');
|
|
write('4');
|
|
write(c + 0x30);
|
|
write('m');
|
|
}
|
|
|
|
void SerialStream::setAttribute(Attrib a) {
|
|
write(0x1b);
|
|
write('[');
|
|
write(a + 0x30);
|
|
write('m');
|
|
}
|
|
|
|
void SerialStream::reset() {
|
|
write(0x1b);
|
|
write('c');
|
|
}
|
|
|
|
void SerialStream::setPos(int x, int y) {
|
|
write(0x1b);
|
|
sout << '[';
|
|
sout << dec << x;
|
|
sout << ';';
|
|
sout << dec << y;
|
|
sout << 'H';
|
|
flush();
|
|
}
|
|
|
|
void SerialStream::print(char* str, int length) {
|
|
for(int i=0; i < length; i++)
|
|
write(str[i]);
|
|
}
|