AnalogInputPoti12_5a_Spannung_Strom

Committer:
martwerl
Date:
Thu Nov 15 17:25:27 2018 +0000
Revision:
0:54a8c9ae5155
AnalogInputPoti12_5a_Spannung_Strom

Who changed what in which revision?

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