Compare commits
10 Commits
2d9d72e162
...
5ae907ca5a
| Author | SHA1 | Date |
|---|---|---|
|
|
5ae907ca5a | 6 months ago |
|
|
e4575605aa | 6 months ago |
|
|
c72d1a8677 | 6 months ago |
|
|
d4f5a4780c | 6 months ago |
|
|
7670ffdf42 | 6 months ago |
|
|
30638e0b29 | 6 months ago |
|
|
2fea91b6cf | 6 months ago |
|
|
0cfcfe5fcb | 6 months ago |
|
|
adbe5934fa | 6 months ago |
|
|
f03e33928b | 6 months ago |
@ -1,30 +1,95 @@
|
|||||||
#include "serialstream.h"
|
#include "serialstream.h"
|
||||||
|
#include "../utils/string.h"
|
||||||
|
|
||||||
SerialStream::SerialStream(ComPort port, BaudRate baud_rate, DataBits data_bits,
|
SerialStream::SerialStream(ComPort port, BaudRate baud_rate, DataBits data_bits,
|
||||||
StopBits stop_bits, Parity parity) {
|
StopBits stop_bits, Parity parity)
|
||||||
(void)port;
|
:Serial(port, baud_rate, data_bits, stop_bits, parity) {}
|
||||||
(void)baud_rate;
|
|
||||||
(void)data_bits;
|
void SerialStream::flush() {
|
||||||
(void)stop_bits;
|
print(buffer, strlen(buffer));
|
||||||
(void)parity;
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/3440726/what-is-the-proper-way-of-implementing-a-good-itoa-function
|
||||||
|
// Yet, another good itoa implementation
|
||||||
|
// returns: the length of the number string
|
||||||
|
int itoa(int value, char *sp, int radix)
|
||||||
|
{
|
||||||
|
char tmp[16];// be careful with the length of the buffer
|
||||||
|
char *tp = tmp;
|
||||||
|
int i;
|
||||||
|
unsigned v;
|
||||||
|
|
||||||
|
int sign = (radix == 10 && value < 0);
|
||||||
|
if (sign)
|
||||||
|
v = -value;
|
||||||
|
else
|
||||||
|
v = (unsigned)value;
|
||||||
|
|
||||||
|
while (v || tp == tmp)
|
||||||
|
{
|
||||||
|
i = v % radix;
|
||||||
|
v /= radix;
|
||||||
|
if (i < 10)
|
||||||
|
*tp++ = i+'0';
|
||||||
|
else
|
||||||
|
*tp++ = i + 'a' - 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int len = tp - tmp;
|
||||||
|
|
||||||
|
if (sign)
|
||||||
|
{
|
||||||
|
*sp++ = '-';
|
||||||
|
len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialStream::flush() {}
|
while (tp > tmp)
|
||||||
|
*sp++ = *--tp;
|
||||||
|
|
||||||
void SerialStream::setForeground(Color c) { (void)c; }
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
void SerialStream::setBackground(Color c) { (void)c; }
|
void SerialStream::setForeground(Color c) {
|
||||||
|
write(0x1b);
|
||||||
|
write('[');
|
||||||
|
write('3');
|
||||||
|
write(c + 0x30);
|
||||||
|
write('m');
|
||||||
|
}
|
||||||
|
|
||||||
void SerialStream::setAttribute(Attrib a) { (void)a; }
|
void SerialStream::setBackground(Color c) {
|
||||||
|
write(0x1b);
|
||||||
|
write('[');
|
||||||
|
write('4');
|
||||||
|
write(c + 0x30);
|
||||||
|
write('m');
|
||||||
|
}
|
||||||
|
|
||||||
void SerialStream::reset() {}
|
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) {
|
void SerialStream::setPos(int x, int y) {
|
||||||
(void)x;
|
//char out[] = {0x1b, '[', 0, 0, ';', 0, 0, 'H', 0};
|
||||||
(void)y;
|
*this << 0x1b;
|
||||||
|
*this << '[';
|
||||||
|
*this << dec << x;
|
||||||
|
*this << ';' << y << 'H' << endl;
|
||||||
|
flush();
|
||||||
|
//itoa(x, &out[2], 10);
|
||||||
|
//itoa(y, &out[5], 10);
|
||||||
|
//print( out , strlen(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialStream::print(char* str, int length) {
|
void SerialStream::print(char* str, int length) {
|
||||||
(void)str;
|
for(int i=0; i < length; i++)
|
||||||
(void)length;
|
write(str[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,21 @@
|
|||||||
#include "textstream.h"
|
#include "textstream.h"
|
||||||
|
|
||||||
TextStream::TextStream(unsigned from_col, unsigned to_col, unsigned from_row,
|
TextStream::TextStream(unsigned from_col,
|
||||||
unsigned to_row, bool use_cursor) {
|
unsigned to_col,
|
||||||
(void)from_col;
|
unsigned from_row,
|
||||||
(void)to_col;
|
unsigned to_row,
|
||||||
(void)from_row;
|
bool use_cursor)
|
||||||
(void)to_row;
|
: TextWindow(from_col,
|
||||||
(void)use_cursor;
|
to_col,
|
||||||
}
|
from_row,
|
||||||
|
to_row,
|
||||||
|
use_cursor){}
|
||||||
|
|
||||||
|
|
||||||
|
void TextStream::flush() {
|
||||||
|
print(buffer,pos);
|
||||||
|
pos = 0;
|
||||||
|
|
||||||
void TextStream::flush() {}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue