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