Library for EarthLCD ezLCD3xx line of products
Revision 1:c7659c8af0d3, committed 2013-04-28
- Comitter:
- codeman
- Date:
- Sun Apr 28 07:41:27 2013 +0000
- Parent:
- 0:65606abcae36
- Child:
- 2:fc7d151593f1
- Commit message:
- 4/28/2013 arLCD
Changed in this revision
ezLCDLib.cpp | Show annotated file Show diff for this revision Revisions of this file |
ezLCDLib.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ezLCDLib.cpp Mon Apr 22 06:33:57 2013 +0000 +++ b/ezLCDLib.cpp Sun Apr 28 07:41:27 2013 +0000 @@ -1,14 +1,47 @@ #include "mbed.h" #include "ezLCDLib.h" -#define XSIZE 6 -#define YSIZE 9 -#define BUFF_LEN 10 +void Tx_interrupt(); +void Rx_interrupt(); +void send_line(); +void read_line(); + +//Serial pc(USBTX, USBRX); +// Circular buffers for serial TX and RX data - used by interrupt routines +const int buffer_size = 64; +// might need to increase buffer size for high baud rates +char tx_buffer[buffer_size]; +char rx_buffer[buffer_size]; +// Circular buffer pointers +// volatile makes read-modify-write atomic +volatile int tx_in=0; +volatile int tx_out=0; +volatile int rx_in=0; +volatile int rx_out=0; +// Line buffers for sprintf and sscanf +char tx_line[80]; +char rx_line[80]; + +char buf[64]; + ezLCD3::ezLCD3(PinName tx, PinName rx) : Stream("ezLCD3") , _ser(tx, rx) { _ser.baud(115200); // default baud rate + _ser.attach(this,&ezLCD3::Rx_interrupt, Serial::RxIrq); } +void ezLCD3::Rx_interrupt( void ) +{ +// Loop just in case more than one character is in UART's receive FIFO buffer +// Stop if buffer full + while ((_ser.readable()) || (((rx_in + 1) % buffer_size) == rx_out)) { + rx_buffer[rx_in] = _ser.getc(); +// Uncomment to Echo to USB serial to watch data flow +// monitor_device.putc(rx_buffer[rx_in]); + rx_in = (rx_in + 1) % buffer_size; + } + return; +} /* itoa: convert n to characters in s */ void ezLCD3::itoa(int value, char *sp, int radix) @@ -37,35 +70,78 @@ while (tp > tmp) *sp++ = *--tp; } + +bool ezLCD3::sync( void ) +{ + rx_in=0; + rx_out=0; + _ser.putc('\r'); + if(waitForCR()) + return true; + else + return false; + +} void ezLCD3::sendInt( int i ) { char value[5]= {0, 0, 0, 0, 0}; itoa(i, value, 10); - if(value[0]) putc(value[0]); - if(value[1]) putc(value[1]); - if(value[2]) putc(value[2]); - if(value[3]) putc(value[3]); - if(value[4]) putc(value[4]); + if(value[0]) _ser.putc(value[0]); + if(value[1]) _ser.putc(value[1]); + if(value[2]) _ser.putc(value[2]); + if(value[3]) _ser.putc(value[3]); + if(value[4]) _ser.putc(value[4]); } -/* + +void ezLCD3::stripSpace(char* str) +{ + char* i = str; + char* j = str; + while(*j != 0) + { + *i = *j++; + if(*i != ' ') + i++; + } + *i = 0; +} + int ezLCD3::getInt( char *str ) { - return atoi(str); + stripSpace(str); + return atoi(str ); } + void ezLCD3::getString( char *str ) { - char value[5]= {0, 0, 0, 0, 0}; - int counter; - + char c=0; + unsigned long timeOut=0; + do { + if(rx_in != rx_out) { + c=rx_buffer[rx_out]; + rx_out = (rx_out + 1) % buffer_size; + *str++ = c; + } + timeOut++; + } while(c!='\r' && timeOut != 0xfffff); + *str--; + *str = 0; } -*/ + bool ezLCD3::waitForCR( void ) { - while(! _ser.readable()); - if(_ser.getc() == '\r') + char c=0; + unsigned long timeOut=0; + while(rx_in == rx_out) { + if(timeOut++ > 0xfffff) return false; + } + c=rx_buffer[rx_out]; + rx_out = (rx_out + 1) % buffer_size; + if(c == '\r') { return true; - else + } else { return false; + } } void ezLCD3::cls() @@ -96,6 +172,7 @@ } void ezLCD3::color(int fColor) { + //pc.printf("color"); sendInt(Color); _ser.putc(' '); sendInt(fColor); @@ -116,6 +193,7 @@ _ser.putc(' '); sendInt(y); _ser.putc('\r'); + waitForCR(); } void ezLCD3::plot( void ) @@ -144,7 +222,6 @@ sendInt(y); _ser.putc('\r'); waitForCR(); - } void ezLCD3::circle(int radius, bool filled) @@ -177,6 +254,7 @@ void ezLCD3::light(int i) { + //pc.printf("light"); if (i >= 0 && i <= 100) { sendInt(Light); putc(' '); @@ -185,29 +263,46 @@ waitForCR(); } } -/* -int ezLCD3::getMaxX( void ) + +int ezLCD3::getXmax( void ) { sendInt(Xmax); - putc('\r'); - waitForCR(); - + _ser.putc('\r'); + getString( buf ); + return getInt( buf ); } -int ezLCD3::getMaxY( void ) +int ezLCD3::getYmax( void ) { sendInt(Ymax); - putc('\r'); + _ser.putc('\r'); + getString( buf ); + return getInt( buf ); +} + +void ezLCD3::setStringID( int ID, char *str ) +{ + unsigned char c; + sendInt(StringID); + _ser.putc(' '); + sendInt(ID); + _ser.putc(' '); + _ser.putc('\"'); + while( (c = *str++) ) + _ser.putc(c); + _ser.putc('\"'); + _ser.putc('\r'); waitForCR(); } -void ezLCD3::string( int ID ) { - +void ezLCD3::getStringID( int ID , char *str) +{ + sendInt(StringID); + _ser.putc(' '); + sendInt(ID); + _ser.putc('\r'); + getString(str); } -void ezLCD3::string( int ID , char *str) { - -} -*/ void ezLCD3::reverseMode() { putc(0x7c); @@ -216,14 +311,7 @@ void ezLCD3::resolution(int type) { - switch (type) { - case LCD_128x64 : - resolution(128, 64); - break; - case LCD_160x128 : - resolution(160, 128); - break; - } + } void ezLCD3::print( char *str ) @@ -245,6 +333,96 @@ _yMax = y; } +//ameter [ID][x][y][width][height][options][value][min][max][theme][stringID][type] +void ezLCD3::ameter( int ID, int x, int y, int w, int h, int options, int value, int min, int max, int theme, int stringID, int type) +{ + sendInt(Set_AMeter); + _ser.putc(' '); + sendInt(ID); + _ser.putc(' '); + sendInt(x); + _ser.putc(' '); + sendInt(y); + _ser.putc(' '); + sendInt(w); + _ser.putc(' '); + sendInt(h); + _ser.putc(' '); + sendInt(options); + _ser.putc(' '); + sendInt(value); + _ser.putc(' '); + sendInt(min); + _ser.putc(' '); + sendInt(max); + _ser.putc(' '); + sendInt(theme); + _ser.putc(' '); + sendInt(stringID); + _ser.putc(' '); + sendInt(type); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::touchZone( int ID, int x, int y, int w, int h, bool option) +{ + sendInt(Set_TouchZone); + _ser.putc(' '); + sendInt(ID); + _ser.putc(' '); + sendInt(x); + _ser.putc(' '); + sendInt(y); + _ser.putc(' '); + sendInt(w); + _ser.putc(' '); + sendInt(h); + _ser.putc(' '); + if(option) + sendInt('1'); + else + sendInt('0'); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::button( int ID, int x, int y, int w, int h, int option, int align, int radius, int theme, int stringID ) +{ + sendInt(Set_Button); + _ser.putc(' '); + sendInt(ID); + _ser.putc(' '); + sendInt(x); + _ser.putc(' '); + sendInt(y); + _ser.putc(' '); + sendInt(w); + _ser.putc(' '); + sendInt(h); + _ser.putc(' '); + sendInt(option); + _ser.putc(' '); + sendInt(align); + _ser.putc(' '); + sendInt(radius); + _ser.putc(' '); + sendInt(theme); + _ser.putc(' '); + sendInt(stringID); + _ser.putc('\r'); + waitForCR(); +} + +unsigned int ezLCD3::wstack( int type ) +{ + sendInt( Wstack ); + _ser.putc(' '); + sendInt( type ); + _ser.putc('\r'); + getString( buf ); + return getInt( buf ); +} int ezLCD3::_putc( int c) { _ser.putc('2');
--- a/ezLCDLib.h Mon Apr 22 06:33:57 2013 +0000 +++ b/ezLCDLib.h Sun Apr 28 07:41:27 2013 +0000 @@ -1,5 +1,5 @@ -/* - * +/* + * * * @author Ken Segler * @@ -40,19 +40,10 @@ #define _EZLCDLIB_H #include "mbed.h" -#include "platform.h" -/** LCD Baud Rates */ -#define LCD_4800 1 -#define LCD_9600 2 -#define LCD_19200 3 -#define LCD_38400 4 -#define LCD_57600 5 -#define LCD_115200 6 - -/** LCD Types */ -#define LCD_128x64 1 -#define LCD_160x128 2 +#define FIFO 0 +#define LIFO 1 +#define CLEAR 2 class ezLCD3: public Stream { @@ -68,7 +59,10 @@ * * */ + void Rx_interrupt( void ); void itoa(int value, char *sp, int radix); + void stripSpace(char *str); + bool sync( void ); /** * * @@ -82,8 +76,14 @@ /** * * - */ + */ + void getString( char *str ); + /** + * + * + */ bool waitForCR( void ); + /** clear the screen */ void cls(void); @@ -92,12 +92,12 @@ void cls(int bColor); /** clear the screen with background color and forground color */ - void cls(int bColor, int fColor); + void cls(int bColor, int fColor); /** * */ void color( int color ); - + /** set text position in rows, columns * * @param col is the col coordinate @@ -183,20 +183,52 @@ * @param y is the number of vertical pixels */ void resolution(int x, int y); + /** + * + * + */ + int getXmax( void ); + /** + * + * + */ + int getYmax( void ); + void setStringID( int ID, char *str ); + void getStringID( int ID, char *str ); /** print string at current x y * @param string * * */ void print( char *str); - + /** + * + * + */ + //ameter [ID][x][y][width][height][options][value][min][max][theme][stringID][type] + void ameter( int ID, int x, int y, int w, int h, int options, int value, int min, int max, int theme, int stringID, int type); + /** + * + * + */ + void touchZone( int ID, int x, int y, int w, int h, bool option); + /** + * + * + */ + void button( int ID, int x, int y, int w, int h, int option, int align, int radius, int theme, int stringID ); + /** + * + * + */ + unsigned int wstack( int type ); /** Send a character directly to the serial interface - * @param c The character to send to the + * @param c The character to send to the */ int putc(int c); - + /** Receive a character directly to the serial interface - * @returns c The character received from the + * @returns c The character received from the */ int getc(); @@ -225,7 +257,7 @@ Font_Orient= 12, /**< Horizontal or vertical. */ Line_Width= 13, /**< 1 or 3. */ Line_Type= 14, /**< 1=dot dot 2=dash dash. */ - XY= 15, /**< X and Y. */ + XY= 15, /**< X and Y. */ StringID= 16, /**< SID ASCII String or File Name that * ends with 0. */ Plot= 17, /**< Place Pixel at X and Y. */ @@ -314,12 +346,11 @@ Wquiet= 113, Wstack= 114, }; - + private: Serial _ser; virtual int _putc(int c); virtual int _getc(); - int _xMax; int _yMax; int _firmware;