James Grant / Mbed 2 deprecated NewMobileLCD

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Terminal.cpp Source File

Terminal.cpp

00001 /* mbed ANSI/VT100 Terminal Library
00002  * Copyright (c) 2007-2009 sford
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005 
00006 #include "Terminal.h"
00007 
00008 #include "mbed.h"
00009 
00010 Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx) {}
00011 
00012 void Terminal::cls() {
00013     this->printf("\033[2J");
00014 }
00015 
00016 void Terminal::locate(int column, int row) {
00017     // Cursor Home    <ESC>[{ROW};{COLUMN}H
00018     this->printf("\033[%d;%dH%c", row + 1, column + 1);
00019 }
00020 
00021 static int rgb888tobgr111(int colour) {
00022     int r = (colour >> 23) & 1;
00023     int g = (colour >> 15) & 1;
00024     int b = (colour >> 7) & 1;
00025     return (b << 2) | (g << 1) | (r << 0);
00026 }
00027 
00028 void Terminal::foreground(int colour) {
00029     // Set Attribute Mode    <ESC>[{n}m
00030     // Foreground Colours : 30 + bgr
00031     int c = 30 + rgb888tobgr111(colour);
00032     this->printf("\033[%dm", c);
00033 }
00034 
00035 void Terminal::background(int colour) {
00036     // Set Attribute Mode    <ESC>[{n}m
00037     // Background Colours : 40 + bgr
00038     int c = 40 + rgb888tobgr111(colour);
00039     this->printf("\033[%dm", c);
00040 }