Erik -
/
Mini_DK_clk
Simple clock program for LPC1768 Mini-DK
Mini_DK/SPI_TFT/TextDisplay.cpp@0:ab0aec01b38e, 2012-12-30 (annotated)
- Committer:
- Sissors
- Date:
- Sun Dec 30 21:31:56 2012 +0000
- Revision:
- 0:ab0aec01b38e
v0.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:ab0aec01b38e | 1 | /* mbed TextDisplay Display Library Base Class |
Sissors | 0:ab0aec01b38e | 2 | * Copyright (c) 2007-2009 sford |
Sissors | 0:ab0aec01b38e | 3 | * Released under the MIT License: http://mbed.org/license/mit |
Sissors | 0:ab0aec01b38e | 4 | */ |
Sissors | 0:ab0aec01b38e | 5 | |
Sissors | 0:ab0aec01b38e | 6 | #include "TextDisplay.h" |
Sissors | 0:ab0aec01b38e | 7 | |
Sissors | 0:ab0aec01b38e | 8 | TextDisplay::TextDisplay(const char *name) : Stream(){ |
Sissors | 0:ab0aec01b38e | 9 | _row = 0; |
Sissors | 0:ab0aec01b38e | 10 | _column = 0; |
Sissors | 0:ab0aec01b38e | 11 | if (name == NULL) { |
Sissors | 0:ab0aec01b38e | 12 | _path = NULL; |
Sissors | 0:ab0aec01b38e | 13 | } else { |
Sissors | 0:ab0aec01b38e | 14 | _path = new char[strlen(name) + 2]; |
Sissors | 0:ab0aec01b38e | 15 | sprintf(_path, "/%s", name); |
Sissors | 0:ab0aec01b38e | 16 | } |
Sissors | 0:ab0aec01b38e | 17 | } |
Sissors | 0:ab0aec01b38e | 18 | |
Sissors | 0:ab0aec01b38e | 19 | int TextDisplay::_putc(int value) { |
Sissors | 0:ab0aec01b38e | 20 | if(value == '\n') { |
Sissors | 0:ab0aec01b38e | 21 | _column = 0; |
Sissors | 0:ab0aec01b38e | 22 | _row++; |
Sissors | 0:ab0aec01b38e | 23 | if(_row >= rows()) { |
Sissors | 0:ab0aec01b38e | 24 | _row = 0; |
Sissors | 0:ab0aec01b38e | 25 | } |
Sissors | 0:ab0aec01b38e | 26 | } else { |
Sissors | 0:ab0aec01b38e | 27 | character(_column, _row, value); |
Sissors | 0:ab0aec01b38e | 28 | _column++; |
Sissors | 0:ab0aec01b38e | 29 | if(_column >= columns()) { |
Sissors | 0:ab0aec01b38e | 30 | _column = 0; |
Sissors | 0:ab0aec01b38e | 31 | _row++; |
Sissors | 0:ab0aec01b38e | 32 | if(_row >= rows()) { |
Sissors | 0:ab0aec01b38e | 33 | _row = 0; |
Sissors | 0:ab0aec01b38e | 34 | } |
Sissors | 0:ab0aec01b38e | 35 | } |
Sissors | 0:ab0aec01b38e | 36 | } |
Sissors | 0:ab0aec01b38e | 37 | return value; |
Sissors | 0:ab0aec01b38e | 38 | } |
Sissors | 0:ab0aec01b38e | 39 | |
Sissors | 0:ab0aec01b38e | 40 | // crude cls implementation, should generally be overwritten in derived class |
Sissors | 0:ab0aec01b38e | 41 | void TextDisplay::cls() { |
Sissors | 0:ab0aec01b38e | 42 | locate(0, 0); |
Sissors | 0:ab0aec01b38e | 43 | for(int i=0; i<columns()*rows(); i++) { |
Sissors | 0:ab0aec01b38e | 44 | putc(' '); |
Sissors | 0:ab0aec01b38e | 45 | } |
Sissors | 0:ab0aec01b38e | 46 | } |
Sissors | 0:ab0aec01b38e | 47 | |
Sissors | 0:ab0aec01b38e | 48 | void TextDisplay::locate(int column, int row) { |
Sissors | 0:ab0aec01b38e | 49 | _column = column; |
Sissors | 0:ab0aec01b38e | 50 | _row = row; |
Sissors | 0:ab0aec01b38e | 51 | } |
Sissors | 0:ab0aec01b38e | 52 | |
Sissors | 0:ab0aec01b38e | 53 | int TextDisplay::_getc() { |
Sissors | 0:ab0aec01b38e | 54 | return -1; |
Sissors | 0:ab0aec01b38e | 55 | } |
Sissors | 0:ab0aec01b38e | 56 | |
Sissors | 0:ab0aec01b38e | 57 | void TextDisplay::foreground(uint16_t colour) { |
Sissors | 0:ab0aec01b38e | 58 | _foreground = colour; |
Sissors | 0:ab0aec01b38e | 59 | } |
Sissors | 0:ab0aec01b38e | 60 | |
Sissors | 0:ab0aec01b38e | 61 | void TextDisplay::background(uint16_t colour) { |
Sissors | 0:ab0aec01b38e | 62 | _background = colour; |
Sissors | 0:ab0aec01b38e | 63 | } |
Sissors | 0:ab0aec01b38e | 64 | |
Sissors | 0:ab0aec01b38e | 65 | bool TextDisplay::claim (FILE *stream) { |
Sissors | 0:ab0aec01b38e | 66 | if ( _path == NULL) { |
Sissors | 0:ab0aec01b38e | 67 | fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n"); |
Sissors | 0:ab0aec01b38e | 68 | return false; |
Sissors | 0:ab0aec01b38e | 69 | } |
Sissors | 0:ab0aec01b38e | 70 | if (freopen(_path, "w", stream) == NULL) { |
Sissors | 0:ab0aec01b38e | 71 | // Failed, should not happen |
Sissors | 0:ab0aec01b38e | 72 | return false; |
Sissors | 0:ab0aec01b38e | 73 | } |
Sissors | 0:ab0aec01b38e | 74 | // make sure we use line buffering |
Sissors | 0:ab0aec01b38e | 75 | setvbuf(stdout, NULL, _IOLBF, columns()); |
Sissors | 0:ab0aec01b38e | 76 | return true; |
Sissors | 0:ab0aec01b38e | 77 | } |