Dependencies:   mbed

Committer:
simon
Date:
Mon Nov 30 09:32:28 2009 +0000
Revision:
0:42626fc1bbc5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:42626fc1bbc5 1 /* mbed TextDisplay Display Library Base Class
simon 0:42626fc1bbc5 2 * Copyright (c) 2007-2009 sford
simon 0:42626fc1bbc5 3 * Released under the MIT License: http://mbed.org/license/mit
simon 0:42626fc1bbc5 4 */
simon 0:42626fc1bbc5 5
simon 0:42626fc1bbc5 6 #include "TextDisplay.h"
simon 0:42626fc1bbc5 7
simon 0:42626fc1bbc5 8 TextDisplay::TextDisplay(const char *name) : Stream(name) {
simon 0:42626fc1bbc5 9 _row = 0;
simon 0:42626fc1bbc5 10 _column = 0;
simon 0:42626fc1bbc5 11 }
simon 0:42626fc1bbc5 12
simon 0:42626fc1bbc5 13 int TextDisplay::_putc(int value) {
simon 0:42626fc1bbc5 14 if(value == '\n') {
simon 0:42626fc1bbc5 15 _column = 0;
simon 0:42626fc1bbc5 16 _row++;
simon 0:42626fc1bbc5 17 if(_row >= rows()) {
simon 0:42626fc1bbc5 18 _row = 0;
simon 0:42626fc1bbc5 19 }
simon 0:42626fc1bbc5 20 } else {
simon 0:42626fc1bbc5 21 character(_column, _row, value);
simon 0:42626fc1bbc5 22 _column++;
simon 0:42626fc1bbc5 23 if(_column >= columns()) {
simon 0:42626fc1bbc5 24 _column = 0;
simon 0:42626fc1bbc5 25 _row++;
simon 0:42626fc1bbc5 26 if(_row >= rows()) {
simon 0:42626fc1bbc5 27 _row = 0;
simon 0:42626fc1bbc5 28 }
simon 0:42626fc1bbc5 29 }
simon 0:42626fc1bbc5 30 }
simon 0:42626fc1bbc5 31 return value;
simon 0:42626fc1bbc5 32 }
simon 0:42626fc1bbc5 33
simon 0:42626fc1bbc5 34 // crude cls implementation, should generally be overwritten in derived class
simon 0:42626fc1bbc5 35 void TextDisplay::cls() {
simon 0:42626fc1bbc5 36 locate(0, 0);
simon 0:42626fc1bbc5 37 for(int i=0; i<columns()*rows(); i++) {
simon 0:42626fc1bbc5 38 putc(' ');
simon 0:42626fc1bbc5 39 }
simon 0:42626fc1bbc5 40 }
simon 0:42626fc1bbc5 41
simon 0:42626fc1bbc5 42 void TextDisplay::locate(int column, int row) {
simon 0:42626fc1bbc5 43 _column = column;
simon 0:42626fc1bbc5 44 _row = row;
simon 0:42626fc1bbc5 45 }
simon 0:42626fc1bbc5 46
simon 0:42626fc1bbc5 47 int TextDisplay::_getc() {
simon 0:42626fc1bbc5 48 return -1;
simon 0:42626fc1bbc5 49 }
simon 0:42626fc1bbc5 50
simon 0:42626fc1bbc5 51 void TextDisplay::foreground(int colour) {
simon 0:42626fc1bbc5 52 _foreground = colour;
simon 0:42626fc1bbc5 53 }
simon 0:42626fc1bbc5 54
simon 0:42626fc1bbc5 55 void TextDisplay::background(int colour) {
simon 0:42626fc1bbc5 56 _background = colour;
simon 0:42626fc1bbc5 57 }