temp poti

Dependents:   2016-01-28_TINF_Temperatur_einlesen

Committer:
tauchi88
Date:
Thu Jan 28 19:53:13 2016 +0000
Revision:
0:4a09a5e0d6d8
temp

Who changed what in which revision?

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