Initial commit

Dependents:   Presence_detector

Fork of Terminal by Simon Ford

Committer:
anmar
Date:
Fri Dec 05 10:25:54 2014 +0000
Revision:
3:63c8617cf6d5
Parent:
2:85184c13476c
Initial commit;

Who changed what in which revision?

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