fixed library.

Dependents:   Sharp_Memory_LCD_Test hello_GT20L16J1Y_FONT_mlcd

Fork of sharp_mlcd by Masato YAMANISHI

Committer:
ban4jp
Date:
Sun Sep 21 08:05:33 2014 +0000
Revision:
3:d2aed1df064c
Parent:
0:c99dda90f834
Fix multi connection spi device issue.

Who changed what in which revision?

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