Chinese module HY-1.8 SPI TFT lcd Display library.
Dependents: KL25Z_DCF77_HY-1_8LCD
Fork of HY-1_8TFT_ST7735 by
TextDisplay.cpp@2:26149011665e, 2015-10-11 (annotated)
- Committer:
- star297
- Date:
- Sun Oct 11 21:30:26 2015 +0000
- Revision:
- 2:26149011665e
- Parent:
- 0:35a1964228b4
updated BurstSPI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
star297 | 0:35a1964228b4 | 1 | // ST7735 8 Bit SPI Library |
star297 | 0:35a1964228b4 | 2 | |
star297 | 0:35a1964228b4 | 3 | #include "TextDisplay.h" |
star297 | 0:35a1964228b4 | 4 | |
star297 | 0:35a1964228b4 | 5 | TextDisplay::TextDisplay(const char *name) : Stream(name){ |
star297 | 0:35a1964228b4 | 6 | _row = 0; |
star297 | 0:35a1964228b4 | 7 | _column = 0; |
star297 | 0:35a1964228b4 | 8 | if (name == NULL) { |
star297 | 0:35a1964228b4 | 9 | _path = NULL; |
star297 | 0:35a1964228b4 | 10 | } else { |
star297 | 0:35a1964228b4 | 11 | _path = new char[strlen(name) + 2]; |
star297 | 0:35a1964228b4 | 12 | sprintf(_path, "/%s", name); |
star297 | 0:35a1964228b4 | 13 | } |
star297 | 0:35a1964228b4 | 14 | } |
star297 | 0:35a1964228b4 | 15 | |
star297 | 0:35a1964228b4 | 16 | int TextDisplay::_putc(int value) { |
star297 | 0:35a1964228b4 | 17 | if(value == '\n') { |
star297 | 0:35a1964228b4 | 18 | _column = 0; |
star297 | 0:35a1964228b4 | 19 | _row++; |
star297 | 0:35a1964228b4 | 20 | if(_row >= rows()) { |
star297 | 0:35a1964228b4 | 21 | _row = 0; |
star297 | 0:35a1964228b4 | 22 | } |
star297 | 0:35a1964228b4 | 23 | } else { |
star297 | 0:35a1964228b4 | 24 | character(_column, _row, value); |
star297 | 0:35a1964228b4 | 25 | _column++; |
star297 | 0:35a1964228b4 | 26 | if(_column >= columns()) { |
star297 | 0:35a1964228b4 | 27 | _column = 0; |
star297 | 0:35a1964228b4 | 28 | _row++; |
star297 | 0:35a1964228b4 | 29 | if(_row >= rows()) { |
star297 | 0:35a1964228b4 | 30 | _row = 0; |
star297 | 0:35a1964228b4 | 31 | } |
star297 | 0:35a1964228b4 | 32 | } |
star297 | 0:35a1964228b4 | 33 | } |
star297 | 0:35a1964228b4 | 34 | return value; |
star297 | 0:35a1964228b4 | 35 | } |
star297 | 0:35a1964228b4 | 36 | void TextDisplay::cls() { |
star297 | 0:35a1964228b4 | 37 | locate(0, 0); |
star297 | 0:35a1964228b4 | 38 | for(int i=0; i<columns()*rows(); i++) { |
star297 | 0:35a1964228b4 | 39 | putc(' '); |
star297 | 0:35a1964228b4 | 40 | } |
star297 | 0:35a1964228b4 | 41 | } |
star297 | 0:35a1964228b4 | 42 | void TextDisplay::locate(int column, int row) { |
star297 | 0:35a1964228b4 | 43 | _column = column; |
star297 | 0:35a1964228b4 | 44 | _row = row; |
star297 | 0:35a1964228b4 | 45 | } |
star297 | 0:35a1964228b4 | 46 | int TextDisplay::_getc() { |
star297 | 0:35a1964228b4 | 47 | return -1; |
star297 | 0:35a1964228b4 | 48 | } |
star297 | 0:35a1964228b4 | 49 | void TextDisplay::foreground(uint16_t colour) { |
star297 | 0:35a1964228b4 | 50 | _foreground = colour; |
star297 | 0:35a1964228b4 | 51 | } |
star297 | 0:35a1964228b4 | 52 | void TextDisplay::background(uint16_t colour) { |
star297 | 0:35a1964228b4 | 53 | _background = colour; |
star297 | 0:35a1964228b4 | 54 | } |
star297 | 0:35a1964228b4 | 55 | bool TextDisplay::claim (FILE *stream) { |
star297 | 0:35a1964228b4 | 56 | if ( _path == NULL) { |
star297 | 0:35a1964228b4 | 57 | fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n"); |
star297 | 0:35a1964228b4 | 58 | return false; |
star297 | 0:35a1964228b4 | 59 | } |
star297 | 0:35a1964228b4 | 60 | if (freopen(_path, "w", stream) == NULL) { |
star297 | 0:35a1964228b4 | 61 | // Failed, should not happen |
star297 | 0:35a1964228b4 | 62 | return false; |
star297 | 0:35a1964228b4 | 63 | } |
star297 | 0:35a1964228b4 | 64 | // make sure we use line buffering |
star297 | 0:35a1964228b4 | 65 | setvbuf(stdout, NULL, _IOLBF, columns()); |
star297 | 0:35a1964228b4 | 66 | return true; |
star297 | 0:35a1964228b4 | 67 | } |