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

Fork of LcdWindow by Hendrik Lipka

Committer:
charly
Date:
Wed Jan 13 19:38:54 2016 +0000
Revision:
13:99b500b05716
Parent:
11:85f30e1f19fc
added enableDisplay and disableDisplay for Terminal to stop the output to LCD.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:ae5037e3d6e0 1 /*
hlipka 0:ae5037e3d6e0 2 * mbed LCDWindow library
hlipka 0:ae5037e3d6e0 3 * Copyright (c) 2010 Hendrik Lipka
hlipka 2:5ac5bab7daaf 4 *
hlipka 0:ae5037e3d6e0 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 0:ae5037e3d6e0 6 * of this software and associated documentation files (the "Software"), to deal
hlipka 0:ae5037e3d6e0 7 * in the Software without restriction, including without limitation the rights
hlipka 0:ae5037e3d6e0 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 0:ae5037e3d6e0 9 * copies of the Software, and to permit persons to whom the Software is
hlipka 0:ae5037e3d6e0 10 * furnished to do so, subject to the following conditions:
hlipka 2:5ac5bab7daaf 11 *
hlipka 0:ae5037e3d6e0 12 * The above copyright notice and this permission notice shall be included in
hlipka 0:ae5037e3d6e0 13 * all copies or substantial portions of the Software.
hlipka 2:5ac5bab7daaf 14 *
hlipka 0:ae5037e3d6e0 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 0:ae5037e3d6e0 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 0:ae5037e3d6e0 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 0:ae5037e3d6e0 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 0:ae5037e3d6e0 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 0:ae5037e3d6e0 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 0:ae5037e3d6e0 21 * THE SOFTWARE.
hlipka 0:ae5037e3d6e0 22 */
hlipka 0:ae5037e3d6e0 23
hlipka 0:ae5037e3d6e0 24 #include "terminal.h"
hlipka 0:ae5037e3d6e0 25 #include "string.h"
hlipka 0:ae5037e3d6e0 26
charly 13:99b500b05716 27 Terminal::Terminal(Window* window):Window()
charly 13:99b500b05716 28 {
hlipka 0:ae5037e3d6e0 29 _window=window;
hlipka 2:5ac5bab7daaf 30 _columns=window->getColumns();
hlipka 2:5ac5bab7daaf 31 _rows=window->getRows();
hlipka 2:5ac5bab7daaf 32 _lineBuffer=new char*[_rows];
charly 13:99b500b05716 33 _enabled = true;
hlipka 2:5ac5bab7daaf 34 clear();
hlipka 0:ae5037e3d6e0 35 }
hlipka 0:ae5037e3d6e0 36
charly 13:99b500b05716 37 char* Terminal::createLine()
charly 13:99b500b05716 38 {
hlipka 2:5ac5bab7daaf 39 char* text=new char[_columns+1];
hlipka 2:5ac5bab7daaf 40 memset(text,32,_columns);
hlipka 2:5ac5bab7daaf 41 text[_columns]=0;
hlipka 0:ae5037e3d6e0 42 return text;
hlipka 0:ae5037e3d6e0 43 }
hlipka 0:ae5037e3d6e0 44
charly 13:99b500b05716 45 void Terminal::character(int column, int row, int c)
charly 13:99b500b05716 46 {
hlipka 2:5ac5bab7daaf 47 if (column>_columns || row > _rows) {
hlipka 2:5ac5bab7daaf 48 return;
hlipka 2:5ac5bab7daaf 49 }
hlipka 2:5ac5bab7daaf 50 _lineBuffer[row][column]=c;
charly 13:99b500b05716 51 if (_enabled) {
charly 13:99b500b05716 52 _window->character(column,row,c);
charly 13:99b500b05716 53 }
hlipka 2:5ac5bab7daaf 54
hlipka 2:5ac5bab7daaf 55 }
hlipka 2:5ac5bab7daaf 56
charly 13:99b500b05716 57 void Terminal::writeText(const unsigned int column, const unsigned int row, const char text[])
charly 13:99b500b05716 58 {
charly 13:99b500b05716 59 if (_enabled) {
charly 13:99b500b05716 60 _window->writeText(column,row,text);
charly 13:99b500b05716 61 }
hlipka 2:5ac5bab7daaf 62 int min=column+strlen(text);
hlipka 2:5ac5bab7daaf 63 if (min>_columns)
hlipka 2:5ac5bab7daaf 64 min=_columns;
charly 13:99b500b05716 65 for (int i=column; i<min; i++) {
hlipka 2:5ac5bab7daaf 66 _lineBuffer[row][i]=text[i-column]; // copy text into proper line
hlipka 0:ae5037e3d6e0 67 }
hlipka 0:ae5037e3d6e0 68 }
hlipka 0:ae5037e3d6e0 69
charly 13:99b500b05716 70 void Terminal::addText(const char text[])
charly 13:99b500b05716 71 {
hlipka 2:5ac5bab7daaf 72 delete [] _lineBuffer[0];
charly 13:99b500b05716 73 for (int i=0; i<_rows-1; i++) {
hlipka 2:5ac5bab7daaf 74 _lineBuffer[i]=_lineBuffer[i+1];
hlipka 0:ae5037e3d6e0 75 }
hlipka 2:5ac5bab7daaf 76 _lineBuffer[_rows-1]=createLine();
hlipka 2:5ac5bab7daaf 77 memset(_lineBuffer[_rows-1],32,_columns);
hlipka 0:ae5037e3d6e0 78 int min=strlen(text);
hlipka 2:5ac5bab7daaf 79 if (min>_columns)
hlipka 2:5ac5bab7daaf 80 min=_columns;
charly 13:99b500b05716 81 for (int i=0; i<min; i++) {
hlipka 2:5ac5bab7daaf 82 _lineBuffer[_rows-1][i]=text[i]; // copy text into proper line
hlipka 0:ae5037e3d6e0 83 }
charly 13:99b500b05716 84 if (_enabled) {
charly 13:99b500b05716 85 _window->clear();
charly 13:99b500b05716 86 for (int i=0; i<_rows; i++) {
charly 13:99b500b05716 87 _window->writeText(0,i,_lineBuffer[i]);
charly 13:99b500b05716 88 }
hlipka 0:ae5037e3d6e0 89 }
charly 13:99b500b05716 90 // text longer than line?
charly 13:99b500b05716 91 if (strlen(text) > _columns) {
charly 11:85f30e1f19fc 92 // add the remaining text to the next Line
charly 11:85f30e1f19fc 93 this->addText(text + _columns);
charly 11:85f30e1f19fc 94 }
hlipka 0:ae5037e3d6e0 95 }
hlipka 0:ae5037e3d6e0 96
charly 13:99b500b05716 97 void Terminal::clear()
charly 13:99b500b05716 98 {
charly 13:99b500b05716 99 for (int i=0; i<_rows; i++) {
hlipka 2:5ac5bab7daaf 100 _lineBuffer[i]=createLine();
hlipka 2:5ac5bab7daaf 101 }
charly 13:99b500b05716 102 if (_enabled) {
charly 13:99b500b05716 103 _window->clear();
charly 13:99b500b05716 104 }
charly 13:99b500b05716 105 }
charly 13:99b500b05716 106
charly 13:99b500b05716 107 void Terminal::disableDisplay()
charly 13:99b500b05716 108 {
charly 13:99b500b05716 109 if (_enabled) {
charly 13:99b500b05716 110 _enabled = false;
charly 13:99b500b05716 111 _window->clear();
charly 13:99b500b05716 112 }
hlipka 0:ae5037e3d6e0 113 }
charly 13:99b500b05716 114
charly 13:99b500b05716 115 void Terminal::enableDisplay()
charly 13:99b500b05716 116 {
charly 13:99b500b05716 117 if (! _enabled) {
charly 13:99b500b05716 118 _enabled = true;
charly 13:99b500b05716 119 _window->clear();
charly 13:99b500b05716 120 //Display the buffer-content
charly 13:99b500b05716 121 for (int i=0; i<_rows; i++) {
charly 13:99b500b05716 122 _window->writeText(0,i,_lineBuffer[i]);
charly 13:99b500b05716 123 }
charly 13:99b500b05716 124 }
charly 13:99b500b05716 125 }