Wim Huiskamp / TextLCD
Dependents: Projeto_CCM_Maquinas_MotorPasso Projeto_CCM_Maquinas_MotorDC
TextDisplay.cpp@0:edfb85c53631, 2010-05-22 (annotated)
- Committer:
- simon
- Date:
- Sat May 22 18:18:19 2010 +0000
- Revision:
- 0:edfb85c53631
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:edfb85c53631 | 1 | /* mbed TextDisplay Library Base Class |
simon | 0:edfb85c53631 | 2 | * Copyright (c) 2007-2010, sford |
simon | 0:edfb85c53631 | 3 | * |
simon | 0:edfb85c53631 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 0:edfb85c53631 | 5 | * of this software and associated documentation files (the "Software"), to deal |
simon | 0:edfb85c53631 | 6 | * in the Software without restriction, including without limitation the rights |
simon | 0:edfb85c53631 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 0:edfb85c53631 | 8 | * copies of the Software, and to permit persons to whom the Software is |
simon | 0:edfb85c53631 | 9 | * furnished to do so, subject to the following conditions: |
simon | 0:edfb85c53631 | 10 | * |
simon | 0:edfb85c53631 | 11 | * The above copyright notice and this permission notice shall be included in |
simon | 0:edfb85c53631 | 12 | * all copies or substantial portions of the Software. |
simon | 0:edfb85c53631 | 13 | * |
simon | 0:edfb85c53631 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 0:edfb85c53631 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 0:edfb85c53631 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 0:edfb85c53631 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 0:edfb85c53631 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 0:edfb85c53631 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 0:edfb85c53631 | 20 | * THE SOFTWARE. |
simon | 0:edfb85c53631 | 21 | */ |
simon | 0:edfb85c53631 | 22 | |
simon | 0:edfb85c53631 | 23 | #include "TextDisplay.h" |
simon | 0:edfb85c53631 | 24 | |
simon | 0:edfb85c53631 | 25 | TextDisplay::TextDisplay() { |
simon | 0:edfb85c53631 | 26 | _row = 0; |
simon | 0:edfb85c53631 | 27 | _column = 0; |
simon | 0:edfb85c53631 | 28 | } |
simon | 0:edfb85c53631 | 29 | |
simon | 0:edfb85c53631 | 30 | int TextDisplay::_putc(int value) { |
simon | 0:edfb85c53631 | 31 | if(value == '\n') { |
simon | 0:edfb85c53631 | 32 | _column = 0; |
simon | 0:edfb85c53631 | 33 | _row++; |
simon | 0:edfb85c53631 | 34 | if(_row >= rows()) { |
simon | 0:edfb85c53631 | 35 | _row = 0; |
simon | 0:edfb85c53631 | 36 | } |
simon | 0:edfb85c53631 | 37 | } else { |
simon | 0:edfb85c53631 | 38 | character(_column, _row, value); |
simon | 0:edfb85c53631 | 39 | _column++; |
simon | 0:edfb85c53631 | 40 | if(_column >= columns()) { |
simon | 0:edfb85c53631 | 41 | _column = 0; |
simon | 0:edfb85c53631 | 42 | _row++; |
simon | 0:edfb85c53631 | 43 | if(_row >= rows()) { |
simon | 0:edfb85c53631 | 44 | _row = 0; |
simon | 0:edfb85c53631 | 45 | } |
simon | 0:edfb85c53631 | 46 | } |
simon | 0:edfb85c53631 | 47 | } |
simon | 0:edfb85c53631 | 48 | return value; |
simon | 0:edfb85c53631 | 49 | } |
simon | 0:edfb85c53631 | 50 | |
simon | 0:edfb85c53631 | 51 | // a basic cls implementation, that should generally be overwritten |
simon | 0:edfb85c53631 | 52 | // with a more efficient implementation |
simon | 0:edfb85c53631 | 53 | void TextDisplay::cls() { |
simon | 0:edfb85c53631 | 54 | locate(0, 0); |
simon | 0:edfb85c53631 | 55 | for(int i=0; i<columns()*rows(); i++) { |
simon | 0:edfb85c53631 | 56 | putc(' '); |
simon | 0:edfb85c53631 | 57 | } |
simon | 0:edfb85c53631 | 58 | } |
simon | 0:edfb85c53631 | 59 | |
simon | 0:edfb85c53631 | 60 | void TextDisplay::locate(int column, int row) { |
simon | 0:edfb85c53631 | 61 | _column = column; |
simon | 0:edfb85c53631 | 62 | _row = row; |
simon | 0:edfb85c53631 | 63 | } |
simon | 0:edfb85c53631 | 64 | |
simon | 0:edfb85c53631 | 65 | int TextDisplay::_getc() { |
simon | 0:edfb85c53631 | 66 | return -1; |
simon | 0:edfb85c53631 | 67 | } |
simon | 0:edfb85c53631 | 68 | |
simon | 0:edfb85c53631 | 69 | void TextDisplay::foreground(int colour) { |
simon | 0:edfb85c53631 | 70 | _foreground = colour; |
simon | 0:edfb85c53631 | 71 | } |
simon | 0:edfb85c53631 | 72 | |
simon | 0:edfb85c53631 | 73 | void TextDisplay::background(int colour) { |
simon | 0:edfb85c53631 | 74 | _background = colour; |
simon | 0:edfb85c53631 | 75 | } |