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.
Terminal.cpp
- Committer:
- simon
- Date:
- 2009-12-31
- Revision:
- 0:2bf27af3c759
- Child:
- 1:96ae39e58792
File content as of revision 0:2bf27af3c759:
/* mbed ANSI/VT100 Terminal 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) : Serial(tx, rx) {}
void Terminal::cls() {
this->printf("\033[2J");
}
void Terminal::locate(int column, int row) {
// Cursor Home <ESC>[{ROW};{COLUMN}H
this->printf("\033[%d;%dH%c", row + 1, column + 1);
}
static int rgb888tobgr111(int colour) {
int r = (colour >> 23) & 1;
int g = (colour >> 15) & 1;
int b = (colour >> 7) & 1;
return (b << 2) | (g << 1) | (r << 0);
}
void Terminal::foreground(int colour) {
// Set Attribute Mode <ESC>[{n}m
// Foreground Colours : 30 + bgr
int c = 30 + rgb888tobgr111(colour);
this->printf("\033[%dm", c);
}
void Terminal::background(int colour) {
// Set Attribute Mode <ESC>[{n}m
// Background Colours : 40 + bgr
int c = 40 + rgb888tobgr111(colour);
this->printf("\033[%dm", c);
}