- ANALOG METER, initial offering - Emulation of an analog/mechanical meter using the SPI TFT display \"http://mbed.org/cookbook/SPI-driven-QVGA-TFT\" (touch not used) Meter takes an integer number from 0 - 100 and uses that number to position the meter\'s needle - An additional auto-scaling feature allows for + floating numbers from 0.0 - 10000.0 in \"NewfNumb\" Scaling is noted two ways a. Color of the meter body changes b. A text scale factor is displayed in the upper, right-hand corner, near the full scale reading Value of \"NewfNumb\" Meter_Body Scale_Factor < -0.0 Blue 0 0.1 - 9.9 Green x1 10.0 - 99.0 Yellow x10 100.0 - 999.0 Orange x100 1000.0 - 9990.0 Red x1k >= 10000.0 Red peg! - If NewfNumb is > 600.0, a flashing yellow warning message appears in the center of the meter movement - The date and time are displayed in the lower right corner of the display - The value of NewfNumb being shown in the movement is also displayed in the lower left coener of the display - A timer ISR automatically updates the meter\'s movement Other Stuff: - Additional demo test program, walks analog meter up and down through all auto scales by manipulating the value of NewfNumb - USB serial port used to dump a few messages. Not needed, set to 921600 BAUD - LED1 slowly gets brighter and dimmer as main loop runs - If for some reason, the \"MeterNumber\" int register ends up >100 or <0, a Purple display appears at 50% movement with a \"bad#\" scale factor - There is NO provision for setting the RTC. Note that TimeZone and DST are added to the RTC number

Dependencies:   mbed

Committer:
loopsva
Date:
Tue Jan 31 19:40:57 2012 +0000
Revision:
0:fc70640071d2
100

Who changed what in which revision?

UserRevisionLine numberNew contents of line
loopsva 0:fc70640071d2 1 /* mbed TextDisplay Display Library Base Class
loopsva 0:fc70640071d2 2 * Copyright (c) 2007-2009 sford
loopsva 0:fc70640071d2 3 * Released under the MIT License: http://mbed.org/license/mit
loopsva 0:fc70640071d2 4 */
loopsva 0:fc70640071d2 5
loopsva 0:fc70640071d2 6 #include "TextDisplay.h"
loopsva 0:fc70640071d2 7
loopsva 0:fc70640071d2 8 TextDisplay::TextDisplay(const char *name) : Stream(name){
loopsva 0:fc70640071d2 9 _row = 0;
loopsva 0:fc70640071d2 10 _column = 0;
loopsva 0:fc70640071d2 11 if (name == NULL) {
loopsva 0:fc70640071d2 12 _path = NULL;
loopsva 0:fc70640071d2 13 } else {
loopsva 0:fc70640071d2 14 _path = new char[strlen(name) + 2];
loopsva 0:fc70640071d2 15 sprintf(_path, "/%s", name);
loopsva 0:fc70640071d2 16 }
loopsva 0:fc70640071d2 17 }
loopsva 0:fc70640071d2 18
loopsva 0:fc70640071d2 19 int TextDisplay::_putc(int value) {
loopsva 0:fc70640071d2 20 if(value == '\n') {
loopsva 0:fc70640071d2 21 _column = 0;
loopsva 0:fc70640071d2 22 _row++;
loopsva 0:fc70640071d2 23 if(_row >= rows()) {
loopsva 0:fc70640071d2 24 _row = 0;
loopsva 0:fc70640071d2 25 }
loopsva 0:fc70640071d2 26 } else {
loopsva 0:fc70640071d2 27 character(_column, _row, value);
loopsva 0:fc70640071d2 28 _column++;
loopsva 0:fc70640071d2 29 if(_column >= columns()) {
loopsva 0:fc70640071d2 30 _column = 0;
loopsva 0:fc70640071d2 31 _row++;
loopsva 0:fc70640071d2 32 if(_row >= rows()) {
loopsva 0:fc70640071d2 33 _row = 0;
loopsva 0:fc70640071d2 34 }
loopsva 0:fc70640071d2 35 }
loopsva 0:fc70640071d2 36 }
loopsva 0:fc70640071d2 37 return value;
loopsva 0:fc70640071d2 38 }
loopsva 0:fc70640071d2 39
loopsva 0:fc70640071d2 40 // crude cls implementation, should generally be overwritten in derived class
loopsva 0:fc70640071d2 41 void TextDisplay::cls() {
loopsva 0:fc70640071d2 42 locate(0, 0);
loopsva 0:fc70640071d2 43 for(int i=0; i<columns()*rows(); i++) {
loopsva 0:fc70640071d2 44 putc(' ');
loopsva 0:fc70640071d2 45 }
loopsva 0:fc70640071d2 46 }
loopsva 0:fc70640071d2 47
loopsva 0:fc70640071d2 48 void TextDisplay::locate(int column, int row) {
loopsva 0:fc70640071d2 49 _column = column;
loopsva 0:fc70640071d2 50 _row = row;
loopsva 0:fc70640071d2 51 }
loopsva 0:fc70640071d2 52
loopsva 0:fc70640071d2 53 int TextDisplay::_getc() {
loopsva 0:fc70640071d2 54 return -1;
loopsva 0:fc70640071d2 55 }
loopsva 0:fc70640071d2 56
loopsva 0:fc70640071d2 57 void TextDisplay::foreground(uint16_t colour) {
loopsva 0:fc70640071d2 58 _foreground = colour;
loopsva 0:fc70640071d2 59 }
loopsva 0:fc70640071d2 60
loopsva 0:fc70640071d2 61 void TextDisplay::background(uint16_t colour) {
loopsva 0:fc70640071d2 62 _background = colour;
loopsva 0:fc70640071d2 63 }
loopsva 0:fc70640071d2 64
loopsva 0:fc70640071d2 65 bool TextDisplay::claim (FILE *stream) {
loopsva 0:fc70640071d2 66 if ( _path == NULL) {
loopsva 0:fc70640071d2 67 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
loopsva 0:fc70640071d2 68 return false;
loopsva 0:fc70640071d2 69 }
loopsva 0:fc70640071d2 70 if (freopen(_path, "w", stream) == NULL) {
loopsva 0:fc70640071d2 71 // Failed, should not happen
loopsva 0:fc70640071d2 72 return false;
loopsva 0:fc70640071d2 73 }
loopsva 0:fc70640071d2 74 // make sure we use line buffering
loopsva 0:fc70640071d2 75 setvbuf(stdout, NULL, _IOLBF, columns());
loopsva 0:fc70640071d2 76 return true;
loopsva 0:fc70640071d2 77 }