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.
Dependents: Fancy-Terminal-Menu Fancy-Terminal
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 }
Generated on Wed Jul 20 2022 02:15:49 by
1.7.2