This commit is contained in:
Niklas Gollenstede
2025-10-31 22:37:36 +01:00
commit 174fe17e89
197 changed files with 79558 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#include "serialstream.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) {}
void SerialStream::flush() {
print(buffer, pos);
pos = 0;
}
void SerialStream::setForeground(Color c) {
*this << "\e[" << (30 + static_cast<uint32_t>(c)) << 'm';
}
void SerialStream::setBackground(Color c) {
*this << "\e[" << (40 + static_cast<uint32_t>(c)) << 'm';
}
void SerialStream::setAttribute(Attrib a) {
*this << "\e[" << static_cast<uint32_t>(a) << 'm';
}
void SerialStream::reset() { *this << "\ec" << ::flush; }
void SerialStream::setPos(int x, int y) {
*this << "\e[" << (y + 1) << ';' << (x + 1) << 'H' << ::flush;
}
void SerialStream::print(char* str, int length) {
for (int p = 0; p < length; p++) {
if (str[p] == '\n' && (p == 0 || str[p - 1] != '\r')) {
write('\r');
}
write(str[p]);
}
}