A TextDisplay driver that supports graphical displays using on of the SED133x conrtrolers. Allows stdout and stderr output to be redirected to the display.
Terminal.cpp
- Committer:
- llagendijk
- Date:
- 2011-01-15
- Revision:
- 1:18c56f038905
- Parent:
- 0:9e72c57b16fd
- Child:
- 5:684f79f70ac9
File content as of revision 1:18c56f038905:
/* mbed Terminal TextDisplay Library * Copyright (c) 2007-2009 sford * Released under the MIT License: http://mbed.org/license/mit */ #include "Terminal.h" #include "mbed.h" Terminal::Terminal(PinName tx, PinName rx, const char *name) : TextDisplay(name), _serial(tx, rx) { cls(); } void Terminal::character(uint16_t column, uint16_t row, int c) { // Cursor Home <ESC>[{ROW};{COLUMN}H _serial.printf("\033[%u;%uH%c", row + 1, column + 1, c); } uint16_t Terminal::columns() { return 80; } uint16_t Terminal::rows() { return 35; } void Terminal::cls() { _serial.printf("\033[2J"); } void Terminal::foreground(uint32_t colour) { /* Set Attribute Mode <ESC>[{n}m * - Sets display attribute settings. The following lists standard attributes: * * Foreground Colours * 30 Black * 31 Red * 32 Green * 33 Yellow * 34 Blue * 35 Magenta * 36 Cyan * 37 White */ uint32_t r = (colour >> 23) & 1; uint32_t g = (colour >> 15) & 1; uint32_t b = (colour >> 7) & 1; uint32_t bgr = (b << 2) | (g << 1) | (r << 0); uint32_t c = 30 + bgr; _serial.printf("\033[%um", c); } void Terminal::background(uint32_t colour) { /* Background Colours * 40 Black * 41 Red * 42 Green * 43 Yellow * 44 Blue * 45 Magenta * 46 Cyan * 47 White */ uint32_t r = (colour >> 23) & 1; uint32_t g = (colour >> 15) & 1; uint32_t b = (colour >> 7) & 1; uint32_t bgr = (b << 2) | (g << 1) | (r << 0); uint32_t c = 40 + bgr; _serial.printf("\033[%um", c); }