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 (c) 2007-2009 sford 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 */ 00005 00006 #include "TextDisplay.h" 00007 00008 TextDisplay::TextDisplay(const char *name) : Stream(name){ 00009 _row = 0; 00010 _column = 0; 00011 if (name == NULL) { 00012 _path = NULL; 00013 } else { 00014 _path = new char[strlen(name) + 2]; 00015 sprintf(_path, "/%s", name); 00016 } 00017 } 00018 00019 int TextDisplay::_putc(int value) { 00020 if(value == '\n') { 00021 _column = 0; 00022 _row++; 00023 if(_row >= rows()) { 00024 _row = 0; 00025 } 00026 } else { 00027 character(_column, _row, value); 00028 _column++; 00029 if(_column >= columns()) { 00030 _column = 0; 00031 _row++; 00032 if(_row >= rows()) { 00033 _row = 0; 00034 } 00035 } 00036 } 00037 return value; 00038 } 00039 00040 // crude cls implementation, should generally be overwritten in derived class 00041 void TextDisplay::cls() { 00042 locate(0, 0); 00043 for(int i=0; i<columns()*rows(); i++) { 00044 putc(' '); 00045 } 00046 } 00047 00048 void TextDisplay::locate(int column, int row) { 00049 _column = column; 00050 _row = row; 00051 } 00052 00053 int TextDisplay::_getc() { 00054 return -1; 00055 } 00056 00057 void TextDisplay::foreground(uint16_t colour) { 00058 _foreground = colour; 00059 } 00060 00061 void TextDisplay::background(uint16_t colour) { 00062 _background = colour; 00063 } 00064 00065 bool TextDisplay::claim (FILE *stream) { 00066 if ( _path == NULL) { 00067 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n"); 00068 return false; 00069 } 00070 if (freopen(_path, "w", stream) == NULL) { 00071 // Failed, should not happen 00072 return false; 00073 } 00074 // make sure we use line buffering 00075 setvbuf(stdout, NULL, _IOLBF, columns()); 00076 return true; 00077 }
Generated on Tue Jul 12 2022 12:45:55 by
