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.
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 _foreground = 0; 00026 _background = 0; 00027 if (name == NULL) { 00028 _path = NULL; 00029 } else { 00030 int len = strlen(name) + 2; 00031 _path = new char[len]; 00032 snprintf(_path, len, "/%s", name); 00033 } 00034 } 00035 00036 TextDisplay::~TextDisplay() 00037 { 00038 delete [] _path; 00039 } 00040 00041 int TextDisplay::_putc(int value) 00042 { 00043 INFO("_putc(%d)", value); 00044 if(value == '\n') { 00045 _column = 0; 00046 _row++; 00047 if(_row >= rows()) { 00048 _row = 0; 00049 } 00050 } else { 00051 character(_column, _row, value); 00052 _column++; 00053 if(_column >= columns()) { 00054 _column = 0; 00055 _row++; 00056 if(_row >= rows()) { 00057 _row = 0; 00058 } 00059 } 00060 } 00061 return value; 00062 } 00063 00064 // crude cls implementation, should generally be overwritten in derived class 00065 RetCode_t TextDisplay::cls(uint16_t layers) 00066 { 00067 INFO("cls()"); 00068 locate(0, 0); 00069 for(int i=0; i<columns()*rows(); i++) { 00070 putc(' '); 00071 } 00072 return noerror; 00073 } 00074 00075 RetCode_t TextDisplay::locate(textloc_t column, textloc_t row) 00076 { 00077 INFO("locate(%d,%d)", column, row); 00078 _column = column; 00079 _row = row; 00080 return noerror; 00081 } 00082 00083 int TextDisplay::_getc() 00084 { 00085 return -1; 00086 } 00087 00088 RetCode_t TextDisplay::foreground(uint16_t color) 00089 { 00090 //INFO("foreground(%4X)", color); 00091 _foreground = color; 00092 return noerror; 00093 } 00094 00095 RetCode_t TextDisplay::background(uint16_t color) 00096 { 00097 //INFO("background(%4X)", color); 00098 _background = color; 00099 return noerror; 00100 } 00101 00102 bool TextDisplay::claim(FILE *stream) 00103 { 00104 if ( _path == NULL) { 00105 fprintf(stderr, "claim requires a name to be given in the instantiator of the TextDisplay instance!\r\n"); 00106 return false; 00107 } 00108 if (freopen(_path, "w", stream) == NULL) { 00109 return false; // Failed, should not happen 00110 } 00111 // make sure we use line buffering 00112 setvbuf(stdout, NULL, _IOLBF, columns()); 00113 return true; 00114 } 00115
Generated on Thu Jul 14 2022 02:03:21 by
1.7.2