aitendo T18003T01-V2,TFT1.8,SPI,FRDM-KL25Z

Dependents:   FRDM_SPI18TFT_demo

Fork of ST7735_TFT by Jonne Valola

Committer:
king33jp
Date:
Thu Mar 19 13:34:50 2015 +0000
Revision:
2:047ca9682450
Parent:
0:246f2fb5be59
aitendo 1.8"TFT,SPI,ST7735B

Who changed what in which revision?

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