This is the David Smart RA8875 Library with mods for working with FRDM-K64F
TextDisplay.cpp@199:08eb9e55567b, 2020-03-10 (annotated)
- Committer:
- lamell
- Date:
- Tue Mar 10 21:28:18 2020 -0400
- Revision:
- 199:08eb9e55567b
- Parent:
- 182:8832d03a2a29
Subtle changes in the way the library behaves.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 167:8aa3fb2a5a31 | 1 | // mbed TextDisplay Display Library Base Class |
WiredHome | 167:8aa3fb2a5a31 | 2 | // Copyright © 2007-2009 sford |
WiredHome | 167:8aa3fb2a5a31 | 3 | // Released under the MIT License: http://mbed.org/license/mit |
WiredHome | 19:3f82c1161fd2 | 4 | |
dreschpe | 0:de9d1462a835 | 5 | #include "TextDisplay.h" |
dreschpe | 0:de9d1462a835 | 6 | |
WiredHome | 75:ca78388cfd77 | 7 | //#define DEBUG "Text" |
WiredHome | 29:422616aa04bd | 8 | // ... |
WiredHome | 29:422616aa04bd | 9 | // INFO("Stuff to show %d", var); // new-line is automatically appended |
WiredHome | 29:422616aa04bd | 10 | // |
WiredHome | 29:422616aa04bd | 11 | #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) |
WiredHome | 29:422616aa04bd | 12 | #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 13 | #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 14 | #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 15 | #else |
WiredHome | 29:422616aa04bd | 16 | #define INFO(x, ...) |
WiredHome | 29:422616aa04bd | 17 | #define WARN(x, ...) |
WiredHome | 29:422616aa04bd | 18 | #define ERR(x, ...) |
WiredHome | 29:422616aa04bd | 19 | #endif |
WiredHome | 29:422616aa04bd | 20 | |
WiredHome | 19:3f82c1161fd2 | 21 | TextDisplay::TextDisplay(const char *name) : Stream(name) |
WiredHome | 19:3f82c1161fd2 | 22 | { |
dreschpe | 0:de9d1462a835 | 23 | _row = 0; |
dreschpe | 0:de9d1462a835 | 24 | _column = 0; |
WiredHome | 182:8832d03a2a29 | 25 | _foreground = 0; |
WiredHome | 182:8832d03a2a29 | 26 | _background = 0; |
dreschpe | 0:de9d1462a835 | 27 | if (name == NULL) { |
dreschpe | 0:de9d1462a835 | 28 | _path = NULL; |
dreschpe | 0:de9d1462a835 | 29 | } else { |
WiredHome | 141:2ec78a50dc98 | 30 | int len = strlen(name) + 2; |
WiredHome | 141:2ec78a50dc98 | 31 | _path = new char[len]; |
WiredHome | 141:2ec78a50dc98 | 32 | snprintf(_path, len, "/%s", name); |
dreschpe | 0:de9d1462a835 | 33 | } |
dreschpe | 0:de9d1462a835 | 34 | } |
WiredHome | 19:3f82c1161fd2 | 35 | |
WiredHome | 182:8832d03a2a29 | 36 | TextDisplay::~TextDisplay() |
WiredHome | 182:8832d03a2a29 | 37 | { |
WiredHome | 182:8832d03a2a29 | 38 | delete [] _path; |
WiredHome | 182:8832d03a2a29 | 39 | } |
WiredHome | 103:7e0464ca6c5c | 40 | |
WiredHome | 19:3f82c1161fd2 | 41 | int TextDisplay::_putc(int value) |
WiredHome | 19:3f82c1161fd2 | 42 | { |
WiredHome | 29:422616aa04bd | 43 | INFO("_putc(%d)", value); |
dreschpe | 0:de9d1462a835 | 44 | if(value == '\n') { |
dreschpe | 0:de9d1462a835 | 45 | _column = 0; |
dreschpe | 0:de9d1462a835 | 46 | _row++; |
WiredHome | 47:d96a09269f91 | 47 | if(_row >= rows()) { |
dreschpe | 0:de9d1462a835 | 48 | _row = 0; |
dreschpe | 0:de9d1462a835 | 49 | } |
dreschpe | 0:de9d1462a835 | 50 | } else { |
dreschpe | 0:de9d1462a835 | 51 | character(_column, _row, value); |
dreschpe | 0:de9d1462a835 | 52 | _column++; |
dreschpe | 0:de9d1462a835 | 53 | if(_column >= columns()) { |
dreschpe | 0:de9d1462a835 | 54 | _column = 0; |
dreschpe | 0:de9d1462a835 | 55 | _row++; |
WiredHome | 47:d96a09269f91 | 56 | if(_row >= rows()) { |
dreschpe | 0:de9d1462a835 | 57 | _row = 0; |
dreschpe | 0:de9d1462a835 | 58 | } |
dreschpe | 0:de9d1462a835 | 59 | } |
dreschpe | 0:de9d1462a835 | 60 | } |
dreschpe | 0:de9d1462a835 | 61 | return value; |
dreschpe | 0:de9d1462a835 | 62 | } |
dreschpe | 0:de9d1462a835 | 63 | |
dreschpe | 0:de9d1462a835 | 64 | // crude cls implementation, should generally be overwritten in derived class |
WiredHome | 61:8f3153bf0baa | 65 | RetCode_t TextDisplay::cls(uint16_t layers) |
WiredHome | 19:3f82c1161fd2 | 66 | { |
WiredHome | 29:422616aa04bd | 67 | INFO("cls()"); |
dreschpe | 0:de9d1462a835 | 68 | locate(0, 0); |
dreschpe | 0:de9d1462a835 | 69 | for(int i=0; i<columns()*rows(); i++) { |
dreschpe | 0:de9d1462a835 | 70 | putc(' '); |
dreschpe | 0:de9d1462a835 | 71 | } |
WiredHome | 19:3f82c1161fd2 | 72 | return noerror; |
dreschpe | 0:de9d1462a835 | 73 | } |
dreschpe | 0:de9d1462a835 | 74 | |
WiredHome | 37:f19b7e7449dc | 75 | RetCode_t TextDisplay::locate(textloc_t column, textloc_t row) |
WiredHome | 19:3f82c1161fd2 | 76 | { |
WiredHome | 29:422616aa04bd | 77 | INFO("locate(%d,%d)", column, row); |
dreschpe | 0:de9d1462a835 | 78 | _column = column; |
dreschpe | 0:de9d1462a835 | 79 | _row = row; |
WiredHome | 19:3f82c1161fd2 | 80 | return noerror; |
dreschpe | 0:de9d1462a835 | 81 | } |
dreschpe | 0:de9d1462a835 | 82 | |
WiredHome | 19:3f82c1161fd2 | 83 | int TextDisplay::_getc() |
WiredHome | 19:3f82c1161fd2 | 84 | { |
dreschpe | 0:de9d1462a835 | 85 | return -1; |
dreschpe | 0:de9d1462a835 | 86 | } |
WiredHome | 19:3f82c1161fd2 | 87 | |
WiredHome | 33:b6b710758ab3 | 88 | RetCode_t TextDisplay::foreground(uint16_t color) |
WiredHome | 19:3f82c1161fd2 | 89 | { |
WiredHome | 37:f19b7e7449dc | 90 | //INFO("foreground(%4X)", color); |
WiredHome | 33:b6b710758ab3 | 91 | _foreground = color; |
WiredHome | 19:3f82c1161fd2 | 92 | return noerror; |
dreschpe | 0:de9d1462a835 | 93 | } |
dreschpe | 0:de9d1462a835 | 94 | |
WiredHome | 33:b6b710758ab3 | 95 | RetCode_t TextDisplay::background(uint16_t color) |
WiredHome | 19:3f82c1161fd2 | 96 | { |
WiredHome | 37:f19b7e7449dc | 97 | //INFO("background(%4X)", color); |
WiredHome | 33:b6b710758ab3 | 98 | _background = color; |
WiredHome | 19:3f82c1161fd2 | 99 | return noerror; |
dreschpe | 0:de9d1462a835 | 100 | } |
dreschpe | 0:de9d1462a835 | 101 | |
WiredHome | 29:422616aa04bd | 102 | bool TextDisplay::claim(FILE *stream) |
WiredHome | 19:3f82c1161fd2 | 103 | { |
dreschpe | 0:de9d1462a835 | 104 | if ( _path == NULL) { |
WiredHome | 19:3f82c1161fd2 | 105 | fprintf(stderr, "claim requires a name to be given in the instantiator of the TextDisplay instance!\r\n"); |
dreschpe | 0:de9d1462a835 | 106 | return false; |
dreschpe | 0:de9d1462a835 | 107 | } |
dreschpe | 0:de9d1462a835 | 108 | if (freopen(_path, "w", stream) == NULL) { |
WiredHome | 29:422616aa04bd | 109 | return false; // Failed, should not happen |
dreschpe | 0:de9d1462a835 | 110 | } |
dreschpe | 0:de9d1462a835 | 111 | // make sure we use line buffering |
dreschpe | 0:de9d1462a835 | 112 | setvbuf(stdout, NULL, _IOLBF, columns()); |
dreschpe | 0:de9d1462a835 | 113 | return true; |
WiredHome | 19:3f82c1161fd2 | 114 | } |
WiredHome | 33:b6b710758ab3 | 115 |