Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SerialTerminal.cpp
00001 #include "SerialTerminal.h" 00002 00003 #include "mbed.h" 00004 00005 SerialTerminal::SerialTerminal(PinName tx, PinName rx, int Baudrate) : Serial(tx, rx) 00006 { 00007 this->baud(Baudrate); 00008 } 00009 00010 void SerialTerminal::cls() { 00011 this->printf("\033[2J"); 00012 } 00013 00014 void SerialTerminal::locate(int column, int row) { 00015 // Cursor Home <ESC>[{ROW};{COLUMN}H 00016 this->printf("\033[%d;%dH%c", row + 1, column + 1); 00017 } 00018 00019 static int rgb888tobgr111(int colour) { 00020 int r = (colour >> 23) & 1; 00021 int g = (colour >> 15) & 1; 00022 int b = (colour >> 7) & 1; 00023 return (b << 2) | (g << 1) | (r << 0); 00024 } 00025 00026 void SerialTerminal::foreground(int colour) { 00027 // Set Attribute Mode <ESC>[{n}m 00028 // Foreground Colours : 30 + bgr 00029 int c = 30 + rgb888tobgr111(colour); 00030 this->printf("\033[%dm", c); 00031 } 00032 00033 void SerialTerminal::background(int colour) { 00034 // Set Attribute Mode <ESC>[{n}m 00035 // Background Colours : 40 + bgr 00036 int c = 40 + rgb888tobgr111(colour); 00037 this->printf("\033[%dm", c); 00038 } 00039 00040 void SerialTerminal::hideCursor() { 00041 //Hide cursor from terminal 00042 this->printf("\033[?25l"); 00043 } 00044 00045 void SerialTerminal::showCursor() { 00046 //Hide cursor from terminal 00047 this->printf("\33[[?25h"); 00048 } 00049 00050 void SerialTerminal::move_cursor_up(int step_num) { 00051 this->printf("\033[%dA", step_num); 00052 } 00053 00054 void SerialTerminal::move_cursor_down(int step_num) { 00055 this->printf("\033[%dB", step_num); 00056 } 00057 00058 void SerialTerminal::move_cursor_right(int step_num) { 00059 this->printf("\033[%dC", step_num); 00060 } 00061 00062 void SerialTerminal::move_cursor_left(int step_num) { 00063 this->printf("\033[%dD", step_num); 00064 } 00065 00066 void SerialTerminal::hide_cursor() { 00067 this->printf("\e[?25l"); 00068 } 00069 00070 void SerialTerminal::show_cursor() { 00071 this->printf("\e[?25h"); 00072 }
Generated on Thu Aug 11 2022 22:22:57 by
