Forked para SNOCC
Fork of RA8875 by
TextDisplay.cpp@46:1321832f11d8, 2014-03-13 (annotated)
- Committer:
- hexley
- Date:
- Thu Mar 13 17:24:45 2014 +0000
- Revision:
- 46:1321832f11d8
- Parent:
- 37:f19b7e7449dc
- Child:
- 47:d96a09269f91
Fixes for vertical line wrap.
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 | */ |
WiredHome | 19:3f82c1161fd2 | 5 | |
dreschpe | 0:de9d1462a835 | 6 | #include "TextDisplay.h" |
dreschpe | 0:de9d1462a835 | 7 | |
WiredHome | 29:422616aa04bd | 8 | #define DEBUG "Text" |
WiredHome | 29:422616aa04bd | 9 | // ... |
WiredHome | 29:422616aa04bd | 10 | // INFO("Stuff to show %d", var); // new-line is automatically appended |
WiredHome | 29:422616aa04bd | 11 | // |
WiredHome | 29:422616aa04bd | 12 | #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) |
WiredHome | 29:422616aa04bd | 13 | #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 14 | #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 15 | #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 16 | #else |
WiredHome | 29:422616aa04bd | 17 | #define INFO(x, ...) |
WiredHome | 29:422616aa04bd | 18 | #define WARN(x, ...) |
WiredHome | 29:422616aa04bd | 19 | #define ERR(x, ...) |
WiredHome | 29:422616aa04bd | 20 | #endif |
WiredHome | 29:422616aa04bd | 21 | |
WiredHome | 19:3f82c1161fd2 | 22 | TextDisplay::TextDisplay(const char *name) : Stream(name) |
WiredHome | 19:3f82c1161fd2 | 23 | { |
dreschpe | 0:de9d1462a835 | 24 | _row = 0; |
dreschpe | 0:de9d1462a835 | 25 | _column = 0; |
dreschpe | 0:de9d1462a835 | 26 | if (name == NULL) { |
dreschpe | 0:de9d1462a835 | 27 | _path = NULL; |
dreschpe | 0:de9d1462a835 | 28 | } else { |
dreschpe | 0:de9d1462a835 | 29 | _path = new char[strlen(name) + 2]; |
dreschpe | 0:de9d1462a835 | 30 | sprintf(_path, "/%s", name); |
dreschpe | 0:de9d1462a835 | 31 | } |
dreschpe | 0:de9d1462a835 | 32 | } |
WiredHome | 19:3f82c1161fd2 | 33 | |
WiredHome | 19:3f82c1161fd2 | 34 | int TextDisplay::_putc(int value) |
WiredHome | 19:3f82c1161fd2 | 35 | { |
WiredHome | 29:422616aa04bd | 36 | INFO("_putc(%d)", value); |
dreschpe | 0:de9d1462a835 | 37 | if(value == '\n') { |
dreschpe | 0:de9d1462a835 | 38 | _column = 0; |
dreschpe | 0:de9d1462a835 | 39 | _row++; |
hexley | 46:1321832f11d8 | 40 | if(_row >= rows() ) { // #### hb. Fix missing 18th row issue. |
dreschpe | 0:de9d1462a835 | 41 | _row = 0; |
dreschpe | 0:de9d1462a835 | 42 | } |
dreschpe | 0:de9d1462a835 | 43 | } else { |
dreschpe | 0:de9d1462a835 | 44 | character(_column, _row, value); |
dreschpe | 0:de9d1462a835 | 45 | _column++; |
dreschpe | 0:de9d1462a835 | 46 | if(_column >= columns()) { |
dreschpe | 0:de9d1462a835 | 47 | _column = 0; |
dreschpe | 0:de9d1462a835 | 48 | _row++; |
hexley | 46:1321832f11d8 | 49 | if(_row >= rows() ) { // #### hb. Fix missing 18th row issue. |
dreschpe | 0:de9d1462a835 | 50 | _row = 0; |
dreschpe | 0:de9d1462a835 | 51 | } |
dreschpe | 0:de9d1462a835 | 52 | } |
dreschpe | 0:de9d1462a835 | 53 | } |
dreschpe | 0:de9d1462a835 | 54 | return value; |
dreschpe | 0:de9d1462a835 | 55 | } |
dreschpe | 0:de9d1462a835 | 56 | |
dreschpe | 0:de9d1462a835 | 57 | // crude cls implementation, should generally be overwritten in derived class |
WiredHome | 19:3f82c1161fd2 | 58 | RetCode_t TextDisplay::cls() |
WiredHome | 19:3f82c1161fd2 | 59 | { |
WiredHome | 29:422616aa04bd | 60 | INFO("cls()"); |
dreschpe | 0:de9d1462a835 | 61 | locate(0, 0); |
dreschpe | 0:de9d1462a835 | 62 | for(int i=0; i<columns()*rows(); i++) { |
dreschpe | 0:de9d1462a835 | 63 | putc(' '); |
dreschpe | 0:de9d1462a835 | 64 | } |
WiredHome | 19:3f82c1161fd2 | 65 | return noerror; |
dreschpe | 0:de9d1462a835 | 66 | } |
dreschpe | 0:de9d1462a835 | 67 | |
WiredHome | 37:f19b7e7449dc | 68 | RetCode_t TextDisplay::locate(textloc_t column, textloc_t row) |
WiredHome | 19:3f82c1161fd2 | 69 | { |
WiredHome | 29:422616aa04bd | 70 | INFO("locate(%d,%d)", column, row); |
dreschpe | 0:de9d1462a835 | 71 | _column = column; |
dreschpe | 0:de9d1462a835 | 72 | _row = row; |
WiredHome | 19:3f82c1161fd2 | 73 | return noerror; |
dreschpe | 0:de9d1462a835 | 74 | } |
dreschpe | 0:de9d1462a835 | 75 | |
WiredHome | 19:3f82c1161fd2 | 76 | int TextDisplay::_getc() |
WiredHome | 19:3f82c1161fd2 | 77 | { |
dreschpe | 0:de9d1462a835 | 78 | return -1; |
dreschpe | 0:de9d1462a835 | 79 | } |
WiredHome | 19:3f82c1161fd2 | 80 | |
WiredHome | 33:b6b710758ab3 | 81 | RetCode_t TextDisplay::foreground(uint16_t color) |
WiredHome | 19:3f82c1161fd2 | 82 | { |
WiredHome | 37:f19b7e7449dc | 83 | //INFO("foreground(%4X)", color); |
WiredHome | 33:b6b710758ab3 | 84 | _foreground = color; |
WiredHome | 19:3f82c1161fd2 | 85 | return noerror; |
dreschpe | 0:de9d1462a835 | 86 | } |
dreschpe | 0:de9d1462a835 | 87 | |
WiredHome | 33:b6b710758ab3 | 88 | RetCode_t TextDisplay::background(uint16_t color) |
WiredHome | 19:3f82c1161fd2 | 89 | { |
WiredHome | 37:f19b7e7449dc | 90 | //INFO("background(%4X)", color); |
WiredHome | 33:b6b710758ab3 | 91 | _background = color; |
WiredHome | 19:3f82c1161fd2 | 92 | return noerror; |
dreschpe | 0:de9d1462a835 | 93 | } |
dreschpe | 0:de9d1462a835 | 94 | |
WiredHome | 29:422616aa04bd | 95 | bool TextDisplay::claim(FILE *stream) |
WiredHome | 19:3f82c1161fd2 | 96 | { |
dreschpe | 0:de9d1462a835 | 97 | if ( _path == NULL) { |
WiredHome | 19:3f82c1161fd2 | 98 | fprintf(stderr, "claim requires a name to be given in the instantiator of the TextDisplay instance!\r\n"); |
dreschpe | 0:de9d1462a835 | 99 | return false; |
dreschpe | 0:de9d1462a835 | 100 | } |
dreschpe | 0:de9d1462a835 | 101 | if (freopen(_path, "w", stream) == NULL) { |
WiredHome | 29:422616aa04bd | 102 | return false; // Failed, should not happen |
dreschpe | 0:de9d1462a835 | 103 | } |
dreschpe | 0:de9d1462a835 | 104 | // make sure we use line buffering |
dreschpe | 0:de9d1462a835 | 105 | setvbuf(stdout, NULL, _IOLBF, columns()); |
dreschpe | 0:de9d1462a835 | 106 | return true; |
WiredHome | 19:3f82c1161fd2 | 107 | } |
WiredHome | 33:b6b710758ab3 | 108 |