Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.

Dependents:   Mbell

Committer:
hlipka
Date:
Sat Nov 27 22:54:13 2010 +0000
Revision:
2:5ac5bab7daaf
Parent:
1:65f72ed914fa
Child:
3:e5d5e2fe4bf6
Moved to \"Stream\"-based API (like TextLCD) which allows the usage of printf

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 0:ae5037e3d6e0 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 0:ae5037e3d6e0 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 0:ae5037e3d6e0 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 "subwindow.h"
hlipka 0:ae5037e3d6e0 25
hlipka 0:ae5037e3d6e0 26 #include "string.h"
hlipka 0:ae5037e3d6e0 27
hlipka 2:5ac5bab7daaf 28 SubWindow::SubWindow(Window* lcd, const unsigned int columnOffset, const unsigned int rowOffset, const unsigned int columns, const unsigned int rows) {
hlipka 0:ae5037e3d6e0 29 _lcd=lcd;
hlipka 2:5ac5bab7daaf 30 _columnOffset=columnOffset;
hlipka 2:5ac5bab7daaf 31 _rowOffset=rowOffset;
hlipka 2:5ac5bab7daaf 32 _columns=columns;
hlipka 2:5ac5bab7daaf 33 _rows=rows;
hlipka 0:ae5037e3d6e0 34
hlipka 0:ae5037e3d6e0 35 }
hlipka 0:ae5037e3d6e0 36
hlipka 2:5ac5bab7daaf 37 void SubWindow::character(int column, int row, int c)
hlipka 2:5ac5bab7daaf 38 {
hlipka 2:5ac5bab7daaf 39 if (column>_columns || row>_rows)
hlipka 0:ae5037e3d6e0 40 return;
hlipka 0:ae5037e3d6e0 41
hlipka 2:5ac5bab7daaf 42 _lcd->character(column+_columnOffset, row+_rowOffset, c);
hlipka 2:5ac5bab7daaf 43 }
hlipka 2:5ac5bab7daaf 44
hlipka 2:5ac5bab7daaf 45 void SubWindow::writeText(const unsigned int column, const unsigned int row, const char* text) {
hlipka 2:5ac5bab7daaf 46 if (row>_rows)
hlipka 2:5ac5bab7daaf 47 return;
hlipka 2:5ac5bab7daaf 48
hlipka 2:5ac5bab7daaf 49 char* text2=new char[_columns-column+1];
hlipka 0:ae5037e3d6e0 50 int i=0;
hlipka 2:5ac5bab7daaf 51 while (i<_columns-column+1) {
hlipka 0:ae5037e3d6e0 52 text2[i]=text[i];
hlipka 0:ae5037e3d6e0 53 if (text[i]=='\0')
hlipka 0:ae5037e3d6e0 54 break;
hlipka 0:ae5037e3d6e0 55 i++;
hlipka 0:ae5037e3d6e0 56 }
hlipka 2:5ac5bab7daaf 57 text2[_columns-column]='\0';
hlipka 0:ae5037e3d6e0 58
hlipka 2:5ac5bab7daaf 59 _lcd->writeText(column+_columnOffset, row+_rowOffset, text2);
hlipka 0:ae5037e3d6e0 60 delete [] text2;
hlipka 0:ae5037e3d6e0 61 }
hlipka 0:ae5037e3d6e0 62
hlipka 0:ae5037e3d6e0 63 void SubWindow::clear() {
hlipka 2:5ac5bab7daaf 64 char* spaces=new char[_columns+1];
hlipka 2:5ac5bab7daaf 65 memset(spaces,32,_columns);
hlipka 2:5ac5bab7daaf 66 spaces[_columns]=0;
hlipka 2:5ac5bab7daaf 67 for (int i=0;i<_rows;i++) {
hlipka 2:5ac5bab7daaf 68 _lcd->writeText(_columnOffset,_rowOffset+i,spaces);
hlipka 0:ae5037e3d6e0 69 }
hlipka 0:ae5037e3d6e0 70 }