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