Fork of LCD-Window which works with Enhanced TextLCD from Wim

Fork of LcdWindow by Hendrik Lipka

Files at this revision

API Documentation at this revision

Comitter:
charly
Date:
Wed Jan 13 19:38:54 2016 +0000
Parent:
12:393329d0e050
Commit message:
added enableDisplay and disableDisplay for Terminal to stop the output to LCD.

Changed in this revision

terminal.cpp Show annotated file Show diff for this revision Revisions of this file
terminal.h Show annotated file Show diff for this revision Revisions of this file
--- a/terminal.cpp	Tue Jan 12 20:40:39 2016 +0000
+++ b/terminal.cpp	Wed Jan 13 19:38:54 2016 +0000
@@ -24,43 +24,53 @@
 #include "terminal.h"
 #include "string.h"
 
-Terminal::Terminal(Window* window):Window() {
+Terminal::Terminal(Window* window):Window()
+{
     _window=window;
     _columns=window->getColumns();
     _rows=window->getRows();
     _lineBuffer=new char*[_rows];
+    _enabled = true;
     clear();
 }
 
-char* Terminal::createLine() {
+char* Terminal::createLine()
+{
     char* text=new char[_columns+1];
     memset(text,32,_columns);
     text[_columns]=0;
     return text;
 }
 
-void Terminal::character(int column, int row, int c) {
+void Terminal::character(int column, int row, int c)
+{
     if (column>_columns || row > _rows) {
         return;
     }
     _lineBuffer[row][column]=c;
-    _window->character(column,row,c);
+    if (_enabled) {
+        _window->character(column,row,c);
+    }
 
 }
 
-void Terminal::writeText(const unsigned int column, const unsigned int row, const char text[]) {
-    _window->writeText(column,row,text);
+void Terminal::writeText(const unsigned int column, const unsigned int row, const char text[])
+{
+    if (_enabled) {
+        _window->writeText(column,row,text);
+    }
     int min=column+strlen(text);
     if (min>_columns)
         min=_columns;
-    for (int i=column;i<min;i++) {
+    for (int i=column; i<min; i++) {
         _lineBuffer[row][i]=text[i-column]; // copy text into proper line
     }
 }
 
-void Terminal::addText(const char text[]) {
+void Terminal::addText(const char text[])
+{
     delete [] _lineBuffer[0];
-    for (int i=0;i<_rows-1;i++) {
+    for (int i=0; i<_rows-1; i++) {
         _lineBuffer[i]=_lineBuffer[i+1];
     }
     _lineBuffer[_rows-1]=createLine();
@@ -68,22 +78,48 @@
     int min=strlen(text);
     if (min>_columns)
         min=_columns;
-    for (int i=0;i<min;i++) {
+    for (int i=0; i<min; i++) {
         _lineBuffer[_rows-1][i]=text[i]; // copy text into proper line
     }
-    _window->clear();
-    for (int i=0;i<_rows;i++) {
-        _window->writeText(0,i,_lineBuffer[i]);
+    if (_enabled) {
+        _window->clear();
+        for (int i=0; i<_rows; i++) {
+            _window->writeText(0,i,_lineBuffer[i]);
+        }
     }
-    if (strlen(text) > _columns){
+    // text longer than line?
+    if (strlen(text) > _columns) {
         // add the remaining text to the next Line
         this->addText(text + _columns);
     }
 }
 
-void Terminal::clear() {
-    for (int i=0;i<_rows;i++) {
+void Terminal::clear()
+{
+    for (int i=0; i<_rows; i++) {
         _lineBuffer[i]=createLine();
     }
-    _window->clear();
+    if (_enabled) {
+        _window->clear();
+    }
+}
+
+void Terminal::disableDisplay()
+{
+    if (_enabled) {
+        _enabled = false;
+        _window->clear();
+    }
 }
+
+void Terminal::enableDisplay()
+{
+    if (! _enabled) {
+        _enabled = true;
+        _window->clear();
+        //Display the buffer-content
+        for (int i=0; i<_rows; i++) {
+            _window->writeText(0,i,_lineBuffer[i]);
+        }
+    }
+}
\ No newline at end of file
--- a/terminal.h	Tue Jan 12 20:40:39 2016 +0000
+++ b/terminal.h	Wed Jan 13 19:38:54 2016 +0000
@@ -51,6 +51,14 @@
         virtual int getRows(){return _rows;};
         virtual void clear();
         virtual void character(int column, int row, int c);
+        /**
+         * disable Output on Display
+        */
+        void disableDisplay();
+        /**
+         * Enable Output on Display
+        */
+        void enableDisplay();
 
     private:
         Window* _window;
@@ -58,6 +66,7 @@
         unsigned int _columns;
         unsigned int _rows;
         char* createLine();
+        bool _enabled;
 };
 
 #endif
\ No newline at end of file