modified Library from sford for use with TeraTerm / VT100 emulation without sending any signs after a \"locate\" command. edited Line 35 -> deleted %c
Terminal.cpp@0:acdab91342e6, 2012-01-26 (annotated)
- Committer:
- Ipu
- Date:
- Thu Jan 26 19:30:33 2012 +0000
- Revision:
- 0:acdab91342e6
- Child:
- 1:a3bd01d498a9
Version without sending different signs after locate
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:acdab91342e6 | 23 | #include "Terminal.h" |
Ipu | 0:acdab91342e6 | 24 | |
Ipu | 0:acdab91342e6 | 25 | #include "mbed.h" |
Ipu | 0:acdab91342e6 | 26 | |
Ipu | 0:acdab91342e6 | 27 | Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx) {} |
Ipu | 0:acdab91342e6 | 28 | |
Ipu | 0:acdab91342e6 | 29 | void Terminal::cls() { |
Ipu | 0:acdab91342e6 | 30 | this->printf("\033[2J"); |
Ipu | 0:acdab91342e6 | 31 | } |
Ipu | 0:acdab91342e6 | 32 | |
Ipu | 0:acdab91342e6 | 33 | void Terminal::locate(int column, int row) { |
Ipu | 0:acdab91342e6 | 34 | // Cursor Home <ESC>[{ROW};{COLUMN}H |
Ipu | 0:acdab91342e6 | 35 | this->printf("\033[%d;%dH", row + 1, column + 1); |
Ipu | 0:acdab91342e6 | 36 | } |
Ipu | 0:acdab91342e6 | 37 | |
Ipu | 0:acdab91342e6 | 38 | static int rgb888tobgr111(int colour) { |
Ipu | 0:acdab91342e6 | 39 | int r = (colour >> 23) & 1; |
Ipu | 0:acdab91342e6 | 40 | int g = (colour >> 15) & 1; |
Ipu | 0:acdab91342e6 | 41 | int b = (colour >> 7) & 1; |
Ipu | 0:acdab91342e6 | 42 | return (b << 2) | (g << 1) | (r << 0); |
Ipu | 0:acdab91342e6 | 43 | } |
Ipu | 0:acdab91342e6 | 44 | |
Ipu | 0:acdab91342e6 | 45 | void Terminal::foreground(int colour) { |
Ipu | 0:acdab91342e6 | 46 | // Set Attribute Mode <ESC>[{n}m |
Ipu | 0:acdab91342e6 | 47 | // Foreground Colours : 30 + bgr |
Ipu | 0:acdab91342e6 | 48 | int c = 30 + rgb888tobgr111(colour); |
Ipu | 0:acdab91342e6 | 49 | this->printf("\033[%dm", c); |
Ipu | 0:acdab91342e6 | 50 | } |
Ipu | 0:acdab91342e6 | 51 | |
Ipu | 0:acdab91342e6 | 52 | void Terminal::background(int colour) { |
Ipu | 0:acdab91342e6 | 53 | // Set Attribute Mode <ESC>[{n}m |
Ipu | 0:acdab91342e6 | 54 | // Background Colours : 40 + bgr |
Ipu | 0:acdab91342e6 | 55 | int c = 40 + rgb888tobgr111(colour); |
Ipu | 0:acdab91342e6 | 56 | this->printf("\033[%dm", c); |
Ipu | 0:acdab91342e6 | 57 | } |