Library for TFT via SPI

Dependents:   mbed_projekt_tetris Ejemplo_TFT

Committer:
2018US_HarisSoljic
Date:
Mon Jun 18 20:01:55 2018 +0000
Revision:
0:b8956708b92f
revi?n;

Who changed what in which revision?

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