Ken Todotani
/
eDISP
eDisp library and sample code
eDisp.cpp@1:134b6e987450, 2011-03-07 (annotated)
- Committer:
- todotani
- Date:
- Mon Mar 07 13:38:33 2011 +0000
- Revision:
- 1:134b6e987450
- Parent:
- 0:e86010984e9a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
todotani | 0:e86010984e9a | 1 | /* mbed eDISP Library |
todotani | 0:e86010984e9a | 2 | * Copyright (c) 2010 todotani |
todotani | 0:e86010984e9a | 3 | * Version 0.1 (March 6, 2010) |
todotani | 0:e86010984e9a | 4 | * Released under the MIT License: http://mbed.org/license/mit |
todotani | 0:e86010984e9a | 5 | */ |
todotani | 0:e86010984e9a | 6 | |
todotani | 0:e86010984e9a | 7 | #include "eDisp.h" |
todotani | 0:e86010984e9a | 8 | #include "error.h" |
todotani | 0:e86010984e9a | 9 | |
todotani | 0:e86010984e9a | 10 | using namespace mbed; |
todotani | 0:e86010984e9a | 11 | |
todotani | 0:e86010984e9a | 12 | eDisp::eDisp(PinName tx, PinName rx, int baud, int columns, int rows) |
todotani | 0:e86010984e9a | 13 | :_serial(tx, rx), _columns(columns), _rows(rows) { |
todotani | 0:e86010984e9a | 14 | _serial.baud(baud); |
todotani | 0:e86010984e9a | 15 | cls(); |
todotani | 0:e86010984e9a | 16 | } |
todotani | 0:e86010984e9a | 17 | |
todotani | 0:e86010984e9a | 18 | int eDisp::_putc(int value) { |
todotani | 0:e86010984e9a | 19 | if(value == '\n') { |
todotani | 0:e86010984e9a | 20 | newline(); |
todotani | 0:e86010984e9a | 21 | } else { |
todotani | 0:e86010984e9a | 22 | _serial.putc(value); |
todotani | 0:e86010984e9a | 23 | } |
todotani | 0:e86010984e9a | 24 | return value; |
todotani | 0:e86010984e9a | 25 | } |
todotani | 0:e86010984e9a | 26 | |
todotani | 0:e86010984e9a | 27 | int eDisp::_getc() { |
todotani | 0:e86010984e9a | 28 | return 0; |
todotani | 0:e86010984e9a | 29 | } |
todotani | 0:e86010984e9a | 30 | |
todotani | 0:e86010984e9a | 31 | void eDisp::newline() { |
todotani | 0:e86010984e9a | 32 | _column = 0; |
todotani | 0:e86010984e9a | 33 | _row++; |
todotani | 0:e86010984e9a | 34 | if (_row >= _rows) { |
todotani | 0:e86010984e9a | 35 | _row = 0; |
todotani | 0:e86010984e9a | 36 | } |
todotani | 0:e86010984e9a | 37 | locate(_column, _row); |
todotani | 0:e86010984e9a | 38 | } |
todotani | 0:e86010984e9a | 39 | |
todotani | 0:e86010984e9a | 40 | void eDisp::locate(int column, int row) { |
todotani | 0:e86010984e9a | 41 | if (column < 0 || column >= _columns || row < 0 || row >= _rows) { |
todotani | 0:e86010984e9a | 42 | error("locate(%d,%d) out of range on %dx%d display", column, row, _columns, _rows); |
todotani | 0:e86010984e9a | 43 | return; |
todotani | 0:e86010984e9a | 44 | } |
todotani | 0:e86010984e9a | 45 | |
todotani | 0:e86010984e9a | 46 | _row = row; |
todotani | 0:e86010984e9a | 47 | _column = column; |
todotani | 0:e86010984e9a | 48 | _serial.printf("\x1B[%d;%dH", _row, _column); |
todotani | 0:e86010984e9a | 49 | } |
todotani | 0:e86010984e9a | 50 | |
todotani | 0:e86010984e9a | 51 | void eDisp::cls() { |
todotani | 0:e86010984e9a | 52 | locate(0, 0); |
todotani | 0:e86010984e9a | 53 | _serial.printf("\x1B[J"); |
todotani | 0:e86010984e9a | 54 | } |
todotani | 0:e86010984e9a | 55 | |
todotani | 0:e86010984e9a | 56 | void eDisp::reset() { |
todotani | 0:e86010984e9a | 57 | _serial.printf("\x1B[m"); |
todotani | 0:e86010984e9a | 58 | cls(); |
todotani | 0:e86010984e9a | 59 | } |
todotani | 0:e86010984e9a | 60 | |
todotani | 0:e86010984e9a | 61 | void eDisp::textColor (int color) { |
todotani | 0:e86010984e9a | 62 | _serial.printf("\x1B[%dm", color); |
todotani | 0:e86010984e9a | 63 | } |
todotani | 0:e86010984e9a | 64 | |
todotani | 0:e86010984e9a | 65 | void eDisp::backgroundColor (int color) { |
todotani | 0:e86010984e9a | 66 | _serial.printf("\x1B[%dm", color + 10); |
todotani | 0:e86010984e9a | 67 | } |
todotani | 0:e86010984e9a | 68 | |
todotani | 0:e86010984e9a | 69 | void eDisp::fillRect (int buffer, int width, int hight, int x, int y, int color ) { |
todotani | 0:e86010984e9a | 70 | _serial.printf("\x1B@0;%d;%d;%d;%d;%d;%dz", buffer, width, hight, x, y, color); |
todotani | 0:e86010984e9a | 71 | } |
todotani | 0:e86010984e9a | 72 | |
todotani | 0:e86010984e9a | 73 | void eDisp::drawLine (int buffer, int x0, int y0, int x1, int y1, int color) { |
todotani | 0:e86010984e9a | 74 | _serial.printf("\x1B@2;%d;%d;%d;%d;%d;%dz", buffer, x0, y0, x1, y1, color); |
todotani | 0:e86010984e9a | 75 | } |