|  |  | @ -5,18 +5,55 @@ SerialStream::SerialStream(ComPort port, BaudRate baud_rate, DataBits data_bits, | 
			
		
	
		
		
			
				
					
					|  |  |  |                            StopBits stop_bits, Parity parity) |  |  |  |                            StopBits stop_bits, Parity parity) | 
			
		
	
		
		
			
				
					
					|  |  |  |     :Serial(port, baud_rate, data_bits, stop_bits, parity) {} |  |  |  |     :Serial(port, baud_rate, data_bits, stop_bits, parity) {} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | SerialStream kout = SerialStream(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | void SerialStream::flush() { |  |  |  | void SerialStream::flush() { | 
			
		
	
		
		
			
				
					
					|  |  |  |   print(kout.buffer, kout.pos); |  |  |  |   print(buffer, strlen(buffer)); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   kout.pos = 0; |  |  |  | } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | // 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++; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     while (tp > tmp) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         *sp++ = *--tp; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return len; | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void SerialStream::setForeground(Color c) { |  |  |  | void SerialStream::setForeground(Color c) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     write(0x1b); |  |  |  |     write(0x1b); | 
			
		
	
		
		
			
				
					
					|  |  |  |     write('['); |  |  |  |     write('['); | 
			
		
	
		
		
			
				
					
					|  |  |  |     kout <<  30+c; |  |  |  |     write('3'); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     flush(); |  |  |  |     write(c + 0x30); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     write('m'); |  |  |  |     write('m'); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -42,13 +79,10 @@ void SerialStream::reset() { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void SerialStream::setPos(int x, int y) { |  |  |  | void SerialStream::setPos(int x, int y) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     //char out[] = {0x1b, '[', 0, 0, ';', 0, 0, 'H', 0};
 |  |  |  |     //char out[] = {0x1b, '[', 0, 0, ';', 0, 0, 'H', 0};
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     //*this << 0x1b;
 |  |  |  |     *this << 0x1b; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     write(0x1b); |  |  |  |     *this << '['; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     kout << '['; |  |  |  |     *this << dec << x; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     kout << dec << x; |  |  |  |     *this << ';' << y << 'H' << endl; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     kout << ';'; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     kout << dec << y; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     kout << 'H'; |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     flush(); |  |  |  |     flush(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     //itoa(x, &out[2], 10);
 |  |  |  |     //itoa(x, &out[2], 10);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     //itoa(y, &out[5], 10);
 |  |  |  |     //itoa(y, &out[5], 10);
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |