My implementation of VT100 ESC-sequence utility

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vt100.h Source File

vt100.h

00001 #ifndef VT100_H
00002 #define VT100_H included
00003 #include "mbed.h"
00004 
00005 /** vt100 class
00006  * Utility for handling text/letter on a terminal
00007  * which can handle VT100 escape command sequence.
00008  *
00009  * Example:
00010  * @code
00011  * #include "mbed.h"
00012  * #include "vt100.h"
00013  * 
00014  * vt100 tty ;
00015  * 
00016  * int main() {
00017  *   int count = 0 ;
00018  *   tty.cls() ;
00019  *   tty.black() ;
00020  *   tty.frame(5, 5, 15, 9) ;
00021  *   while(1) {
00022  *       tty.locate(7, 7) ;
00023  *       tty.setFG(count % 8) ;
00024  *       printf("%d\r\n", count++) ;
00025  *       wait(1.0) ;
00026  *   }
00027  * }
00028  * @endcode
00029  * 
00030  * Note: I know there should be other libraries
00031  *  with similar functions, but I could not help 
00032  *  writing one for myself anyway.
00033  */
00034 
00035 class vt100 : public Serial {
00036 public:
00037     /** constructor 
00038      * @param baud baud rate
00039      */
00040     vt100(int baud = 115200) ;
00041     
00042     vt100(PinName tx_pin, PinName rx_pin, int baud=115200) ;
00043     
00044     /** destructor */
00045     ~vt100() ;
00046     
00047     /** clear screen */
00048     void cls(void) ;
00049     
00050     /** move cursor to (x, y) 
00051      * @param x start column of the next letter
00052      * @param y start row of the next letter
00053      * @note no value checking is performed.
00054      */
00055     void locate(int x, int y) ;
00056     
00057     /** print a letter c at (x,y)
00058      * @param c the letter to be written 
00059      * @param x column of the letter
00060      * @param y row of the letter
00061      */
00062     void putChar(int x, int y, char c) ;
00063     
00064     /** print a string str from (x,y) 
00065      * @param *str c-style string to be written
00066      * @param x column of the first letter
00067      * @param y row of the first letter
00068      */
00069     void putStr(int x, int y, char *str) ;
00070     
00071     /** print a line of char 
00072      * @param c the letter to form the line
00073      * @param x1 starting column
00074      * @param y1 starting row
00075      * @param x2 ending column
00076      * @param y2 ending row
00077      */
00078     void line(int x1, int y1, int x2, int y2, char c='*') ;
00079     
00080     /** print a text frame 
00081      * @param x1 left column
00082      * @param y1 top row
00083      * @param x2 right column
00084      * @param y2 bottom row
00085      */
00086     void frame(int x1, int y1, int x2, int y2) ;
00087     
00088     /** print a text circle
00089      * @c the letter to form the circle
00090      * @param x0 center column
00091      * @param y1 center row
00092      * @param r radius
00093      */
00094     void circle(int x0, int y0, int r, char c='*') ;
00095     
00096     /** set foreground color
00097      * @param newFG new foreground color
00098      * @returns previous foreground color
00099      * @note 0 BLACK
00100      * @note 1 RED
00101      * @note 2 GREEN
00102      * @note 3 YELLOW
00103      * @note 4 BLUE
00104      * @note 5 PURPLE
00105      * @note 6 CIAN
00106      * @note 7 WHITE
00107      */
00108     int setFG(int newFG) ;
00109     
00110     /** get current foreground color 
00111      * @returns current foreground color
00112      */
00113     int getFG(void) ;
00114     
00115     /** set background color
00116      * @param newBG new background color
00117      * @returns previous background color
00118      */
00119     int setBG(int newBG) ;
00120     
00121     /** get current background color 
00122      * @returns current background color
00123      */
00124     int getBG(void) ;
00125     /** set foreground color to black */
00126     void black(void) ;
00127     /** set foreground color to red */
00128     void red(void) ;
00129     /** set foreground color to green */
00130     void green(void) ;
00131     /** set foreground color to yellow */
00132     void yellow(void) ;
00133     /** set foreground color to blue */
00134     void blue(void) ;
00135     /** set foreground color to purple */
00136     void purple(void) ;
00137     /** set foreground color to cian */
00138     void cian(void) ;
00139     /** set foreground color to white */
00140     void white(void) ;
00141 protected:
00142 private:
00143     int foreground ;
00144     int background ;
00145 
00146 } ;
00147 
00148 #endif /* VT100_H */