.

Committer:
Geremia
Date:
Thu Feb 12 22:22:47 2015 +0000
Revision:
0:75ec1b3cde17
Initial tests, LCD par and spi ok

Who changed what in which revision?

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