modified Library from sford for use with TeraTerm / VT100 emulation without sending any signs after a \"locate\" command. edited Line 35 -> deleted %c

Committer:
Ipu
Date:
Fri Jan 27 08:57:21 2012 +0000
Revision:
1:a3bd01d498a9
Parent:
0:acdab91342e6
insert comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ipu 0:acdab91342e6 1 /* mbed Terminal Library, for ANSI/VT200 Terminals and ecape codes
Ipu 0:acdab91342e6 2 * Copyright (c) 2007-2010, sford, http://mbed.org
Ipu 0:acdab91342e6 3 *
Ipu 0:acdab91342e6 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Ipu 0:acdab91342e6 5 * of this software and associated documentation files (the "Software"), to deal
Ipu 0:acdab91342e6 6 * in the Software without restriction, including without limitation the rights
Ipu 0:acdab91342e6 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Ipu 0:acdab91342e6 8 * copies of the Software, and to permit persons to whom the Software is
Ipu 0:acdab91342e6 9 * furnished to do so, subject to the following conditions:
Ipu 0:acdab91342e6 10 *
Ipu 0:acdab91342e6 11 * The above copyright notice and this permission notice shall be included in
Ipu 0:acdab91342e6 12 * all copies or substantial portions of the Software.
Ipu 0:acdab91342e6 13 *
Ipu 0:acdab91342e6 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Ipu 0:acdab91342e6 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Ipu 0:acdab91342e6 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Ipu 0:acdab91342e6 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Ipu 0:acdab91342e6 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Ipu 0:acdab91342e6 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Ipu 0:acdab91342e6 20 * THE SOFTWARE.
Ipu 0:acdab91342e6 21 */
Ipu 0:acdab91342e6 22
Ipu 1:a3bd01d498a9 23 /*
Ipu 1:a3bd01d498a9 24 * 26.01.2012 -> Line 35 edited by Stefan Hendrich, all other code is original
Ipu 1:a3bd01d498a9 25 */
Ipu 1:a3bd01d498a9 26
Ipu 1:a3bd01d498a9 27
Ipu 0:acdab91342e6 28 #include "Terminal.h"
Ipu 0:acdab91342e6 29
Ipu 0:acdab91342e6 30 #include "mbed.h"
Ipu 0:acdab91342e6 31
Ipu 0:acdab91342e6 32 Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx) {}
Ipu 0:acdab91342e6 33
Ipu 0:acdab91342e6 34 void Terminal::cls() {
Ipu 0:acdab91342e6 35 this->printf("\033[2J");
Ipu 0:acdab91342e6 36 }
Ipu 0:acdab91342e6 37
Ipu 0:acdab91342e6 38 void Terminal::locate(int column, int row) {
Ipu 0:acdab91342e6 39 // Cursor Home <ESC>[{ROW};{COLUMN}H
Ipu 1:a3bd01d498a9 40 this->printf("\033[%d;%dH", row + 1, column + 1); // %c deleted by Stefan Hendrich at 26.01.2012
Ipu 0:acdab91342e6 41 }
Ipu 0:acdab91342e6 42
Ipu 0:acdab91342e6 43 static int rgb888tobgr111(int colour) {
Ipu 0:acdab91342e6 44 int r = (colour >> 23) & 1;
Ipu 0:acdab91342e6 45 int g = (colour >> 15) & 1;
Ipu 0:acdab91342e6 46 int b = (colour >> 7) & 1;
Ipu 0:acdab91342e6 47 return (b << 2) | (g << 1) | (r << 0);
Ipu 0:acdab91342e6 48 }
Ipu 0:acdab91342e6 49
Ipu 0:acdab91342e6 50 void Terminal::foreground(int colour) {
Ipu 0:acdab91342e6 51 // Set Attribute Mode <ESC>[{n}m
Ipu 0:acdab91342e6 52 // Foreground Colours : 30 + bgr
Ipu 0:acdab91342e6 53 int c = 30 + rgb888tobgr111(colour);
Ipu 0:acdab91342e6 54 this->printf("\033[%dm", c);
Ipu 0:acdab91342e6 55 }
Ipu 0:acdab91342e6 56
Ipu 0:acdab91342e6 57 void Terminal::background(int colour) {
Ipu 0:acdab91342e6 58 // Set Attribute Mode <ESC>[{n}m
Ipu 0:acdab91342e6 59 // Background Colours : 40 + bgr
Ipu 0:acdab91342e6 60 int c = 40 + rgb888tobgr111(colour);
Ipu 0:acdab91342e6 61 this->printf("\033[%dm", c);
Ipu 0:acdab91342e6 62 }