Library for EarthLCD ezLCD3xx line of products
Revision 5:4a6254e2012f, committed 2013-05-02
- Comitter:
- codeman
- Date:
- Thu May 02 02:32:26 2013 +0000
- Parent:
- 4:f4dde1f3baad
- Child:
- 6:83cada1140d4
- Commit message:
- pre 1.0;
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 29 04:44:16 2013 +0000 +++ b/ezLCDLib.cpp Thu May 02 02:32:26 2013 +0000 @@ -1,3 +1,13 @@ +/** +* +* +* +* +* +* +*/ + + #include "mbed.h" #include "ezLCDLib.h" @@ -32,8 +42,6 @@ // 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; @@ -212,7 +220,22 @@ _ser.putc('\r'); waitForCR(); } - +void ezLCD3::lineType( int type ) +{ + sendInt(Line_Type); + _ser.putc(' '); + sendInt(type); + _ser.putc('\r'); + waitForCR(); +} +void ezLCD3::lineWidth( int width ) +{ + sendInt(Line_Width); + _ser.putc(' '); + sendInt(width); + _ser.putc('\r'); + waitForCR(); +} void ezLCD3::circle(int radius, bool filled) { sendInt(Circle); @@ -298,13 +321,10 @@ void ezLCD3::print( char *str ) { -// unsigned char c; sendInt(Print); _ser.putc(' '); _ser.putc('\"'); sendString(str); -// while( (c = *str++) ) -// _ser.putc(c); _ser.putc('\"'); _ser.putc('\r'); waitForCR(); @@ -322,6 +342,53 @@ waitForCR(); } +void ezLCD3::font( char *str) +{ + sendInt(Font); + _ser.putc(' '); + sendString(str); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::fontO( bool dir ) +{ + sendInt(Font_Orient); + _ser.putc(' '); + if(dir) + _ser.putc('1'); + else + _ser.putc('0'); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::clipArea( int l, int t, int r, int b) +{ + sendInt(ClipArea); + _ser.putc(' '); + sendInt(l); + _ser.putc(' '); + sendInt(t); + _ser.putc(' '); + sendInt(r); + _ser.putc(' '); + sendInt(b); + _ser.putc(' '); + _ser.putc('\r'); + waitForCR(); +} +void ezLCD3::clipEnable( bool enable) +{ + sendInt(ClipEnable); + _ser.putc(' '); + if(enable) + _ser.putc('1'); + else + _ser.putc('0'); + _ser.putc('\r'); + +} void ezLCD3::theme(int ID, int EmbossDkColor, int EmbossLtColor, int TextColor0, int TextColor1, int TextColorDisabled, int Color0, int Color1, int ColorDisabled, int CommonBkColor, int Fontw) { sendInt(Widget_Theme); @@ -350,8 +417,29 @@ _ser.putc('\r'); waitForCR(); } +void ezLCD3::groupBox( int ID, int x, int y, int w, int h, int options, int theme, int stringID) +{ + sendInt(Set_Gbox); + _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(theme); + _ser.putc(' '); + sendInt(stringID); + _ser.putc('\r'); + waitForCR(); +} -//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); @@ -469,6 +557,33 @@ waitForCR(); } +void ezLCD3::slider(int ID, int x, int y, int w, int h, int option, int range, int res, int value, int theme) +{ + sendInt(Set_Slider); + _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(range); + _ser.putc(' '); + sendInt(res); + _ser.putc(' '); + sendInt(value); + _ser.putc(' '); + sendInt(theme); + _ser.putc('\r'); + waitForCR(); +} + void ezLCD3::image( int x, int y, char *str ) { sendInt(Picture);
--- a/ezLCDLib.h Mon Apr 29 04:44:16 2013 +0000 +++ b/ezLCDLib.h Thu May 02 02:32:26 2013 +0000 @@ -1,41 +1,11 @@ -/* - * - * +/* * @author Ken Segler - * + * @author ken@earthlcd.com + * @copyright 2013 Ken Segler + * @version 1.0 + * @date */ -/** Interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic -* LCD Serial Backpack, LCD-09352. Derived class from Serial so that you -* can conveniently printf(), putc(), etc to the display. -* -* Example: -* @code -* #include "mbed.h" -* #include "ezLCDLib.h" -* -* SerialGraphicLCD lcd(p26, p25); -* -* int main() { -* lcd.baud(115200); // default baud rate -* while (1) { -* lcd.clear(); -* lcd.rect(3, 3, 20, 20); -* lcd.printf("Hello World!"); -* lcd.pixel(14, 35, true); -* lcd.pixel(16, 36, true); -* lcd.pixel(18, 37, true); -* lcd.pos(5, 30); -* lcd.printf("Hi"); -* lcd.circle(50, 20, 20, true); -* lcd.pos(50, 20); -* lcd.printf("Howdy"); -* lcd.line(0, 0, 25, 25, true); -* wait(2); -* } -* } -* @endcode -*/ #ifndef _EZLCDLIB_H #define _EZLCDLIB_H @@ -49,12 +19,173 @@ #define ENABLE 1 #define DISABLE 2 #define REDRAW 3 + +/** Interface to the EarthLCD ezLCD3xx line of smart displays +* Derived class from Serial so that you +* can conveniently printf(), putc(), etc to the display. +* +* Example: +* @code +* #include "mbed.h" +* #include "TSISensor.h" +* #include "ezLCDLib.h" +* #include "MMA8451Q.h" +* +* #define MMA8451_I2C_ADDRESS (0x1d<<1) +* +* enum { BLACK, GRAY, SILVER, WHITE, RED, MAROON, YELLOW, OLIVE, LIME, GREEN, AQUA, TEAL, BLUE, NAVY, FUCHSIA, PURPLE }; +* #define arLCD +//InterruptIn ezLCD3Int( PTD7); // interrupt instance for touch +//InterruptIn ezLCD3Int( PTA13); // interrupt instance for touch +* #ifdef arLCD +* InterruptIn ezLCD3Int( PTD4 ); // interrupt instance for touch +* DigitalOut _nrst(PTC7); +* ezLCD3 lcd(PTA2, PTA1); //rx,tx +* TSISensor tsi; +* AnalogIn adc1(PTB0); +* MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); +* #endif +* +* DigitalOut myled(LED_BLUE); +* volatile bool ezLCD3Touch = false; +* +* int color = BLACK; +* int temp; +* int touch=0; +* int adc1Count = 0; +* float adc1Average = 0; +* +* char ezID[20]; +* char ezVER[20]; +* char adcBuf[20]; +* void ezLCD3Isr( void ) +* { + * ezLCD3Touch = true; +* } +* +* int main() +* { + * wait(3); + * while(!lcd.sync()); + * ezLCD3Int.fall(&ezLCD3Isr); + * ezLCD3Touch = false; + * myled=1; + * lcd.cls(BLACK); + * lcd.theme(0, 111, 106, 0, 130, 0, 13, 12, 101, 100, 0); + * lcd.xy(0,0);//11 + * lcd.color(BLACK); //1 + * lcd.box(319,239, 1 );//2 + * lcd.color(155); + * lcd.xy(1,1); + * lcd.line(317,1); + * lcd.xy(1,1); + * lcd.line(1,237); + * lcd.color(WHITE); + * lcd.xy(2,237); + * lcd.line(317,237); + * lcd.line(317,2); + * lcd.color(WHITE);//3 + * lcd.xy(300,100);//4 + * lcd.xy(300,200);//6 + * lcd.light(50);//8 + * lcd.xy(40,10);//9 + * lcd.print("--==[\\[28m Hello \\[65mMBED\\[28m World \\[3m]==--");//10 + * lcd.xy(20,100);//11 + * lcd.color(YELLOW);//12 + * lcd.setStringID( 2,"Button1"); + * lcd.setStringID( 3,"Button2"); + * lcd.button(2,20,40,100,40,1,0,10,0,2); + * lcd.button(3,200,40,100,40,1,0,10,0,3); + * lcd.getStringID( 65,ezID); + * lcd.getStringID( 66,ezVER); + * lcd.print(ezID); + * lcd.color(PURPLE); + * lcd.xy(20,120);//11 + * lcd.print(ezVER); + * lcd.color(TEAL); + * lcd.xy(20,140); + * lcd.printf("MaxX %d MaxY %d", lcd.getXmax()+1, lcd.getYmax()+1); //13 14 + * lcd.light(5);//15 + * lcd.light(100);//16 + * lcd.image(20,165,"0.gif"); + * lcd.image(55,165,"1.gif"); + * lcd.image(90,165,"2.gif"); + * lcd.image(125,165,"3.gif"); + * lcd.color(WHITE);//17 + * lcd.setStringID(4, "meter"); + * lcd.setStringID(5, "%"); + * lcd.setStringID(6, "X"); + * lcd.setStringID(7, "Y"); + * lcd.setStringID(8, "Z"); + * lcd.staticText( 4, 200, 210, 100, 25, 8, 0, 4); + * lcd.progressBar( 5, 200, 180, 100, 25, 1, 0, 100, 0 , 5); + * lcd.progressBar( 6, 200, 90, 100, 25, 1, 0, 100, 0 , 6); + * lcd.progressBar( 7, 200, 120, 100, 25, 1, 0, 100, 0 , 7); + * lcd.progressBar( 8, 200, 150, 100, 25, 1, 0, 100, 0 , 8); + * + * while(1) { + * if(ezLCD3Touch) { + * ezLCD3Touch = false; + * touch=lcd.wstack(LIFO); + * myled = !myled; + * lcd.xy(10,210); + * lcd.color(BLACK); + * lcd.box(180,20,1); + * lcd.color(WHITE); + * switch( touch ) { + * case 240: + * lcd.print("Button1 Pressed"); + * break; + * case 214: + * lcd.print("Button1 Released"); + * break; + * case 224: + * lcd.print("Button1 Cancel"); + * break; + * case 340: + * lcd.print("Button2 Pressed"); + * break; + * case 314: + * lcd.print("Button2 Released"); + * break; + * case 324: + * lcd.print("Button2 Cancel"); + * break; + * default: + * lcd.print("default"); + * break; + * + } + * + } + * adc1Average += adc1.read(); + * adc1Count ++; + * if (adc1Count == 500) { + * adc1Count=0; + * sprintf(adcBuf, "%1.3f V",(adc1Average/500)*3.3); + * lcd.setStringID(4, adcBuf); + * lcd.wstate(4,REDRAW); + * adc1Average =0; + * + } + * if(adc1Count ==250) { + * lcd.wvalue(5,abs( tsi.readPercentage()*100)); + * lcd.wvalue(6,abs(acc.getAccX())*100); + * lcd.wvalue(7,abs(acc.getAccY())*100); + * lcd.wvalue(8,abs(acc.getAccZ())*100); + * + } + * + } + * + * +} +* @endcode +*/ class ezLCD3: public Stream { public: - /** Create a new interface to a Serial Graphic LCD - * Note that the display lower left corner is coordinates 0, 0. - * Rows start at the top at 0, columns start at the left at 0. + /** Create a new interface to a ezLCD3xx display * @param tx -- mbed transmit pin * @param rx -- mbed receive pin */ @@ -64,189 +195,322 @@ * */ void Rx_interrupt( void ); + /** + * + * + */ void itoa(int value, char *sp, int radix); + /** + * + * + */ void stripSpace(char *str); - bool sync( void ); /** * * */ + bool sync( void ); + + /** Send a integer to the display + * @param i integer to send + */ void sendInt( int i ); - /** - * + + /** Get a integer from the display + * @param str string to put the data in * */ int getInt( char *str ); - /** - * + + /** Get a string from the display + * @param[out] str string to put the data in * */ void getString( char *str ); - /** - * + + /** Waits for a CR from display * */ bool waitForCR( void ); - /** clear the screen - */ + /** clear the screen to black + * + */ void cls(void); + /** clear the screen with background color - */ + * @param[in] bcolor Background color + */ void cls(int bColor); - /** clear the screen with background color and forground color - */ + + /** clear the screen with background color and drawing color + * + * @param[in] bColor background color + * @param[in] fColor drawing color + */ void cls(int bColor, int fColor); - /** - * + + /** Set drawing color + * @param[in] color color to draw with */ void color( int color ); - /** set text position in rows, columns + /** set x y position for drawing and text * - * @param col is the col coordinate - * @param row is the row coordinate - */ - void pos(int col, int row); - - /** set text position in x, y coordinates - * - * @param x is the x coordinate - * @param y is the y coordinate + * @param[in] x is the x coordinate + * @param[in] y is the y coordinate */ void xy(int x, int y); - /** set or erase a pixel + /** set pixel at current x y * - * @param x is the x coordinate - * @param y is the y coordinate */ void plot(void); - /** set or erase a pixel + /** set pixel in current draw color at x y * * @param x is the x coordinate * @param y is the y coordinate */ void plot(int x, int y); - /** draw or erase a line + /** draw line from current x y to new x y * - * @param x1 is the x coordinate of the start of the line - * @param y1 is the y coordinate of the start of the line + * @param x is the x coordinate + * @param y is the y coordinate */ - void line(int x1, int y1); + void line(int x, int y); - /** set or reset a circle + /** Set line drawing type + * @param type Options: 0 = solid, 1= dotted (1 pixel spacing between dots), 2 = dashed (2 pixel spacing between dashes) + * + * + */ + void lineType( int type ); + + /** Set line drawing width + * @param width in pixels + * + * + */ + void lineWidth( int width ); + /** Draw circle in current color at current x y * - * @param x is the x coordinate of the circle center - * @param y is the y coordinate of the circle center - * @param r is the radius of the circle - * @param set if true sets the pixel, if false, clears it + * @param radius diameter of circle + * @param filled true for a filled box outline if false */ void circle(int radius, bool filled); - /** draw a box + /** draw a box from current x y to new x y * - * @param x1 is the x coordinate of the upper left of the rectangle - * @param y1 is the y coordinate of the upper left of the rectangle - * @param Fill for filled box + * @param x + * @param y + * @param filled true for a filled box outline if false */ - void box(int x1, int y1, bool filled); + void box(int x, int y, bool filled); /** set backlight brightness * - * @param i is the duty cycle from 0 to 100; 0 is off, 100 is full power + * @param i is brightness 0=off 100=full in steps of 32 */ void light(int i); - /** + + /** Send a command direct to display + * @param str command string * - * + * Example:\n + * @code + * lcd.sendCommand( "cls" ); // clear display + * @endcode */ void sendCommand( char *str ); - /** - * + + /** Return Xmax of display + * @return int Xmax of display * */ int getXmax( void ); + + /** Return Ymax of display + * @return int Ymax of display + * + */ + int getYmax( void ); + + /** Send a string of data to display + * + */ + void sendString( char *str ); + + /** Set stringID to display + * @param ID string ID to write + * @param str string to write + * + */ + void setStringID( int ID, char *str ); + + /** Get stringID from Display + * @param ID string ID to read + * @param str string to put data in + * + * Example: + * @code + * lcd.getstringID(66, ezVer); // get ezLCD Firmware version + * lcd.print(ezVer); // print version + * @endcode + */ + void getStringID( int ID, char *str ); + + /** print string at current x y + * @param str string prints directly to display + */ + void print( char *str); + + /** Set widget font + * Fonts are located in the flash drive of the display\n + * font 0 and font 1 are builtin fonts and are much faster to draw\n + * in the /EZUSERS/FONTS and /EZSYS/FONTS directory\n + * use the ezLCD3xx font convert utilty to convert true type fonts + * @param str font name + */ + void fontw( int id, char *str); + /** * * + * */ - int getYmax( void ); - void sendString( char *str ); - void setStringID( int ID, char *str ); - void getStringID( int ID, char *str ); - /** print string at current x y - * @param string + void font(char *str); + + /** + * * * */ - void print( char *str); + void fontO( bool dir ); + /** * * + * */ - void fontw( int id, char *str); + void clipArea( int l, int t, int r, int b); + /** * * + * + */ + void clipEnable( bool enable ); + + /** Sets color themes for widgets + * + * */ void theme(int ID, int EmbossDkColor, int EmbossLtColor, int TextColor0, int TextColor1, int TextColorDisabled, int Color0, int Color1, int ColorDisabled, int CommonBkColor, int Fontw); + /** * * + * + */ + void groupBox( int ID, int x, int y, int width, int height, int options, int theme, int stringID) ; + + /** Analog Meter Widget + * + * */ //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); - /** + + /** Touchzone Widget * * */ void touchZone( int ID, int x, int y, int w, int h, bool option); - /** + + /** Button Widget * * */ void button( int ID, int x, int y, int w, int h, int option, int align, int radius, int theme, int stringID ); - /** - * - * + + /** Display Bitmap + * Display Bitmap at current x y \n + * supports GIF BMP JPG \n + * images are located in the /EZUSERS/FONTS and /EZSYS/FONTS directory + * @param str filename */ void image( char *str ); - /** - * - * + + /** Display Bitmap + * Display Bitmap at specfied x y \n + * supports GIF BMP JPG \n + * images are located in the /EZUSERS/FONTS and /EZSYS/FONTS directory + * @param x x location to start bitmap + * @param y y location to start bitmap + * @param str filename */ void image( int x, int y, char *str ); - /** + + /** StaticBox Widget * * * */ void staticText( int ID, int x, int y, int w, int h, int option, int theme, int stringID); - /** - * + + /** ProgressBar Widget + * @param ID + * @param x + * @param y + * @param w + * @param h + * @param option + * @param value + * @param max + * @param theme + * @param stringID * * */ void progressBar(int ID, int x, int y, int w, int h, int option, int value, int max, int theme, int stringID); - /** + + /** Slider Widget + * @param ID + * @param x + * @param y + * @param w + * @param h + * @param option + * @param range + * @param res + * @param value + * @param theme + * + */ + void slider(int ID, int x, int y, int w, int h, int option, int range, int res, int value, int theme); + /** wstate * * * */ void wstate( int ID, int option ); - /** - * - * + + /** Wvalue set widget values + * @param ID widget ID to update + * @param value widget value to update */ void wvalue( int ID, int value); - /** - * - * + + /** Wstack is a 32 level stack of widget events + * @param type LIFO - Get the last widget event off the stack + * @param type FIFO - Get the first widget event off the stack + * @param type CLEAR - Clear stack + * @returns widget id and even touch, release */ unsigned int wstack( int type ); + /** Send a character directly to the serial interface * @param c The character to send to the */ @@ -258,13 +522,7 @@ int getc(); /** - - * Numerical values for the EarthSEMPL commands. Provided here for - - * users who wish to compose EarthSEMPL commands manually. (This is a low- - - * level asset that is not required for the common uses of the device) - + * Numerical values for the EarthSEMPL commands. */ enum Commands { @@ -376,9 +634,6 @@ Serial _ser; virtual int _putc(int c); virtual int _getc(); - int _xMax; - int _yMax; - int _firmware; };