Library for EarthLCD ezLCD3xx line of products
Embed:
(wiki syntax)
Show/hide line numbers
ezLCDLib.h
00001 /* 00002 * @author Ken Segler 00003 * @author ken@earthlcd.com 00004 * @copyright 2013 Ken Segler 00005 * @version 1.0 00006 * @date 00007 */ 00008 00009 #ifndef _EZLCDLIB_H 00010 #define _EZLCDLIB_H 00011 00012 #include "mbed.h" 00013 00014 #define FIFO 0 00015 #define LIFO 1 00016 #define CLEAR 2 00017 00018 #define DELETE 0 00019 #define ENABLE 1 00020 #define DISABLE 2 00021 #define REDRAW 3 00022 00023 /** Interface to the EarthLCD ezLCD3xx line of smart displays 00024 * Derived class from Serial so that you 00025 * can conveniently printf(), putc(), etc to the display. 00026 * 00027 * Example: 00028 * @code 00029 * #include "mbed.h" 00030 * #include "TSISensor.h" 00031 * #include "ezLCDLib.h" 00032 * #include "MMA8451Q.h" 00033 * 00034 * #define MMA8451_I2C_ADDRESS (0x1d<<1) 00035 * 00036 * enum { BLACK, GRAY, SILVER, WHITE, RED, MAROON, YELLOW, OLIVE, LIME, GREEN, AQUA, TEAL, BLUE, NAVY, FUCHSIA, PURPLE }; 00037 * #define arLCD 00038 //InterruptIn ezLCD3Int( PTD7); // interrupt instance for touch 00039 //InterruptIn ezLCD3Int( PTA13); // interrupt instance for touch 00040 * #ifdef arLCD 00041 * InterruptIn ezLCD3Int( PTD4 ); // interrupt instance for touch 00042 * DigitalOut _nrst(PTC7); 00043 * ezLCD3 lcd(PTA2, PTA1); //rx,tx 00044 * TSISensor tsi; 00045 * AnalogIn adc1(PTB0); 00046 * MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); 00047 * #endif 00048 * 00049 * DigitalOut myled(LED_BLUE); 00050 * volatile bool ezLCD3Touch = false; 00051 * 00052 * int color = BLACK; 00053 * int temp; 00054 * int touch=0; 00055 * int adc1Count = 0; 00056 * float adc1Average = 0; 00057 * 00058 * char ezID[20]; 00059 * char ezVER[20]; 00060 * char adcBuf[20]; 00061 * void ezLCD3Isr( void ) 00062 * { 00063 * ezLCD3Touch = true; 00064 * } 00065 * 00066 * int main() 00067 * { 00068 * wait(3); 00069 * while(!lcd.sync()); 00070 * ezLCD3Int.fall(&ezLCD3Isr); 00071 * ezLCD3Touch = false; 00072 * myled=1; 00073 * lcd.cls(BLACK); 00074 * lcd.theme(0, 111, 106, 0, 130, 0, 13, 12, 101, 100, 0); 00075 * lcd.xy(0,0);//11 00076 * lcd.color(BLACK); //1 00077 * lcd.box(319,239, 1 );//2 00078 * lcd.color(155); 00079 * lcd.xy(1,1); 00080 * lcd.line(317,1); 00081 * lcd.xy(1,1); 00082 * lcd.line(1,237); 00083 * lcd.color(WHITE); 00084 * lcd.xy(2,237); 00085 * lcd.line(317,237); 00086 * lcd.line(317,2); 00087 * lcd.color(WHITE);//3 00088 * lcd.xy(300,100);//4 00089 * lcd.xy(300,200);//6 00090 * lcd.light(50);//8 00091 * lcd.xy(40,10);//9 00092 * lcd.print("--==[\\[28m Hello \\[65mMBED\\[28m World \\[3m]==--");//10 00093 * lcd.xy(20,100);//11 00094 * lcd.color(YELLOW);//12 00095 * lcd.setStringID( 2,"Button1"); 00096 * lcd.setStringID( 3,"Button2"); 00097 * lcd.button(2,20,40,100,40,1,0,10,0,2); 00098 * lcd.button(3,200,40,100,40,1,0,10,0,3); 00099 * lcd.getStringID( 65,ezID); 00100 * lcd.getStringID( 66,ezVER); 00101 * lcd.print(ezID); 00102 * lcd.color(PURPLE); 00103 * lcd.xy(20,120);//11 00104 * lcd.print(ezVER); 00105 * lcd.color(TEAL); 00106 * lcd.xy(20,140); 00107 * lcd.printf("MaxX %d MaxY %d", lcd.getXmax()+1, lcd.getYmax()+1); //13 14 00108 * lcd.light(5);//15 00109 * lcd.light(100);//16 00110 * lcd.image(20,165,"0.gif"); 00111 * lcd.image(55,165,"1.gif"); 00112 * lcd.image(90,165,"2.gif"); 00113 * lcd.image(125,165,"3.gif"); 00114 * lcd.color(WHITE);//17 00115 * lcd.setStringID(4, "meter"); 00116 * lcd.setStringID(5, "%"); 00117 * lcd.setStringID(6, "X"); 00118 * lcd.setStringID(7, "Y"); 00119 * lcd.setStringID(8, "Z"); 00120 * lcd.staticText( 4, 200, 210, 100, 25, 8, 0, 4); 00121 * lcd.progressBar( 5, 200, 180, 100, 25, 1, 0, 100, 0 , 5); 00122 * lcd.progressBar( 6, 200, 90, 100, 25, 1, 0, 100, 0 , 6); 00123 * lcd.progressBar( 7, 200, 120, 100, 25, 1, 0, 100, 0 , 7); 00124 * lcd.progressBar( 8, 200, 150, 100, 25, 1, 0, 100, 0 , 8); 00125 * 00126 * while(1) { 00127 * if(ezLCD3Touch) { 00128 * ezLCD3Touch = false; 00129 * touch=lcd.wstack(LIFO); 00130 * myled = !myled; 00131 * lcd.xy(10,210); 00132 * lcd.color(BLACK); 00133 * lcd.box(180,20,1); 00134 * lcd.color(WHITE); 00135 * switch( touch ) { 00136 * case 240: 00137 * lcd.print("Button1 Pressed"); 00138 * break; 00139 * case 214: 00140 * lcd.print("Button1 Released"); 00141 * break; 00142 * case 224: 00143 * lcd.print("Button1 Cancel"); 00144 * break; 00145 * case 340: 00146 * lcd.print("Button2 Pressed"); 00147 * break; 00148 * case 314: 00149 * lcd.print("Button2 Released"); 00150 * break; 00151 * case 324: 00152 * lcd.print("Button2 Cancel"); 00153 * break; 00154 * default: 00155 * lcd.print("default"); 00156 * break; 00157 * 00158 } 00159 * 00160 } 00161 * adc1Average += adc1.read(); 00162 * adc1Count ++; 00163 * if (adc1Count == 500) { 00164 * adc1Count=0; 00165 * sprintf(adcBuf, "%1.3f V",(adc1Average/500)*3.3); 00166 * lcd.setStringID(4, adcBuf); 00167 * lcd.wstate(4,REDRAW); 00168 * adc1Average =0; 00169 * 00170 } 00171 * if(adc1Count ==250) { 00172 * lcd.wvalue(5,abs( tsi.readPercentage()*100)); 00173 * lcd.wvalue(6,abs(acc.getAccX())*100); 00174 * lcd.wvalue(7,abs(acc.getAccY())*100); 00175 * lcd.wvalue(8,abs(acc.getAccZ())*100); 00176 * 00177 } 00178 * 00179 } 00180 * 00181 * 00182 } 00183 * @endcode 00184 */ 00185 class ezLCD3: public Stream 00186 { 00187 public: 00188 /** Create a new interface to a ezLCD3xx display 00189 * @param tx -- mbed transmit pin 00190 * @param rx -- mbed receive pin 00191 */ 00192 ezLCD3(PinName tx, PinName rx); 00193 /** 00194 * 00195 * 00196 */ 00197 void Rx_interrupt( void ); 00198 /** 00199 * 00200 * 00201 */ 00202 void itoa(int value, char *sp, int radix); 00203 /** 00204 * 00205 * 00206 */ 00207 void stripSpace(char *str); 00208 /** 00209 * 00210 * 00211 */ 00212 bool sync( void ); 00213 00214 /** Send a integer to the display 00215 * @param[in] i integer to send 00216 */ 00217 void sendInt( int i ); 00218 00219 /** Get a integer from the display 00220 * @param[out] str string to put the data in 00221 * 00222 */ 00223 int getInt( char *str ); 00224 00225 /** Get a string from the display 00226 * @param[out] str string to put the data in 00227 * 00228 */ 00229 void getString( char *str ); 00230 00231 /** Waits for a CR from display 00232 * 00233 */ 00234 bool waitForCR( void ); 00235 00236 /** clear the screen to black 00237 * 00238 */ 00239 void cls(void); 00240 00241 /** clear the screen with background color 00242 * @param[in] bcolor Background color 00243 */ 00244 void cls(int bColor); 00245 00246 /** clear the screen with background color and drawing color 00247 * 00248 * @param[in] bColor background color 00249 * @param[in] fColor drawing color 00250 */ 00251 void cls(int bColor, int fColor); 00252 00253 /** Set drawing color 00254 * @param[in] color color to draw with 00255 */ 00256 void color( int color ); 00257 00258 /** set x y position for drawing and text 00259 * 00260 * @param[in] x is the x coordinate 00261 * @param[in] y is the y coordinate 00262 */ 00263 void xy(int x, int y); 00264 00265 /** set pixel at current x y 00266 * 00267 */ 00268 void plot(void); 00269 00270 /** set pixel in current draw color at x y 00271 * 00272 * @param[in] x is the x coordinate 00273 * @param[in] y is the y coordinate 00274 */ 00275 void plot(int x, int y); 00276 00277 /** draw line from current x y to new x y 00278 * 00279 * @param[in] x is the x coordinate 00280 * @param[in] y is the y coordinate 00281 */ 00282 void line(int x, int y); 00283 00284 /** Set line drawing type 00285 * @param[in] type Options: 0 = solid, 1= dotted (1 pixel spacing between dots), 2 = dashed (2 pixel spacing between dashes) 00286 * 00287 * 00288 */ 00289 void lineType( int type ); 00290 00291 /** Set line drawing width 00292 * @param[in] width in pixels 00293 * 00294 * 00295 */ 00296 void lineWidth( int width ); 00297 /** Draw circle in current color at current x y 00298 * 00299 * @param[in] radius diameter of circle 00300 * @param[in] filled true for a filled box outline if false 00301 */ 00302 void circle(int radius, bool filled); 00303 00304 /** draw a box from current x y of width and heigth 00305 * 00306 * @param[in] width 00307 * @param[in] heigth 00308 * @param[in] filled true for a filled box outline if false 00309 */ 00310 void box(int width, int heigth, bool filled); 00311 00312 /** set backlight brightness 00313 * 00314 * @param[in] level is brightness 0=off 100=full in steps of 32 00315 */ 00316 void light(int level); 00317 00318 /** Send a command direct to display 00319 * @param str command string 00320 * 00321 * Example:\n 00322 * @code 00323 * lcd.sendCommand( "cls" ); // clear display 00324 * @endcode 00325 */ 00326 void sendCommand( char *str ); 00327 00328 /** Return Xmax of display 00329 * @return int Xmax of display 00330 * 00331 */ 00332 int getXmax( void ); 00333 00334 /** Return Ymax of display 00335 * @return int Ymax of display 00336 * 00337 */ 00338 int getYmax( void ); 00339 00340 /** Send a string of data to display 00341 * 00342 */ 00343 void sendString( char *str ); 00344 00345 /** Set stringID to display 00346 * @param ID string ID to write 00347 * @param str string to write 00348 * 00349 */ 00350 void setStringID( int ID, char *str ); 00351 00352 /** Get stringID from Display 00353 * @param ID string ID to read 00354 * @param str string to put data in 00355 * 00356 * Example: 00357 * @code 00358 * lcd.getstringID(66, ezVer); // get ezLCD Firmware version 00359 * lcd.print(ezVer); // print version 00360 * @endcode 00361 */ 00362 void getStringID( int ID, char *str ); 00363 00364 /** print string at current x y 00365 * @param str string prints directly to display 00366 */ 00367 void print( char *str); 00368 00369 /** Set widget font 00370 * Fonts are located in the flash drive of the display\n 00371 * font 0 and font 1 are builtin fonts and are much faster to draw\n 00372 * in the /EZUSERS/FONTS and /EZSYS/FONTS directory\n 00373 * use the ezLCD3xx font convert utilty to convert true type fonts 00374 * @param str font name 00375 */ 00376 void fontw( int id, char *str); 00377 00378 void fontw( int ID, int font); 00379 /** 00380 * 00381 * 00382 * 00383 */ 00384 void font(char *str); 00385 00386 /** 00387 * 00388 * 00389 * 00390 */ 00391 void fontO( bool dir ); 00392 00393 /** 00394 * 00395 * 00396 * 00397 */ 00398 void clipArea( int l, int t, int r, int b); 00399 00400 /** 00401 * 00402 * 00403 * 00404 */ 00405 void clipEnable( bool enable ); 00406 00407 /** Sets color themes for widgets 00408 * 00409 * 00410 */ 00411 void theme(int ID, int EmbossDkColor, int EmbossLtColor, int TextColor0, int TextColor1, int TextColorDisabled, int Color0, int Color1, int ColorDisabled, int CommonBkColor, int Fontw); 00412 00413 /** 00414 * 00415 * 00416 * 00417 */ 00418 void groupBox( int ID, int x, int y, int width, int height, int options, int theme, int stringID) ; 00419 00420 /** Analog Meter Widget 00421 * 00422 * 00423 */ 00424 //ameter [ID][x][y][width][height][options][value][min][max][theme][stringID][type] 00425 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); 00426 00427 /** Touchzone Widget 00428 * 00429 * 00430 */ 00431 void touchZone( int ID, int x, int y, int w, int h, bool option); 00432 00433 /** Button Widget 00434 * 00435 * 00436 */ 00437 void button( int ID, int x, int y, int w, int h, int option, int align, int radius, int theme, int stringID ); 00438 00439 /** Display Bitmap 00440 * Display Bitmap at current x y \n 00441 * supports GIF BMP JPG \n 00442 * images are located in the /EZUSERS/FONTS and /EZSYS/FONTS directory 00443 * @param str filename 00444 */ 00445 void image( char *str ); 00446 00447 /** Display Bitmap 00448 * Display Bitmap at specfied x y \n 00449 * supports GIF BMP JPG \n 00450 * images are located in the /EZUSERS/FONTS and /EZSYS/FONTS directory 00451 * @param x x location to start bitmap 00452 * @param y y location to start bitmap 00453 * @param str filename 00454 */ 00455 void image( int x, int y, char *str ); 00456 00457 /** StaticBox Widget 00458 * 00459 * 00460 * 00461 */ 00462 void staticText( int ID, int x, int y, int w, int h, int option, int theme, int stringID); 00463 00464 /** ProgressBar Widget 00465 * @param ID 00466 * @param x 00467 * @param y 00468 * @param w 00469 * @param h 00470 * @param option 00471 * @param value 00472 * @param max 00473 * @param theme 00474 * @param stringID 00475 * 00476 * 00477 */ 00478 void progressBar(int ID, int x, int y, int w, int h, int option, int value, int max, int theme, int stringID); 00479 00480 /** Slider Widget 00481 * @param ID 00482 * @param x 00483 * @param y 00484 * @param w 00485 * @param h 00486 * @param option 00487 * @param range 00488 * @param res 00489 * @param value 00490 * @param theme 00491 * 00492 */ 00493 void slider(int ID, int x, int y, int w, int h, int option, int range, int res, int value, int theme); 00494 /** wstate 00495 * 00496 * 00497 * 00498 */ 00499 void wstate( int ID, int option ); 00500 00501 /** Wvalue set widget values 00502 * @param ID widget ID to update 00503 * @param value widget value to update 00504 */ 00505 void wvalue( int ID, int value); 00506 00507 /** Wstack is a 32 level stack of widget events 00508 * @param type LIFO - Get the last widget event off the stack 00509 * @param type FIFO - Get the first widget event off the stack 00510 * @param type CLEAR - Clear stack 00511 * @returns widget id and even touch, release 00512 */ 00513 unsigned int wstack( int type ); 00514 00515 /** Send a character directly to the serial interface 00516 * @param c The character to send to the 00517 */ 00518 int putc(int c); 00519 00520 /** Receive a character directly to the serial interface 00521 * @returns c The character received from the 00522 */ 00523 int getc(); 00524 00525 /** 00526 * Numerical values for the EarthSEMPL commands. 00527 */ 00528 00529 enum Commands { 00530 Command= 0, /**< Direct command. */ 00531 Status= 1, 00532 Clr_Screen= 2, /**< Clear to provided color. */ 00533 Ping= 3, /**< Return Pong */ 00534 zBeep= 4, /**< Beep provided duration 00535 *(frequency fixed) */ 00536 Light= 5, /**< \c 0 (off) to \c 100 (on) */ 00537 Color= 6, 00538 eColor_ID= 7, 00539 Font= 10, /**< Font number. */ 00540 Fontw= 11, /**< Font number widget. */ 00541 Font_Orient= 12, /**< Horizontal or vertical. */ 00542 Line_Width= 13, /**< 1 or 3. */ 00543 Line_Type= 14, /**< 1=dot dot 2=dash dash. */ 00544 XY= 15, /**< X and Y. */ 00545 StringID= 16, /**< SID ASCII String or File Name that 00546 * ends with 0. */ 00547 Plot= 17, /**< Place Pixel at X and Y. */ 00548 Line= 18, /**< Draw a line to X and Y. */ 00549 Box= 19, /**< Draws a Box to X and Y optional 00550 * fill. */ 00551 Circle= 20, /**< Draws a Circle with Radius optional 00552 * fill */ 00553 Arc= 21, /**< Draws an Arc with Radius and Begin 00554 * Angle to End Angle. */ 00555 Pie= 22, /**< Draws a Pie figure with Radius and 00556 * Begin Angle to End Angle and fills 00557 * it. */ 00558 Picture= 24, /**< Places a Picture on display. */ 00559 Print= 25, /**< Places the string on display which 00560 * ends with 0. */ 00561 Beep_Freq= 26, /**< Set the beeper frequency. */ 00562 Calibrate= 28, /**< Calibrate touch screen. */ 00563 zReset= 29, /**< Reset. */ 00564 Rec_Macro= 30, /**< Record Macro to flash drive. */ 00565 Play_Macro= 31, /**< Play Macro. */ 00566 Stop_Macro= 32, /**< Stop Macro. */ 00567 Pause_Macro= 33, /**< Pause n msec. */ 00568 Loop_Macro= 34, /**< Loop on Macro. */ 00569 Speed_Macro= 35, /**< Set the macro speed. */ 00570 Peri= 36, 00571 ConfigIO= 37, 00572 IO= 38, 00573 IOG= 39, 00574 Security= 40, /**< Set drive security string. */ 00575 Location= 41, /**< LID Location Vlaue. */ 00576 Upgrade= 43, 00577 Parameters= 45, 00578 ClipEnable= 46, /**< Set clip Enable. */ 00579 ClipArea= 47, /**< Set clip area. */ 00580 /* Filesystem operations */ 00581 Comment= 50, 00582 Fsgetcwd= 51, 00583 Fschdir= 52, 00584 Fsmkdir= 53, 00585 Fsrmdir= 54, 00586 Fsdir= 55, 00587 Fscopy= 56, 00588 Fsrename= 57, 00589 Fsremove= 58, 00590 Fsmore= 59, 00591 Format= 60, /**< Format Flash Drive if string1 = 00592 * "ezLCD" */ 00593 If= 61, 00594 Cmd= 62, 00595 /* Widget commands */ 00596 Set_Button= 70, /**< Widget Button. */ 00597 Set_CheckBox= 71, /**< Widget Checkbox. */ 00598 Set_Gbox= 72, /**< Widget Group Box. */ 00599 Set_RadioButton= 73, /**< Widget Radio Button. */ 00600 Set_DMeter= 74, /**< Widget Digital Meter. */ 00601 DMeter_Value= 75, /**< Set DMeter value. */ 00602 Set_AMeter= 76, /**< Widget Analog Meter. */ 00603 AMeter_Value= 77, /**< Set AMeter value. */ 00604 AMeter_Color= 78, /**< Set AMeter color */ 00605 Set_TouchZone= 79, /**< touch zone */ 00606 Set_Dial= 80, /**< Widget RoundDial. */ 00607 Set_Slider= 82, /**< Widget Slider. */ 00608 Set_Progress= 85, /**< Widget Progress bar. */ 00609 Progress_Value= 86, /**< Progress value. */ 00610 Set_StaticText= 87, /**< Widget Static text. */ 00611 StaticText_Value= 88, /**< Static text Value. */ 00612 Choice= 89, /**< Widget get choice. */ 00613 Widget_Theme= 90, /**< Widget Scheme. */ 00614 Widget_Values= 91, /**<Widget Values (Slider and Dial in this version).*/ 00615 Widget_State= 92, /**<Widget State (Button, checkbox, radiobutton in this version).*/ 00616 // no id returns the id of the last touched 00617 Mode= 98, 00618 Comport= 99, 00619 Xmax= 100, /**< Return Xmax width. */ 00620 Ymax= 101, /**< Return Ymax height. */ 00621 Wait= 102, /**< Wait for touch. */ 00622 Waitn= 103, /**< Wait for no touch. */ 00623 Waitt= 104, /**< Wait for touch. */ 00624 Threshold= 105, /**< Touch threshold. */ 00625 Verbose= 106, /**< Controls the verbose mode. */ 00626 Lecho= 107, /**< Controls the echo mode. */ 00627 Xtouch= 110, /**< return touchX. */ 00628 Ytouch= 111, /**< return touchY. */ 00629 Stouch= 112, /**< return touchS. */ 00630 Wquiet= 113, 00631 Wstack= 114, 00632 }; 00633 00634 private: 00635 Serial _ser; 00636 virtual int _putc(int c); 00637 virtual int _getc(); 00638 }; 00639 00640 00641 #endif
Generated on Wed Jul 13 2022 05:25:49 by 1.7.2