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.
Dependents: demoUI whrmDemoUI Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more
Diff: TextDisplay.cpp
- Revision:
- 0:a0faa86660d4
- Child:
- 4:b02dfd360729
diff -r 000000000000 -r a0faa86660d4 TextDisplay.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextDisplay.cpp Wed Mar 18 10:57:16 2015 -0500
@@ -0,0 +1,92 @@
+/* mbed TextDisplay Display Library Base Class
+ * Copyright (c) 2007-2009 sford
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+
+#include "TextDisplay.h"
+#include <cstdarg>
+
+TextDisplay::TextDisplay(const char *name){
+ _row = 0;
+ _column = 0;
+
+ if (name == NULL) {
+ _path = NULL;
+ } else {
+ _path = new char[strlen(name) + 2];
+ sprintf(_path, "/%s", name);
+ }
+}
+
+int TextDisplay::_putc(int value) {
+ if(value == '\n') {
+ _column = 0;
+ _row++;
+ if(_row >= rows()) {
+ _row = 0;
+ }
+ } else {
+ character(_column, _row, value);
+ _column++;
+ if(_column >= columns()) {
+ _column = 0;
+ _row++;
+ if(_row >= rows()) {
+ _row = 0;
+ }
+ }
+ }
+ return value;
+}
+
+// crude cls implementation, should generally be overwritten in derived class
+void TextDisplay::cls() {
+ locate(0, 0);
+ for(int i=0; i<columns()*rows(); i++) {
+ _putc(' ');
+ }
+}
+
+void TextDisplay::locate(int column, int row) {
+ _column = column;
+ _row = row;
+}
+
+int TextDisplay::_getc() {
+ return -1;
+}
+
+void TextDisplay::foreground(uint16_t colour) {
+ _foreground = colour;
+}
+
+void TextDisplay::background(uint16_t colour) {
+ _background = colour;
+}
+
+bool TextDisplay::claim (FILE *stream) {
+ if ( _path == NULL) {
+ fprintf(stderr, "claim requires a name to be given in the instantiator of the TextDisplay instance!\r\n");
+ return false;
+ }
+ if (freopen(_path, "w", stream) == NULL) {
+ // Failed, should not happen
+ return false;
+ }
+ // make sure we use line buffering
+ setvbuf(stdout, NULL, _IOLBF, columns());
+ return true;
+}
+
+void TextDisplay::printf(const char* format, ...) {
+ char buffer[MAX_PRINTF_CHARS + 1] = { 0 };
+ uint32_t iterator = 0;
+ va_list args;
+ va_start(args, format);
+ vsprintf(buffer, format, args);
+ va_end(args);
+
+ while((buffer[iterator] != 0) && (iterator < MAX_PRINTF_CHARS)) {
+ _putc(buffer[iterator++]);
+ }
+}