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