Lib for the new LCD Display with ILI9341 controller

Committer:
dreschpe
Date:
Wed Jun 12 22:54:38 2013 +0000
Revision:
0:da1bf437cbc1
Test Version,

Who changed what in which revision?

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