Displays a large title and some small text with a blue rectangle Constantly refreshes 3 variable values on the screen. NO TOUCH SUPPORT AS OF YET

Dependencies:   mbed

Committer:
EmbeddedSam
Date:
Sat Dec 05 23:41:01 2015 +0000
Revision:
0:38cf064697d7
First commit, working with displaying messages; no touch support as of yet

Who changed what in which revision?

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