KSM edits to RA8875
Embed:
(wiki syntax)
Show/hide line numbers
TextDisplay.cpp
00001 // mbed TextDisplay Display Library Base Class 00002 // Copyright © 2007-2009 sford 00003 // Released under the MIT License: http://mbed.org/license/mit 00004 00005 #include "TextDisplay.h" 00006 00007 //#define DEBUG "Text" 00008 // ... 00009 // INFO("Stuff to show %d", var); // new-line is automatically appended 00010 // 00011 #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) 00012 #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); 00013 #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); 00014 #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); 00015 #else 00016 #define INFO(x, ...) 00017 #define WARN(x, ...) 00018 #define ERR(x, ...) 00019 #endif 00020 00021 TextDisplay::TextDisplay(const char *name) : Stream(name) 00022 { 00023 _row = 0; 00024 _column = 0; 00025 if (name == NULL) { 00026 _path = NULL; 00027 } else { 00028 int len = strlen(name) + 2; 00029 _path = new char[len]; 00030 snprintf(_path, len, "/%s", name); 00031 } 00032 } 00033 00034 //TextDisplay::~TextDisplay() 00035 //{ 00036 // delete [] _path; 00037 //} 00038 00039 int TextDisplay::_putc(int value) 00040 { 00041 INFO("_putc(%d)", value); 00042 if(value == '\n') { 00043 _column = 0; 00044 _row++; 00045 if(_row >= rows()) { 00046 _row = 0; 00047 } 00048 } else { 00049 character(_column, _row, value); 00050 _column++; 00051 if(_column >= columns()) { 00052 _column = 0; 00053 _row++; 00054 if(_row >= rows()) { 00055 _row = 0; 00056 } 00057 } 00058 } 00059 return value; 00060 } 00061 00062 // crude cls implementation, should generally be overwritten in derived class 00063 RetCode_t TextDisplay::cls(uint16_t layers) 00064 { 00065 INFO("cls()"); 00066 locate(0, 0); 00067 for(int i=0; i<columns()*rows(); i++) { 00068 putc(' '); 00069 } 00070 return noerror; 00071 } 00072 00073 RetCode_t TextDisplay::locate(textloc_t column, textloc_t row) 00074 { 00075 INFO("locate(%d,%d)", column, row); 00076 _column = column; 00077 _row = row; 00078 return noerror; 00079 } 00080 00081 int TextDisplay::_getc() 00082 { 00083 return -1; 00084 } 00085 00086 RetCode_t TextDisplay::foreground(uint16_t color) 00087 { 00088 //INFO("foreground(%4X)", color); 00089 _foreground = color; 00090 return noerror; 00091 } 00092 00093 RetCode_t TextDisplay::background(uint16_t color) 00094 { 00095 //INFO("background(%4X)", color); 00096 _background = color; 00097 return noerror; 00098 } 00099 00100 bool TextDisplay::claim(FILE *stream) 00101 { 00102 if ( _path == NULL) { 00103 fprintf(stderr, "claim requires a name to be given in the instantiator of the TextDisplay instance!\r\n"); 00104 return false; 00105 } 00106 if (freopen(_path, "w", stream) == NULL) { 00107 return false; // Failed, should not happen 00108 } 00109 // make sure we use line buffering 00110 setvbuf(stdout, NULL, _IOLBF, columns()); 00111 return true; 00112 } 00113
Generated on Tue Jul 26 2022 07:46:24 by 1.7.2