Improved version of Simon Ford's TextDisplay library, with addressing and timing fixes. Supports up to 20x4 text displays.
TextDisplay.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 TextDisplay Display Library Base Class |
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 "TextDisplay.h" |
bikeNomad | 0:2c5bba968d7c | 7 | |
bikeNomad | 0:2c5bba968d7c | 8 | TextDisplay::TextDisplay() { |
bikeNomad | 0:2c5bba968d7c | 9 | _row = 0; |
bikeNomad | 0:2c5bba968d7c | 10 | _column = 0; |
bikeNomad | 0:2c5bba968d7c | 11 | } |
bikeNomad | 0:2c5bba968d7c | 12 | |
bikeNomad | 0:2c5bba968d7c | 13 | int TextDisplay::_putc(int value) { |
bikeNomad | 0:2c5bba968d7c | 14 | if(value == '\n') { |
bikeNomad | 0:2c5bba968d7c | 15 | _column = 0; |
bikeNomad | 0:2c5bba968d7c | 16 | _row++; |
bikeNomad | 0:2c5bba968d7c | 17 | if(_row >= rows()) { |
bikeNomad | 0:2c5bba968d7c | 18 | _row = 0; |
bikeNomad | 0:2c5bba968d7c | 19 | } |
bikeNomad | 0:2c5bba968d7c | 20 | } else { |
bikeNomad | 0:2c5bba968d7c | 21 | character(_column, _row, value); |
bikeNomad | 0:2c5bba968d7c | 22 | _column++; |
bikeNomad | 0:2c5bba968d7c | 23 | if(_column >= columns()) { |
bikeNomad | 0:2c5bba968d7c | 24 | _column = 0; |
bikeNomad | 0:2c5bba968d7c | 25 | _row++; |
bikeNomad | 0:2c5bba968d7c | 26 | if(_row >= rows()) { |
bikeNomad | 0:2c5bba968d7c | 27 | _row = 0; |
bikeNomad | 0:2c5bba968d7c | 28 | } |
bikeNomad | 0:2c5bba968d7c | 29 | } |
bikeNomad | 0:2c5bba968d7c | 30 | } |
bikeNomad | 0:2c5bba968d7c | 31 | return value; |
bikeNomad | 0:2c5bba968d7c | 32 | } |
bikeNomad | 0:2c5bba968d7c | 33 | |
bikeNomad | 0:2c5bba968d7c | 34 | // crude cls implementation, should generally be overwritten in derived class |
bikeNomad | 0:2c5bba968d7c | 35 | void TextDisplay::cls() { |
bikeNomad | 0:2c5bba968d7c | 36 | locate(0, 0); |
bikeNomad | 0:2c5bba968d7c | 37 | for(int i=0; i<columns()*rows(); i++) { |
bikeNomad | 0:2c5bba968d7c | 38 | putc(' '); |
bikeNomad | 0:2c5bba968d7c | 39 | } |
bikeNomad | 0:2c5bba968d7c | 40 | } |
bikeNomad | 0:2c5bba968d7c | 41 | |
bikeNomad | 0:2c5bba968d7c | 42 | void TextDisplay::locate(uint16_t column, uint16_t row) { |
bikeNomad | 0:2c5bba968d7c | 43 | _column = column; |
bikeNomad | 0:2c5bba968d7c | 44 | _row = row; |
bikeNomad | 0:2c5bba968d7c | 45 | } |
bikeNomad | 0:2c5bba968d7c | 46 | |
bikeNomad | 0:2c5bba968d7c | 47 | int TextDisplay::_getc() { |
bikeNomad | 0:2c5bba968d7c | 48 | return -1; |
bikeNomad | 0:2c5bba968d7c | 49 | } |
bikeNomad | 0:2c5bba968d7c | 50 | |
bikeNomad | 0:2c5bba968d7c | 51 | void TextDisplay::foreground(uint32_t colour) { |
bikeNomad | 0:2c5bba968d7c | 52 | _foreground = colour; |
bikeNomad | 0:2c5bba968d7c | 53 | } |
bikeNomad | 0:2c5bba968d7c | 54 | |
bikeNomad | 0:2c5bba968d7c | 55 | void TextDisplay::background(uint32_t colour) { |
bikeNomad | 0:2c5bba968d7c | 56 | _background = colour; |
bikeNomad | 0:2c5bba968d7c | 57 | } |