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.
terminal.cpp@1:65f72ed914fa, 2010-11-16 (annotated)
- Committer:
- hlipka
- Date:
- Tue Nov 16 20:49:18 2010 +0000
- Revision:
- 1:65f72ed914fa
- Parent:
- 0:ae5037e3d6e0
- Child:
- 2:5ac5bab7daaf
minor revision: made use of \const\ in the API
Who changed what in which revision?
| User | Revision | Line number | New 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 "terminal.h" | 
| hlipka | 0:ae5037e3d6e0 | 25 | #include "string.h" | 
| hlipka | 0:ae5037e3d6e0 | 26 | |
| hlipka | 0:ae5037e3d6e0 | 27 | Terminal::Terminal(Window* window) { | 
| hlipka | 0:ae5037e3d6e0 | 28 | _window=window; | 
| hlipka | 0:ae5037e3d6e0 | 29 | _height=window->getHeight(); | 
| hlipka | 0:ae5037e3d6e0 | 30 | _width=window->getWidth(); | 
| hlipka | 0:ae5037e3d6e0 | 31 | _lines=new char*[_height]; | 
| hlipka | 0:ae5037e3d6e0 | 32 | for (int i=0;i<_height;i++) { | 
| hlipka | 0:ae5037e3d6e0 | 33 | _lines[i]=createLine(); | 
| hlipka | 0:ae5037e3d6e0 | 34 | } | 
| hlipka | 0:ae5037e3d6e0 | 35 | } | 
| hlipka | 0:ae5037e3d6e0 | 36 | |
| hlipka | 0:ae5037e3d6e0 | 37 | char* Terminal::createLine() | 
| hlipka | 0:ae5037e3d6e0 | 38 | { | 
| hlipka | 0:ae5037e3d6e0 | 39 | char* text=new char[_width+1]; | 
| hlipka | 0:ae5037e3d6e0 | 40 | memset(text,32,_width); | 
| hlipka | 0:ae5037e3d6e0 | 41 | text[_width]=0; | 
| hlipka | 0:ae5037e3d6e0 | 42 | return text; | 
| hlipka | 0:ae5037e3d6e0 | 43 | } | 
| hlipka | 0:ae5037e3d6e0 | 44 | |
| hlipka | 1:65f72ed914fa | 45 | void Terminal::writeText(const unsigned int line, const unsigned int pos, const char text[]) { | 
| hlipka | 0:ae5037e3d6e0 | 46 | _window->writeText(line,pos,text); | 
| hlipka | 0:ae5037e3d6e0 | 47 | int min=pos+strlen(text); | 
| hlipka | 0:ae5037e3d6e0 | 48 | if (min>_width) | 
| hlipka | 0:ae5037e3d6e0 | 49 | min=_width; | 
| hlipka | 0:ae5037e3d6e0 | 50 | for (int i=pos;i<min;i++) { | 
| hlipka | 0:ae5037e3d6e0 | 51 | _lines[line][i]=text[i-pos]; // copy text into proper line | 
| hlipka | 0:ae5037e3d6e0 | 52 | } | 
| hlipka | 0:ae5037e3d6e0 | 53 | } | 
| hlipka | 0:ae5037e3d6e0 | 54 | |
| hlipka | 1:65f72ed914fa | 55 | void Terminal::addText(const char text[]) { | 
| hlipka | 0:ae5037e3d6e0 | 56 | delete [] _lines[0]; | 
| hlipka | 0:ae5037e3d6e0 | 57 | for (int i=0;i<_height-1;i++) { | 
| hlipka | 0:ae5037e3d6e0 | 58 | _lines[i]=_lines[i+1]; | 
| hlipka | 0:ae5037e3d6e0 | 59 | } | 
| hlipka | 0:ae5037e3d6e0 | 60 | _lines[_height-1]=createLine(); | 
| hlipka | 0:ae5037e3d6e0 | 61 | memset(_lines[_height-1],32,_width); | 
| hlipka | 0:ae5037e3d6e0 | 62 | int min=strlen(text); | 
| hlipka | 0:ae5037e3d6e0 | 63 | if (min>_width) | 
| hlipka | 0:ae5037e3d6e0 | 64 | min=_width; | 
| hlipka | 0:ae5037e3d6e0 | 65 | for (int i=0;i<min;i++) { | 
| hlipka | 0:ae5037e3d6e0 | 66 | _lines[_height-1][i]=text[i]; // copy text into proper line | 
| hlipka | 0:ae5037e3d6e0 | 67 | } | 
| hlipka | 0:ae5037e3d6e0 | 68 | clear(); | 
| hlipka | 0:ae5037e3d6e0 | 69 | for (int i=0;i<_height;i++) { | 
| hlipka | 0:ae5037e3d6e0 | 70 | _window->writeText(i,0,_lines[i]); | 
| hlipka | 0:ae5037e3d6e0 | 71 | } | 
| hlipka | 0:ae5037e3d6e0 | 72 | } | 
| hlipka | 0:ae5037e3d6e0 | 73 | |
| hlipka | 0:ae5037e3d6e0 | 74 | void Terminal::clear() { | 
| hlipka | 0:ae5037e3d6e0 | 75 | _window->clear(); | 
| hlipka | 0:ae5037e3d6e0 | 76 | } | 
 LCD Window Library
            LCD Window Library