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