TINF_MittelwerteUeberwachung

Dependencies:   mbed

Committer:
martwerl
Date:
Thu Nov 15 18:24:11 2018 +0000
Revision:
0:fb8791842ef8
TINF_MittelwerteUeberwachung

Who changed what in which revision?

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