Library for EarthLCD ezLCD3xx line of products
Revision 0:65606abcae36, committed 2013-04-22
- Comitter:
- codeman
- Date:
- Mon Apr 22 06:33:57 2013 +0000
- Child:
- 1:c7659c8af0d3
- Commit message:
- first one 4/22/2013
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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ezLCDLib.cpp Mon Apr 22 06:33:57 2013 +0000 @@ -0,0 +1,285 @@ +#include "mbed.h" +#include "ezLCDLib.h" + +#define XSIZE 6 +#define YSIZE 9 +#define BUFF_LEN 10 +ezLCD3::ezLCD3(PinName tx, PinName rx) : Stream("ezLCD3") , _ser(tx, rx) +{ + _ser.baud(115200); // default baud rate +} + + +/* itoa: convert n to characters in s */ +void ezLCD3::itoa(int value, char *sp, int radix) +{ + char tmp[16];// be careful with the length of the buffer + char *tp = tmp; + int i; + unsigned v; + int sign; + + sign = (radix == 10 && value < 0); + if (sign) v = -value; + else v = (unsigned)value; + + while (v || tp == tmp) { + i = v % radix; + v /= radix; // v/=radix uses less CPU clocks than v=v/radix does + if (i < 10) + *tp++ = i+'0'; + else + *tp++ = i + 'a' - 10; + } + + if (sign) + *sp++ = '-'; + while (tp > tmp) + *sp++ = *--tp; +} +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]); +} +/* +int ezLCD3::getInt( char *str ) +{ + return atoi(str); +} +void ezLCD3::getString( char *str ) +{ + char value[5]= {0, 0, 0, 0, 0}; + int counter; + +} +*/ +bool ezLCD3::waitForCR( void ) +{ + while(! _ser.readable()); + if(_ser.getc() == '\r') + return true; + else + return false; +} + +void ezLCD3::cls() +{ + sendInt(Clr_Screen); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::cls(int bColor) +{ + sendInt(Clr_Screen); + _ser.putc(' '); + sendInt(bColor); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::cls(int bColor, int fColor) +{ + sendInt(Clr_Screen); + _ser.putc(' '); + sendInt(bColor); + _ser.putc(' '); + sendInt(fColor); + _ser.putc('\r'); + waitForCR(); +} +void ezLCD3::color(int fColor) +{ + sendInt(Color); + _ser.putc(' '); + sendInt(fColor); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::pos(int col, int row) +{ + //posXY(XSIZE*col, (YSIZE*row)); +} + +void ezLCD3::xy(int x, int y) +{ + sendInt(XY); + _ser.putc(' '); + sendInt(x); + _ser.putc(' '); + sendInt(y); + _ser.putc('\r'); +} + +void ezLCD3::plot( void ) +{ + sendInt(Plot); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::plot( int x, int y ) +{ + sendInt(Plot); + _ser.putc(' '); + sendInt(x); + _ser.putc(' '); + sendInt(y); + _ser.putc('\r'); + waitForCR(); +} +void ezLCD3::line(int x, int y ) +{ + sendInt(Line); + _ser.putc(' '); + sendInt(x); + _ser.putc(' '); + sendInt(y); + _ser.putc('\r'); + waitForCR(); + +} + +void ezLCD3::circle(int radius, bool filled) +{ + sendInt(Circle); + _ser.putc(' '); + sendInt(radius); + if(filled) { + _ser.putc(' '); + _ser.putc('f'); + } + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::box(int x, int y, bool filled) +{ + sendInt(Box); + _ser.putc(' '); + sendInt(x); + _ser.putc(' '); + sendInt(y); + if(filled) { + _ser.putc(' '); + _ser.putc('f'); + } + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::light(int i) +{ + if (i >= 0 && i <= 100) { + sendInt(Light); + putc(' '); + sendInt( i ); + putc('\r'); + waitForCR(); + } +} +/* +int ezLCD3::getMaxX( void ) +{ + sendInt(Xmax); + putc('\r'); + waitForCR(); + +} +int ezLCD3::getMaxY( void ) +{ + sendInt(Ymax); + putc('\r'); + waitForCR(); +} + +void ezLCD3::string( int ID ) { + +} + +void ezLCD3::string( int ID , char *str) { + +} +*/ +void ezLCD3::reverseMode() +{ + putc(0x7c); + putc(0x12); +} + +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 ) +{ + unsigned char c; + sendInt(Print); + _ser.putc(' '); + _ser.putc('\"'); + while( (c = *str++) ) + _ser.putc(c); + _ser.putc('\"'); + _ser.putc('\r'); + waitForCR(); +} + +void ezLCD3::resolution(int x, int y) +{ + _xMax = x; + _yMax = y; +} + +int ezLCD3::_putc( int c) +{ + _ser.putc('2'); + _ser.putc('5'); + _ser.putc(' '); + _ser.putc('\"'); + _ser.putc(c); + _ser.putc('\"'); + _ser.putc('\r'); + waitForCR(); + return (c); +} + +int ezLCD3::_getc(void) +{ + char r = 0; + return(r); +} + +int ezLCD3::putc ( int c ) +{ + return(_ser.putc(c)); +} + +int ezLCD3::getc (void) +{ + return(_ser.getc()); +} + +void ezLCD3::lcdbaud(int b) +{ + if (b > 0 && b < 7) { + putc(0x7c); + putc(0x07); + putc(b+'0'); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ezLCDLib.h Mon Apr 22 06:33:57 2013 +0000 @@ -0,0 +1,329 @@ +/* + * + * + * @author Ken Segler + * + */ + +/** 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 + +#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 + +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. + * @param tx -- mbed transmit pin + * @param rx -- mbed receive pin + */ + ezLCD3(PinName tx, PinName rx); + /** + * + * + */ + void itoa(int value, char *sp, int radix); + /** + * + * + */ + void sendInt( int i ); + /** + * + * + */ + int getInt( char *str ); + /** + * + * + */ + bool waitForCR( void ); + /** clear the screen + */ + void cls(void); + /** clear the screen with background color + */ + void cls(int bColor); + /** clear the screen with background color and forground color + */ + void cls(int bColor, int fColor); + /** + * + */ + void color( int color ); + + /** set text position in rows, columns + * + * @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 + */ + void xy(int x, int y); + + /** set or erase a pixel + * + * @param x is the x coordinate + * @param y is the y coordinate + */ + void plot(void); + + /** set or erase a pixel + * + * @param x is the x coordinate + * @param y is the y coordinate + */ + void plot(int x, int y); + + /** draw or erase a line + * + * @param x1 is the x coordinate of the start of the line + * @param y1 is the y coordinate of the start of the line + */ + void line(int x1, int y1); + + /** set or reset a circle + * + * @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 + */ + void circle(int radius, bool filled); + + /** draw a box + * + * @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 + */ + void box(int x1, int y1, bool filled); + + /** set backlight brightness + * + * @param i is the duty cycle from 0 to 100; 0 is off, 100 is full power + */ + void light(int i); + + /** clear screen and put in reverse mode + */ + void reverseMode(void); + + /** configure the lcd baud rate so you have to call this along with baud() to change + * communication speeds + * + * @param b is the baud rate, LCD_4800, LCD_9600, LCD_19200, LCD_38400, LCD_57600 or LCD_115200 + */ + void lcdbaud(int b); + + + /** sets the resolution of the LCD so that the pos() call works properly + * defaults to LCD_128x64. + * + * @param type is the type of LCD, either LCD_128x64 or LCD_160x128 + */ + void resolution(int type); + + /** sets the resolution of the LCD in x and y coordinates which determines + * how rows and columns are calculated in the pos() call. Defaults to + * x=128, y=64 + * + * @param x is the number of horizontal pixels + * @param y is the number of vertical pixels + */ + void resolution(int x, int y); + /** print string at current x y + * @param string + * + * + */ + void print( char *str); + + /** Send a character directly to the serial interface + * @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 + */ + 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) + + */ + + enum Commands { + Command= 0, /**< Direct command. */ + Status= 1, + Clr_Screen= 2, /**< Clear to provided color. */ + Ping= 3, /**< Return Pong */ + zBeep= 4, /**< Beep provided duration + *(frequency fixed) */ + Light= 5, /**< \c 0 (off) to \c 100 (on) */ + Color= 6, + eColor_ID= 7, + Font= 10, /**< Font number. */ + Fontw= 11, /**< Font number widget. */ + 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. */ + StringID= 16, /**< SID ASCII String or File Name that + * ends with 0. */ + Plot= 17, /**< Place Pixel at X and Y. */ + Line= 18, /**< Draw a line to X and Y. */ + Box= 19, /**< Draws a Box to X and Y optional + * fill. */ + Circle= 20, /**< Draws a Circle with Radius optional + * fill */ + Arc= 21, /**< Draws an Arc with Radius and Begin + * Angle to End Angle. */ + Pie= 22, /**< Draws a Pie figure with Radius and + * Begin Angle to End Angle and fills + * it. */ + Picture= 24, /**< Places a Picture on display. */ + Print= 25, /**< Places the string on display which + * ends with 0. */ + Beep_Freq= 26, /**< Set the beeper frequency. */ + Calibrate= 28, /**< Calibrate touch screen. */ + zReset= 29, /**< Reset. */ + Rec_Macro= 30, /**< Record Macro to flash drive. */ + Play_Macro= 31, /**< Play Macro. */ + Stop_Macro= 32, /**< Stop Macro. */ + Pause_Macro= 33, /**< Pause n msec. */ + Loop_Macro= 34, /**< Loop on Macro. */ + Speed_Macro= 35, /**< Set the macro speed. */ + Peri= 36, + ConfigIO= 37, + IO= 38, + IOG= 39, + Security= 40, /**< Set drive security string. */ + Location= 41, /**< LID Location Vlaue. */ + Upgrade= 43, + Parameters= 45, + ClipEnable= 46, /**< Set clip Enable. */ + ClipArea= 47, /**< Set clip area. */ + /* Filesystem operations */ + Comment= 50, + Fsgetcwd= 51, + Fschdir= 52, + Fsmkdir= 53, + Fsrmdir= 54, + Fsdir= 55, + Fscopy= 56, + Fsrename= 57, + Fsremove= 58, + Fsmore= 59, + Format= 60, /**< Format Flash Drive if string1 = + * "ezLCD" */ + If= 61, + Cmd= 62, + /* Widget commands */ + Set_Button= 70, /**< Widget Button. */ + Set_CheckBox= 71, /**< Widget Checkbox. */ + Set_Gbox= 72, /**< Widget Group Box. */ + Set_RadioButton= 73, /**< Widget Radio Button. */ + Set_DMeter= 74, /**< Widget Digital Meter. */ + DMeter_Value= 75, /**< Set DMeter value. */ + Set_AMeter= 76, /**< Widget Analog Meter. */ + AMeter_Value= 77, /**< Set AMeter value. */ + AMeter_Color= 78, /**< Set AMeter color */ + Set_TouchZone= 79, /**< touch zone */ + Set_Dial= 80, /**< Widget RoundDial. */ + Set_Slider= 82, /**< Widget Slider. */ + Set_Progress= 85, /**< Widget Progress bar. */ + Progress_Value= 86, /**< Progress value. */ + Set_StaticText= 87, /**< Widget Static text. */ + StaticText_Value= 88, /**< Static text Value. */ + Choice= 89, /**< Widget get choice. */ + Widget_Theme= 90, /**< Widget Scheme. */ + Widget_Values= 91, /**<Widget Values (Slider and Dial in this version).*/ + Widget_State= 92, /**<Widget State (Button, checkbox, radiobutton in this version).*/ + // no id returns the id of the last touched + Mode= 98, + Comport= 99, + Xmax= 100, /**< Return Xmax width. */ + Ymax= 101, /**< Return Ymax height. */ + Wait= 102, /**< Wait for touch. */ + Waitn= 103, /**< Wait for no touch. */ + Waitt= 104, /**< Wait for touch. */ + Threshold= 105, /**< Touch threshold. */ + Verbose= 106, /**< Controls the verbose mode. */ + Lecho= 107, /**< Controls the echo mode. */ + Xtouch= 110, /**< return touchX. */ + Ytouch= 111, /**< return touchY. */ + Stouch= 112, /**< return touchS. */ + Wquiet= 113, + Wstack= 114, + }; + +private: + Serial _ser; + virtual int _putc(int c); + virtual int _getc(); + + int _xMax; + int _yMax; + int _firmware; +}; + + +#endif \ No newline at end of file