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