KSM edits to RA8875

Dependents:   Liz_Test_Code

Committer:
WiredHome
Date:
Sun Jan 12 17:40:32 2014 +0000
Revision:
19:3f82c1161fd2
Parent:
0:de9d1462a835
Child:
29:422616aa04bd
Initial commit - mostly working (not Triangles, Externals Fonts). Not ready for other users.

Who changed what in which revision?

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