Improved version of Simon Ford's TextDisplay library, with addressing and timing fixes. Supports up to 20x4 text displays.
Terminal.cpp@0:2c5bba968d7c, 2010-02-14 (annotated)
- Committer:
- bikeNomad
- Date:
- Sun Feb 14 00:28:08 2010 +0000
- Revision:
- 0:2c5bba968d7c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bikeNomad | 0:2c5bba968d7c | 1 | /* mbed Terminal TextDisplay Library |
bikeNomad | 0:2c5bba968d7c | 2 | * Copyright (c) 2007-2009 sford |
bikeNomad | 0:2c5bba968d7c | 3 | * Released under the MIT License: http://mbed.org/license/mit |
bikeNomad | 0:2c5bba968d7c | 4 | */ |
bikeNomad | 0:2c5bba968d7c | 5 | |
bikeNomad | 0:2c5bba968d7c | 6 | #include "Terminal.h" |
bikeNomad | 0:2c5bba968d7c | 7 | |
bikeNomad | 0:2c5bba968d7c | 8 | #include "mbed.h" |
bikeNomad | 0:2c5bba968d7c | 9 | |
bikeNomad | 0:2c5bba968d7c | 10 | Terminal::Terminal(PinName tx, PinName rx) : _serial(tx, rx) { |
bikeNomad | 0:2c5bba968d7c | 11 | cls(); |
bikeNomad | 0:2c5bba968d7c | 12 | } |
bikeNomad | 0:2c5bba968d7c | 13 | |
bikeNomad | 0:2c5bba968d7c | 14 | void Terminal::character(uint16_t column, uint16_t row, int c) { |
bikeNomad | 0:2c5bba968d7c | 15 | // Cursor Home <ESC>[{ROW};{COLUMN}H |
bikeNomad | 0:2c5bba968d7c | 16 | _serial.printf("\033[%u;%uH%c", row + 1, column + 1, c); |
bikeNomad | 0:2c5bba968d7c | 17 | } |
bikeNomad | 0:2c5bba968d7c | 18 | |
bikeNomad | 0:2c5bba968d7c | 19 | uint16_t Terminal::columns() { |
bikeNomad | 0:2c5bba968d7c | 20 | return 80; |
bikeNomad | 0:2c5bba968d7c | 21 | } |
bikeNomad | 0:2c5bba968d7c | 22 | |
bikeNomad | 0:2c5bba968d7c | 23 | uint16_t Terminal::rows() { |
bikeNomad | 0:2c5bba968d7c | 24 | return 35; |
bikeNomad | 0:2c5bba968d7c | 25 | } |
bikeNomad | 0:2c5bba968d7c | 26 | |
bikeNomad | 0:2c5bba968d7c | 27 | void Terminal::cls() { |
bikeNomad | 0:2c5bba968d7c | 28 | _serial.printf("\033[2J"); |
bikeNomad | 0:2c5bba968d7c | 29 | } |
bikeNomad | 0:2c5bba968d7c | 30 | |
bikeNomad | 0:2c5bba968d7c | 31 | void Terminal::foreground(uint32_t colour) { |
bikeNomad | 0:2c5bba968d7c | 32 | |
bikeNomad | 0:2c5bba968d7c | 33 | /* Set Attribute Mode <ESC>[{n}m |
bikeNomad | 0:2c5bba968d7c | 34 | * - Sets display attribute settings. The following lists standard attributes: |
bikeNomad | 0:2c5bba968d7c | 35 | * |
bikeNomad | 0:2c5bba968d7c | 36 | * Foreground Colours |
bikeNomad | 0:2c5bba968d7c | 37 | * 30 Black |
bikeNomad | 0:2c5bba968d7c | 38 | * 31 Red |
bikeNomad | 0:2c5bba968d7c | 39 | * 32 Green |
bikeNomad | 0:2c5bba968d7c | 40 | * 33 Yellow |
bikeNomad | 0:2c5bba968d7c | 41 | * 34 Blue |
bikeNomad | 0:2c5bba968d7c | 42 | * 35 Magenta |
bikeNomad | 0:2c5bba968d7c | 43 | * 36 Cyan |
bikeNomad | 0:2c5bba968d7c | 44 | * 37 White |
bikeNomad | 0:2c5bba968d7c | 45 | */ |
bikeNomad | 0:2c5bba968d7c | 46 | uint32_t r = (colour >> 23) & 1; |
bikeNomad | 0:2c5bba968d7c | 47 | uint32_t g = (colour >> 15) & 1; |
bikeNomad | 0:2c5bba968d7c | 48 | uint32_t b = (colour >> 7) & 1; |
bikeNomad | 0:2c5bba968d7c | 49 | uint32_t bgr = (b << 2) | (g << 1) | (r << 0); |
bikeNomad | 0:2c5bba968d7c | 50 | uint32_t c = 30 + bgr; |
bikeNomad | 0:2c5bba968d7c | 51 | _serial.printf("\033[%um", c); |
bikeNomad | 0:2c5bba968d7c | 52 | } |
bikeNomad | 0:2c5bba968d7c | 53 | |
bikeNomad | 0:2c5bba968d7c | 54 | void Terminal::background(uint32_t colour) { |
bikeNomad | 0:2c5bba968d7c | 55 | |
bikeNomad | 0:2c5bba968d7c | 56 | /* Background Colours |
bikeNomad | 0:2c5bba968d7c | 57 | * 40 Black |
bikeNomad | 0:2c5bba968d7c | 58 | * 41 Red |
bikeNomad | 0:2c5bba968d7c | 59 | * 42 Green |
bikeNomad | 0:2c5bba968d7c | 60 | * 43 Yellow |
bikeNomad | 0:2c5bba968d7c | 61 | * 44 Blue |
bikeNomad | 0:2c5bba968d7c | 62 | * 45 Magenta |
bikeNomad | 0:2c5bba968d7c | 63 | * 46 Cyan |
bikeNomad | 0:2c5bba968d7c | 64 | * 47 White |
bikeNomad | 0:2c5bba968d7c | 65 | */ |
bikeNomad | 0:2c5bba968d7c | 66 | uint32_t r = (colour >> 23) & 1; |
bikeNomad | 0:2c5bba968d7c | 67 | uint32_t g = (colour >> 15) & 1; |
bikeNomad | 0:2c5bba968d7c | 68 | uint32_t b = (colour >> 7) & 1; |
bikeNomad | 0:2c5bba968d7c | 69 | uint32_t bgr = (b << 2) | (g << 1) | (r << 0); |
bikeNomad | 0:2c5bba968d7c | 70 | uint32_t c = 40 + bgr; |
bikeNomad | 0:2c5bba968d7c | 71 | _serial.printf("\033[%um", c); |
bikeNomad | 0:2c5bba968d7c | 72 | } |
bikeNomad | 0:2c5bba968d7c | 73 |