Menu system broken
Dependencies: ANSITermMenuSystem
Fork of menuSystemMbed by
SerialGraphicLCD.h@8:6ddb8c26387a, 2013-05-04 (annotated)
- Committer:
- Rybowonder
- Date:
- Sat May 04 17:37:57 2013 +0000
- Revision:
- 8:6ddb8c26387a
- Parent:
- 4:1178a1905490
For Mitchener
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rybowonder | 4:1178a1905490 | 1 | /* Serial Graphics LCD Driver for Sparkfun Serial Graphics LCD, LCD-09351; and Graphic |
Rybowonder | 4:1178a1905490 | 2 | * LCD Serial Backpack, LCD-09352. |
Rybowonder | 4:1178a1905490 | 3 | * |
Rybowonder | 4:1178a1905490 | 4 | * @author Michael Shimniok http://www.bot-thoughts.com/ |
Rybowonder | 4:1178a1905490 | 5 | * |
Rybowonder | 4:1178a1905490 | 6 | */ |
Rybowonder | 4:1178a1905490 | 7 | #ifndef _SERIALGRAPHICLCD_H |
Rybowonder | 4:1178a1905490 | 8 | #define _SERIALGRAPHICLCD_H |
Rybowonder | 4:1178a1905490 | 9 | |
Rybowonder | 4:1178a1905490 | 10 | #include "mbed.h" |
Rybowonder | 4:1178a1905490 | 11 | |
Rybowonder | 4:1178a1905490 | 12 | /** Firmware modes */ |
Rybowonder | 4:1178a1905490 | 13 | #define SFE_FW 0 // Stock SFE firmware |
Rybowonder | 4:1178a1905490 | 14 | #define SD_FW 1 // summoningdark firmware http://sourceforge.net/projects/serialglcd/ |
Rybowonder | 4:1178a1905490 | 15 | |
Rybowonder | 4:1178a1905490 | 16 | /** LCD Baud Rates */ |
Rybowonder | 4:1178a1905490 | 17 | #define LCD_4800 1 |
Rybowonder | 4:1178a1905490 | 18 | #define LCD_9600 2 |
Rybowonder | 4:1178a1905490 | 19 | #define LCD_19200 3 |
Rybowonder | 4:1178a1905490 | 20 | #define LCD_38400 4 |
Rybowonder | 4:1178a1905490 | 21 | #define LCD_57600 5 |
Rybowonder | 4:1178a1905490 | 22 | #define LCD_115200 6 |
Rybowonder | 4:1178a1905490 | 23 | |
Rybowonder | 4:1178a1905490 | 24 | /** LCD Types */ |
Rybowonder | 4:1178a1905490 | 25 | #define LCD_128x64 1 |
Rybowonder | 4:1178a1905490 | 26 | #define LCD_160x128 2 |
Rybowonder | 4:1178a1905490 | 27 | |
Rybowonder | 4:1178a1905490 | 28 | /** Interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic |
Rybowonder | 4:1178a1905490 | 29 | * LCD Serial Backpack, LCD-09352. Derived class from Serial so that you |
Rybowonder | 4:1178a1905490 | 30 | * can conveniently printf(), putc(), etc to the display. |
Rybowonder | 4:1178a1905490 | 31 | * |
Rybowonder | 4:1178a1905490 | 32 | * Example: |
Rybowonder | 4:1178a1905490 | 33 | * @code |
Rybowonder | 4:1178a1905490 | 34 | * #include "mbed.h" |
Rybowonder | 4:1178a1905490 | 35 | * #include "SerialGraphicLCD.h" |
Rybowonder | 4:1178a1905490 | 36 | * |
Rybowonder | 4:1178a1905490 | 37 | * SerialGraphicLCD lcd(p26, p25); |
Rybowonder | 4:1178a1905490 | 38 | * |
Rybowonder | 4:1178a1905490 | 39 | * int main() { |
Rybowonder | 4:1178a1905490 | 40 | * lcd.baud(115200); // default baud rate |
Rybowonder | 4:1178a1905490 | 41 | * while (1) { |
Rybowonder | 4:1178a1905490 | 42 | * lcd.clear(); |
Rybowonder | 4:1178a1905490 | 43 | * lcd.rect(3, 3, 20, 20); |
Rybowonder | 4:1178a1905490 | 44 | * lcd.printf("Hello World!"); |
Rybowonder | 4:1178a1905490 | 45 | * lcd.pixel(14, 35, true); |
Rybowonder | 4:1178a1905490 | 46 | * lcd.pixel(16, 36, true); |
Rybowonder | 4:1178a1905490 | 47 | * lcd.pixel(18, 37, true); |
Rybowonder | 4:1178a1905490 | 48 | * lcd.pos(5, 30); |
Rybowonder | 4:1178a1905490 | 49 | * lcd.printf("Hi"); |
Rybowonder | 4:1178a1905490 | 50 | * lcd.circle(50, 20, 20, true); |
Rybowonder | 4:1178a1905490 | 51 | * lcd.pos(50, 20); |
Rybowonder | 4:1178a1905490 | 52 | * lcd.printf("Howdy"); |
Rybowonder | 4:1178a1905490 | 53 | * lcd.line(0, 0, 25, 25, true); |
Rybowonder | 4:1178a1905490 | 54 | * wait(2); |
Rybowonder | 4:1178a1905490 | 55 | * } |
Rybowonder | 4:1178a1905490 | 56 | * } |
Rybowonder | 4:1178a1905490 | 57 | * @endcode |
Rybowonder | 4:1178a1905490 | 58 | */ |
Rybowonder | 4:1178a1905490 | 59 | class SerialGraphicLCD: public Serial { |
Rybowonder | 4:1178a1905490 | 60 | public: |
Rybowonder | 4:1178a1905490 | 61 | /** Create a new interface to a Serial Graphic LCD |
Rybowonder | 4:1178a1905490 | 62 | * Note that the display lower left corner is coordinates 0, 0. |
Rybowonder | 4:1178a1905490 | 63 | * Rows start at the top at 0, columns start at the left at 0. |
Rybowonder | 4:1178a1905490 | 64 | * @param tx -- mbed transmit pin |
Rybowonder | 4:1178a1905490 | 65 | * @param rx -- mbed receive pin |
Rybowonder | 4:1178a1905490 | 66 | */ |
Rybowonder | 4:1178a1905490 | 67 | SerialGraphicLCD(PinName tx, PinName rx); |
Rybowonder | 4:1178a1905490 | 68 | |
Rybowonder | 4:1178a1905490 | 69 | /** Create a new interface to a Serial Graphic LCD |
Rybowonder | 4:1178a1905490 | 70 | * Note that the display lower left corner is coordinates 0, 0. |
Rybowonder | 4:1178a1905490 | 71 | * Rows start at the top at 0, columns start at the left at 0. |
Rybowonder | 4:1178a1905490 | 72 | * @param tx -- mbed transmit pin |
Rybowonder | 4:1178a1905490 | 73 | * @param rx -- mbed receive pin |
Rybowonder | 4:1178a1905490 | 74 | * @param firmware -- SFE_FW, stock firmware or SD_FW, summoningdark firmware |
Rybowonder | 4:1178a1905490 | 75 | */ |
Rybowonder | 4:1178a1905490 | 76 | SerialGraphicLCD(PinName tx, PinName rx, int firmware); |
Rybowonder | 4:1178a1905490 | 77 | |
Rybowonder | 4:1178a1905490 | 78 | /** clear the screen |
Rybowonder | 4:1178a1905490 | 79 | */ |
Rybowonder | 4:1178a1905490 | 80 | void clear(void); |
Rybowonder | 4:1178a1905490 | 81 | |
Rybowonder | 4:1178a1905490 | 82 | /** set text position in rows, columns |
Rybowonder | 4:1178a1905490 | 83 | * |
Rybowonder | 4:1178a1905490 | 84 | * @param col is the col coordinate |
Rybowonder | 4:1178a1905490 | 85 | * @param row is the row coordinate |
Rybowonder | 4:1178a1905490 | 86 | */ |
Rybowonder | 4:1178a1905490 | 87 | void pos(int col, int row); |
Rybowonder | 4:1178a1905490 | 88 | |
Rybowonder | 4:1178a1905490 | 89 | /** set text position in x, y coordinates |
Rybowonder | 4:1178a1905490 | 90 | * |
Rybowonder | 4:1178a1905490 | 91 | * @param x is the x coordinate |
Rybowonder | 4:1178a1905490 | 92 | * @param y is the y coordinate |
Rybowonder | 4:1178a1905490 | 93 | */ |
Rybowonder | 4:1178a1905490 | 94 | void posXY(int x, int y); |
Rybowonder | 4:1178a1905490 | 95 | |
Rybowonder | 4:1178a1905490 | 96 | /** set or erase a pixel |
Rybowonder | 4:1178a1905490 | 97 | * |
Rybowonder | 4:1178a1905490 | 98 | * @param x is the x coordinate |
Rybowonder | 4:1178a1905490 | 99 | * @param y is the y coordinate |
Rybowonder | 4:1178a1905490 | 100 | * @param set if true sets the pixel, if false, erases it |
Rybowonder | 4:1178a1905490 | 101 | */ |
Rybowonder | 4:1178a1905490 | 102 | void pixel(int x, int y, bool set); |
Rybowonder | 4:1178a1905490 | 103 | |
Rybowonder | 4:1178a1905490 | 104 | /** draw or erase a line |
Rybowonder | 4:1178a1905490 | 105 | * |
Rybowonder | 4:1178a1905490 | 106 | * @param x1 is the x coordinate of the start of the line |
Rybowonder | 4:1178a1905490 | 107 | * @param y1 is the y coordinate of the start of the line |
Rybowonder | 4:1178a1905490 | 108 | * @param x2 is the x coordinate of the end of the line |
Rybowonder | 4:1178a1905490 | 109 | * @param y2 is the y coordinate of the end of the line |
Rybowonder | 4:1178a1905490 | 110 | * @param set if true sets the line, if false, erases it |
Rybowonder | 4:1178a1905490 | 111 | */ |
Rybowonder | 4:1178a1905490 | 112 | void line(int x1, int y1, int x2, int y2, bool set); |
Rybowonder | 4:1178a1905490 | 113 | |
Rybowonder | 4:1178a1905490 | 114 | /** set or reset a circle |
Rybowonder | 4:1178a1905490 | 115 | * |
Rybowonder | 4:1178a1905490 | 116 | * @param x is the x coordinate of the circle center |
Rybowonder | 4:1178a1905490 | 117 | * @param y is the y coordinate of the circle center |
Rybowonder | 4:1178a1905490 | 118 | * @param r is the radius of the circle |
Rybowonder | 4:1178a1905490 | 119 | * @param set if true sets the pixel, if false, clears it |
Rybowonder | 4:1178a1905490 | 120 | */ |
Rybowonder | 4:1178a1905490 | 121 | void circle(int x, int y, int r, bool set); |
Rybowonder | 4:1178a1905490 | 122 | |
Rybowonder | 4:1178a1905490 | 123 | /** draw or erase a rectangle |
Rybowonder | 4:1178a1905490 | 124 | * |
Rybowonder | 4:1178a1905490 | 125 | * @param x1 is the x coordinate of the upper left of the rectangle |
Rybowonder | 4:1178a1905490 | 126 | * @param y1 is the y coordinate of the upper left of the rectangle |
Rybowonder | 4:1178a1905490 | 127 | * @param x2 is the x coordinate of the lower right of the rectangle |
Rybowonder | 4:1178a1905490 | 128 | * @param y2 is the y coordinate of the lower right of the rectangle |
Rybowonder | 4:1178a1905490 | 129 | */ |
Rybowonder | 4:1178a1905490 | 130 | void rect(int x1, int y1, int x2, int y2); |
Rybowonder | 4:1178a1905490 | 131 | |
Rybowonder | 4:1178a1905490 | 132 | /** erase a rectangular area |
Rybowonder | 4:1178a1905490 | 133 | * |
Rybowonder | 4:1178a1905490 | 134 | * @param x1 is the x coordinate of the upper left of the area |
Rybowonder | 4:1178a1905490 | 135 | * @param y1 is the y coordinate of the upper left of the area |
Rybowonder | 4:1178a1905490 | 136 | * @param x2 is the x coordinate of the lower right of the area |
Rybowonder | 4:1178a1905490 | 137 | * @param y2 is the y coordinate of the lower right of the area |
Rybowonder | 4:1178a1905490 | 138 | */ |
Rybowonder | 4:1178a1905490 | 139 | void erase(int x1, int y1, int x2, int y2); |
Rybowonder | 4:1178a1905490 | 140 | |
Rybowonder | 4:1178a1905490 | 141 | /** set backlight duty cycle |
Rybowonder | 4:1178a1905490 | 142 | * |
Rybowonder | 4:1178a1905490 | 143 | * @param i is the duty cycle from 0 to 100; 0 is off, 100 is full power |
Rybowonder | 4:1178a1905490 | 144 | */ |
Rybowonder | 4:1178a1905490 | 145 | void backlight(int i); |
Rybowonder | 4:1178a1905490 | 146 | |
Rybowonder | 4:1178a1905490 | 147 | /** clear screen and put in reverse mode |
Rybowonder | 4:1178a1905490 | 148 | */ |
Rybowonder | 4:1178a1905490 | 149 | void reverseMode(void); |
Rybowonder | 4:1178a1905490 | 150 | |
Rybowonder | 4:1178a1905490 | 151 | /** configure the lcd baud rate so you have to call this along with baud() to change |
Rybowonder | 4:1178a1905490 | 152 | * communication speeds |
Rybowonder | 4:1178a1905490 | 153 | * |
Rybowonder | 4:1178a1905490 | 154 | * @param b is the baud rate, LCD_4800, LCD_9600, LCD_19200, LCD_38400, LCD_57600 or LCD_115200 |
Rybowonder | 4:1178a1905490 | 155 | */ |
Rybowonder | 4:1178a1905490 | 156 | void lcdbaud(int b); |
Rybowonder | 4:1178a1905490 | 157 | |
Rybowonder | 4:1178a1905490 | 158 | |
Rybowonder | 4:1178a1905490 | 159 | /** sets the resolution of the LCD so that the pos() call works properly |
Rybowonder | 4:1178a1905490 | 160 | * defaults to LCD_128x64. |
Rybowonder | 4:1178a1905490 | 161 | * |
Rybowonder | 4:1178a1905490 | 162 | * @param type is the type of LCD, either LCD_128x64 or LCD_160x128 |
Rybowonder | 4:1178a1905490 | 163 | */ |
Rybowonder | 4:1178a1905490 | 164 | void resolution(int type); |
Rybowonder | 4:1178a1905490 | 165 | |
Rybowonder | 4:1178a1905490 | 166 | /** sets the resolution of the LCD in x and y coordinates which determines |
Rybowonder | 4:1178a1905490 | 167 | * how rows and columns are calculated in the pos() call. Defaults to |
Rybowonder | 4:1178a1905490 | 168 | * x=128, y=64 |
Rybowonder | 4:1178a1905490 | 169 | * |
Rybowonder | 4:1178a1905490 | 170 | * @param x is the number of horizontal pixels |
Rybowonder | 4:1178a1905490 | 171 | * @param y is the number of vertical pixels |
Rybowonder | 4:1178a1905490 | 172 | */ |
Rybowonder | 4:1178a1905490 | 173 | void resolution(int x, int y); |
Rybowonder | 4:1178a1905490 | 174 | |
Rybowonder | 4:1178a1905490 | 175 | private: |
Rybowonder | 4:1178a1905490 | 176 | int _xMax; |
Rybowonder | 4:1178a1905490 | 177 | int _yMax; |
Rybowonder | 4:1178a1905490 | 178 | int _firmware; |
Rybowonder | 4:1178a1905490 | 179 | }; |
Rybowonder | 4:1178a1905490 | 180 | |
Rybowonder | 4:1178a1905490 | 181 | |
Rybowonder | 4:1178a1905490 | 182 | #endif |