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