Ryan Scott / menuSystemMbedBroken

Dependencies:   ANSITermMenuSystem

Fork of menuSystemMbed by Ryan Scott

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SerialGraphicLCD.h Source File

SerialGraphicLCD.h

00001 /* Serial Graphics LCD Driver for Sparkfun Serial Graphics LCD, LCD-09351; and Graphic 
00002  * LCD Serial Backpack, LCD-09352.
00003  *
00004  * @author Michael Shimniok http://www.bot-thoughts.com/
00005  *
00006  */
00007 #ifndef _SERIALGRAPHICLCD_H
00008 #define _SERIALGRAPHICLCD_H
00009 
00010 #include "mbed.h"
00011 
00012 /** Firmware modes */
00013 #define SFE_FW 0        // Stock SFE firmware
00014 #define SD_FW  1        // summoningdark firmware http://sourceforge.net/projects/serialglcd/
00015 
00016 /** LCD Baud Rates */
00017 #define LCD_4800   1
00018 #define LCD_9600   2
00019 #define LCD_19200  3
00020 #define LCD_38400  4
00021 #define LCD_57600  5
00022 #define LCD_115200 6
00023 
00024 /** LCD Types */
00025 #define LCD_128x64  1
00026 #define LCD_160x128 2
00027 
00028 /** Interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic 
00029  * LCD Serial Backpack, LCD-09352. Derived class from Serial so that you
00030  * can conveniently printf(), putc(), etc to the display.
00031  * 
00032  * Example:
00033  * @code
00034  * #include "mbed.h"
00035  * #include "SerialGraphicLCD.h"
00036  * 
00037  * SerialGraphicLCD lcd(p26, p25);
00038  * 
00039  * int main() {
00040  *   lcd.baud(115200); // default baud rate
00041  *   while (1) {
00042  *      lcd.clear();
00043  *      lcd.rect(3, 3, 20, 20);
00044  *      lcd.printf("Hello World!");
00045  *      lcd.pixel(14, 35, true);
00046  *      lcd.pixel(16, 36, true);
00047  *      lcd.pixel(18, 37, true);
00048  *      lcd.pos(5, 30);
00049  *      lcd.printf("Hi");
00050  *      lcd.circle(50, 20, 20, true);
00051  *      lcd.pos(50, 20);
00052  *      lcd.printf("Howdy");
00053  *      lcd.line(0, 0, 25, 25, true);
00054  *      wait(2);
00055  *   }
00056  * }
00057  * @endcode
00058  */
00059 class SerialGraphicLCD: public Serial {
00060 public:
00061     /** Create a new interface to a Serial Graphic LCD
00062      * Note that the display lower left corner is coordinates 0, 0.
00063      * Rows start at the top at 0, columns start at the left at 0.
00064      * @param tx -- mbed transmit pin
00065      * @param rx -- mbed receive pin
00066      */
00067     SerialGraphicLCD(PinName tx, PinName rx);
00068     
00069     /** Create a new interface to a Serial Graphic LCD
00070      * Note that the display lower left corner is coordinates 0, 0.
00071      * Rows start at the top at 0, columns start at the left at 0.
00072      * @param tx -- mbed transmit pin
00073      * @param rx -- mbed receive pin
00074      * @param firmware -- SFE_FW, stock firmware or SD_FW, summoningdark firmware
00075      */
00076     SerialGraphicLCD(PinName tx, PinName rx, int firmware);
00077 
00078     /** clear the screen
00079      */
00080     void clear(void);
00081 
00082     /** set text position in rows, columns
00083      *
00084      * @param col is the col coordinate
00085      * @param row is the row coordinate
00086      */
00087     void pos(int col, int row);
00088     
00089     /** set text position in x, y coordinates
00090      *
00091      * @param x is the x coordinate
00092      * @param y is the y coordinate
00093      */
00094     void posXY(int x, int y);
00095     
00096     /** set or erase a pixel
00097      *
00098      * @param x is the x coordinate
00099      * @param y is the y coordinate
00100      * @param set if true sets the pixel, if false, erases it
00101      */
00102     void pixel(int x, int y, bool set);
00103     
00104     /** draw or erase a line
00105      *
00106      * @param x1 is the x coordinate of the start of the line
00107      * @param y1 is the y coordinate of the start of the line
00108      * @param x2 is the x coordinate of the end of the line
00109      * @param y2 is the y coordinate of the end of the line
00110      * @param set if true sets the line, if false, erases it
00111      */
00112     void line(int x1, int y1, int x2, int y2, bool set);
00113     
00114     /** set or reset a circle
00115      *
00116      * @param x is the x coordinate of the circle center
00117      * @param y is the y coordinate of the circle center
00118      * @param r is the radius of the circle
00119      * @param set if true sets the pixel, if false, clears it
00120      */
00121     void circle(int x, int y, int r, bool set);
00122     
00123     /** draw or erase a rectangle
00124      *
00125      * @param x1 is the x coordinate of the upper left of the rectangle
00126      * @param y1 is the y coordinate of the upper left of the rectangle
00127      * @param x2 is the x coordinate of the lower right of the rectangle
00128      * @param y2 is the y coordinate of the lower right of the rectangle
00129      */
00130     void rect(int x1, int y1, int x2, int y2);
00131     
00132     /** erase a rectangular area
00133      *
00134      * @param x1 is the x coordinate of the upper left of the area
00135      * @param y1 is the y coordinate of the upper left of the area
00136      * @param x2 is the x coordinate of the lower right of the area
00137      * @param y2 is the y coordinate of the lower right of the area
00138      */
00139     void erase(int x1, int y1, int x2, int y2);
00140     
00141     /** set backlight duty cycle
00142      *
00143      * @param i is the duty cycle from 0 to 100; 0 is off, 100 is full power
00144      */
00145     void backlight(int i);
00146     
00147     /** clear screen and put in reverse mode
00148      */
00149     void reverseMode(void);
00150 
00151     /** configure the lcd baud rate so you have to call this along with baud() to change
00152      * communication speeds
00153      *
00154      * @param b is the baud rate, LCD_4800, LCD_9600, LCD_19200, LCD_38400, LCD_57600 or LCD_115200
00155      */
00156     void lcdbaud(int b);
00157     
00158     
00159     /** sets the resolution of the LCD so that the pos() call works properly
00160      * defaults to LCD_128x64.
00161      *
00162      * @param type is the type of LCD, either LCD_128x64 or LCD_160x128
00163      */
00164     void resolution(int type);
00165 
00166     /** sets the resolution of the LCD in x and y coordinates which determines
00167      * how rows and columns are calculated in the pos() call.  Defaults to
00168      * x=128, y=64
00169      *
00170      * @param x is the number of horizontal pixels
00171      * @param y is the number of vertical pixels
00172      */
00173     void resolution(int x, int y);
00174     
00175     private:
00176         int _xMax;
00177         int _yMax;
00178         int _firmware;
00179 };
00180 
00181 
00182 #endif