Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RA8875 by
TextDisplay.cpp@0:de9d1462a835, 2012-09-10 (annotated)
- Committer:
- dreschpe
- Date:
- Mon Sep 10 19:23:26 2012 +0000
- Revision:
- 0:de9d1462a835
- Child:
- 19:3f82c1161fd2
[mbed] converted /TFT/SPI_TFT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:de9d1462a835 | 1 | /* mbed TextDisplay Display Library Base Class |
dreschpe | 0:de9d1462a835 | 2 | * Copyright (c) 2007-2009 sford |
dreschpe | 0:de9d1462a835 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
dreschpe | 0:de9d1462a835 | 4 | */ |
dreschpe | 0:de9d1462a835 | 5 | |
dreschpe | 0:de9d1462a835 | 6 | #include "TextDisplay.h" |
dreschpe | 0:de9d1462a835 | 7 | |
dreschpe | 0:de9d1462a835 | 8 | TextDisplay::TextDisplay(const char *name) : Stream(name){ |
dreschpe | 0:de9d1462a835 | 9 | _row = 0; |
dreschpe | 0:de9d1462a835 | 10 | _column = 0; |
dreschpe | 0:de9d1462a835 | 11 | if (name == NULL) { |
dreschpe | 0:de9d1462a835 | 12 | _path = NULL; |
dreschpe | 0:de9d1462a835 | 13 | } else { |
dreschpe | 0:de9d1462a835 | 14 | _path = new char[strlen(name) + 2]; |
dreschpe | 0:de9d1462a835 | 15 | sprintf(_path, "/%s", name); |
dreschpe | 0:de9d1462a835 | 16 | } |
dreschpe | 0:de9d1462a835 | 17 | } |
dreschpe | 0:de9d1462a835 | 18 | |
dreschpe | 0:de9d1462a835 | 19 | int TextDisplay::_putc(int value) { |
dreschpe | 0:de9d1462a835 | 20 | if(value == '\n') { |
dreschpe | 0:de9d1462a835 | 21 | _column = 0; |
dreschpe | 0:de9d1462a835 | 22 | _row++; |
dreschpe | 0:de9d1462a835 | 23 | if(_row >= rows()) { |
dreschpe | 0:de9d1462a835 | 24 | _row = 0; |
dreschpe | 0:de9d1462a835 | 25 | } |
dreschpe | 0:de9d1462a835 | 26 | } else { |
dreschpe | 0:de9d1462a835 | 27 | character(_column, _row, value); |
dreschpe | 0:de9d1462a835 | 28 | _column++; |
dreschpe | 0:de9d1462a835 | 29 | if(_column >= columns()) { |
dreschpe | 0:de9d1462a835 | 30 | _column = 0; |
dreschpe | 0:de9d1462a835 | 31 | _row++; |
dreschpe | 0:de9d1462a835 | 32 | if(_row >= rows()) { |
dreschpe | 0:de9d1462a835 | 33 | _row = 0; |
dreschpe | 0:de9d1462a835 | 34 | } |
dreschpe | 0:de9d1462a835 | 35 | } |
dreschpe | 0:de9d1462a835 | 36 | } |
dreschpe | 0:de9d1462a835 | 37 | return value; |
dreschpe | 0:de9d1462a835 | 38 | } |
dreschpe | 0:de9d1462a835 | 39 | |
dreschpe | 0:de9d1462a835 | 40 | // crude cls implementation, should generally be overwritten in derived class |
dreschpe | 0:de9d1462a835 | 41 | void TextDisplay::cls() { |
dreschpe | 0:de9d1462a835 | 42 | locate(0, 0); |
dreschpe | 0:de9d1462a835 | 43 | for(int i=0; i<columns()*rows(); i++) { |
dreschpe | 0:de9d1462a835 | 44 | putc(' '); |
dreschpe | 0:de9d1462a835 | 45 | } |
dreschpe | 0:de9d1462a835 | 46 | } |
dreschpe | 0:de9d1462a835 | 47 | |
dreschpe | 0:de9d1462a835 | 48 | void TextDisplay::locate(int column, int row) { |
dreschpe | 0:de9d1462a835 | 49 | _column = column; |
dreschpe | 0:de9d1462a835 | 50 | _row = row; |
dreschpe | 0:de9d1462a835 | 51 | } |
dreschpe | 0:de9d1462a835 | 52 | |
dreschpe | 0:de9d1462a835 | 53 | int TextDisplay::_getc() { |
dreschpe | 0:de9d1462a835 | 54 | return -1; |
dreschpe | 0:de9d1462a835 | 55 | } |
dreschpe | 0:de9d1462a835 | 56 | |
dreschpe | 0:de9d1462a835 | 57 | void TextDisplay::foreground(uint16_t colour) { |
dreschpe | 0:de9d1462a835 | 58 | _foreground = colour; |
dreschpe | 0:de9d1462a835 | 59 | } |
dreschpe | 0:de9d1462a835 | 60 | |
dreschpe | 0:de9d1462a835 | 61 | void TextDisplay::background(uint16_t colour) { |
dreschpe | 0:de9d1462a835 | 62 | _background = colour; |
dreschpe | 0:de9d1462a835 | 63 | } |
dreschpe | 0:de9d1462a835 | 64 | |
dreschpe | 0:de9d1462a835 | 65 | bool TextDisplay::claim (FILE *stream) { |
dreschpe | 0:de9d1462a835 | 66 | if ( _path == NULL) { |
dreschpe | 0:de9d1462a835 | 67 | fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n"); |
dreschpe | 0:de9d1462a835 | 68 | return false; |
dreschpe | 0:de9d1462a835 | 69 | } |
dreschpe | 0:de9d1462a835 | 70 | if (freopen(_path, "w", stream) == NULL) { |
dreschpe | 0:de9d1462a835 | 71 | // Failed, should not happen |
dreschpe | 0:de9d1462a835 | 72 | return false; |
dreschpe | 0:de9d1462a835 | 73 | } |
dreschpe | 0:de9d1462a835 | 74 | // make sure we use line buffering |
dreschpe | 0:de9d1462a835 | 75 | setvbuf(stdout, NULL, _IOLBF, columns()); |
dreschpe | 0:de9d1462a835 | 76 | return true; |
dreschpe | 0:de9d1462a835 | 77 | } |