Heavily documented control library for the uOLED-96-G1 (SGC) by 4D Systems. Will likely work with any of the 4D Systems serial controlled screens. <<info>> All examples in the documentation have been tested to the best of my current abilities, but there are a few functions that I simply do not use. I have created a Lighthouse page for this library. You may submit bug reports or feature requests to [[http://mbed-uoled.lighthouseapp.com|this page]]. If you really do not wish to sign up for a Lighthouse account you may also post any bugs or requests [[/users/Nakor/notebook/uoled-bug-reports/|here]]. <</info>>

Dependents:   DS18B20 DS18B20GSM Astromed Astromed_build20121123

Committer:
Nakor
Date:
Sat Jan 08 09:06:11 2011 +0000
Revision:
30:41a872ad6155
Parent:
29:757036aa73cd
Child:
31:7ad5bf258a1e
Added a function to load 16 bit images from a uSD.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nakor 0:4f009971ac11 1 /* mbed 4D uOLED Library
Nakor 0:4f009971ac11 2 * Originally designed for use with uOLED-96-G1 (SGC)
Nakor 0:4f009971ac11 3 * serially controlled .96" screen.
Nakor 0:4f009971ac11 4 *
Nakor 0:4f009971ac11 5 * This is a modified library originally obtained from
Nakor 0:4f009971ac11 6 * Erik van Wijk's library code at:
Nakor 0:4f009971ac11 7 * http://mbed.org/users/evwijk/libraries/microOLED/li4nzn
Nakor 5:93ea03e2a688 8 *
Nakor 5:93ea03e2a688 9 * This library (uOLED) by Aaron Goselin.
Nakor 5:93ea03e2a688 10 * 2010
Nakor 27:da58cb3c815b 11 *
Nakor 27:da58cb3c815b 12 * If you use and/or modify this library please keep credit lines intact.
Nakor 0:4f009971ac11 13 */
Nakor 0:4f009971ac11 14
Nakor 0:4f009971ac11 15 #ifndef _MBED_UOLED_
Nakor 0:4f009971ac11 16 #define _MBED_UOLED_
Nakor 0:4f009971ac11 17
Nakor 0:4f009971ac11 18 #include "mbed.h"
Nakor 0:4f009971ac11 19
Nakor 0:4f009971ac11 20 #define OLED_FONT5X7 0x01
Nakor 0:4f009971ac11 21 #define OLED_FONT8X8 0x02
Nakor 0:4f009971ac11 22 #define OLED_FONT8X12 0x03
Nakor 0:4f009971ac11 23
Nakor 0:4f009971ac11 24 #define OLED_DISPLAYCONTROL_DISPLAY 0x01
Nakor 0:4f009971ac11 25 #define OLED_DISPLAYCONTROL_CONTRAST 0x02
Nakor 0:4f009971ac11 26 #define OLED_DISPLAYCONTROL_POWER 0x03
Nakor 0:4f009971ac11 27
Nakor 30:41a872ad6155 28
Nakor 0:4f009971ac11 29 /** uOLED control class using Serial
Nakor 27:da58cb3c815b 30 *
Nakor 27:da58cb3c815b 31 * The serially controlled uOLEDs by 4D Systems are controlled
Nakor 27:da58cb3c815b 32 * with only 3 pins:
Nakor 27:da58cb3c815b 33 * - serialTX
Nakor 27:da58cb3c815b 34 * - serialRX
Nakor 27:da58cb3c815b 35 * - reset
Nakor 27:da58cb3c815b 36 *
Nakor 28:81a38ad6e79a 37 * While the device includes many serial functions, it is faster to do things from a uSD card.
Nakor 27:da58cb3c815b 38 * Consider learning the 4DSL scripting language. You can then write your functions in 4DSL
Nakor 27:da58cb3c815b 39 * storing them on the uSD to later be triggered serially.
Nakor 27:da58cb3c815b 40 *
Nakor 27:da58cb3c815b 41 * Examples use SGC as the uOLED instance name. SGC just happens to be the type of device that I have.
Nakor 27:da58cb3c815b 42 * Of course, it doesn't matter what you call your instance(s).
Nakor 27:da58cb3c815b 43 *
Nakor 27:da58cb3c815b 44 * Examples use both decimal and hexadecimal numbers. It does not matter which you use for most functions.
Nakor 27:da58cb3c815b 45 *
Nakor 27:da58cb3c815b 46 * Please post a comment on the library page if you spot an error. I will try to fix it quickly.
Nakor 0:4f009971ac11 47 *
Nakor 0:4f009971ac11 48 * Example:
Nakor 0:4f009971ac11 49 * @code
Nakor 0:4f009971ac11 50 * // Draw text on the screen.
Nakor 0:4f009971ac11 51 * #include "mbed.h"
Nakor 0:4f009971ac11 52 * #include "uOLED.h"
Nakor 0:4f009971ac11 53 *
Nakor 0:4f009971ac11 54 * uOLED SGC(p9, p10, p11);
Nakor 0:4f009971ac11 55 *
Nakor 5:93ea03e2a688 56 * int main()
Nakor 0:4f009971ac11 57 * {
Nakor 29:757036aa73cd 58 * SGC.drawText(0, 0, 0, FF, FF, FF, "This is text");
Nakor 0:4f009971ac11 59 * }
Nakor 3:949c5ac54e9c 60 * @endcode
Nakor 0:4f009971ac11 61 */
Nakor 0:4f009971ac11 62 class uOLED {
Nakor 0:4f009971ac11 63 public:
Nakor 0:4f009971ac11 64
Nakor 4:51f274633e70 65 /** Create an instance of the uOLED class.
Nakor 4:51f274633e70 66 *
Nakor 2:559b81f2bb1e 67 * @param serialTX - mbed TX pin to be used
Nakor 2:559b81f2bb1e 68 * @param serialRX - mbed RX pin to be used
Nakor 2:559b81f2bb1e 69 * @param reset - mbed pin to control reset of the uOLED
Nakor 25:caf134ebfc34 70 *
Nakor 25:caf134ebfc34 71 * Example:
Nakor 25:caf134ebfc34 72 * @code
Nakor 25:caf134ebfc34 73 * // (serialTX, serialRX, reset)
Nakor 25:caf134ebfc34 74 * uOLED SGC(p9, p10, p11);
Nakor 25:caf134ebfc34 75 * @endcode
Nakor 1:476dcc382de3 76 */
Nakor 0:4f009971ac11 77 uOLED(PinName serialTX, PinName serialRX, PinName reset);
Nakor 1:476dcc382de3 78
Nakor 17:cee1c66b3133 79 /** Convert RGB value into the type of value that the uOLED wants.
Nakor 17:cee1c66b3133 80 *
Nakor 17:cee1c66b3133 81 * @param red Red value.
Nakor 17:cee1c66b3133 82 * @param green Green value.
Nakor 17:cee1c66b3133 83 * @param blue Blue value.
Nakor 25:caf134ebfc34 84 *
Nakor 25:caf134ebfc34 85 * Example:
Nakor 25:caf134ebfc34 86 * @code
Nakor 25:caf134ebfc34 87 * // (red, green, blue)
Nakor 25:caf134ebfc34 88 * SGC.getRGB(120, 255, 50);
Nakor 25:caf134ebfc34 89 * @endcode
Nakor 1:476dcc382de3 90 */
Nakor 0:4f009971ac11 91 short getRGB(char red, char green, char blue);
Nakor 0:4f009971ac11 92
Nakor 25:caf134ebfc34 93 /** Add user defined bitmap character into internal memory.
Nakor 17:cee1c66b3133 94 *
Nakor 25:caf134ebfc34 95 * @param character Character index to add to memory. Range is 0-31 (0x00 to 0x1F). 32 8x8 characters.
Nakor 25:caf134ebfc34 96 * @param data[8] 8 data bytes that make up the composition of the bitmap character. 8x8 composition is 1 byte wide (8 bits) by 8 bytes deep.
Nakor 25:caf134ebfc34 97 *
Nakor 25:caf134ebfc34 98 * Example:
Nakor 25:caf134ebfc34 99 * @code
Nakor 25:caf134ebfc34 100 * // Array containing data for 8x8 "O" character.
Nakor 25:caf134ebfc34 101 * char data[8] = {0x18, 0x24, 0x42, 0x81, 0x81, 0x42, 0x24, 0x18};
Nakor 25:caf134ebfc34 102 * // (characterIndex, characterData)
Nakor 25:caf134ebfc34 103 * SGC.addBitmappedCharacter(0x01, data);
Nakor 25:caf134ebfc34 104 * @endcode
Nakor 1:476dcc382de3 105 */
Nakor 0:4f009971ac11 106 bool addBitmappedCharacter(char character, char data[8]);
Nakor 17:cee1c66b3133 107
Nakor 25:caf134ebfc34 108 /** Copy and paste a specified block of the screen.
Nakor 19:cc4f5d01f080 109 *
Nakor 25:caf134ebfc34 110 * @param sourceX Top left horizontal start position of screen area to be copied.
Nakor 25:caf134ebfc34 111 * @param sourceY Top left vertical start position of screen area to be copied.
Nakor 25:caf134ebfc34 112 * @param destinationX Top left horizontal start position of where copied area is to be pasted.
Nakor 25:caf134ebfc34 113 * @param destinationY Top left vertical start position of where copied area is to be pasted.
Nakor 25:caf134ebfc34 114 * @param width Width of screen area to be copied.
Nakor 25:caf134ebfc34 115 * @param height Height of screen area to be copied.
Nakor 25:caf134ebfc34 116 *
Nakor 25:caf134ebfc34 117 * Example:
Nakor 25:caf134ebfc34 118 * @code
Nakor 25:caf134ebfc34 119 * // (sourceX, sourceY, destinationX, destinationY, width, height)
Nakor 25:caf134ebfc34 120 * SGC.blockCopyPaste(0, 0, 25, 5, 10, 10);
Nakor 25:caf134ebfc34 121 * @endcode
Nakor 1:476dcc382de3 122 */
Nakor 0:4f009971ac11 123 bool blockCopyPaste(char sourceX, char sourceY, char destinationX, char destinationY, char width, char height);
Nakor 17:cee1c66b3133 124
Nakor 17:cee1c66b3133 125 /** Display control.
Nakor 17:cee1c66b3133 126 *
Nakor 19:cc4f5d01f080 127 * Display ON/OFF, set contrast, and PowerUp/Shutdown.
Nakor 17:cee1c66b3133 128 *
Nakor 17:cee1c66b3133 129 * @param mode Sets specified mode.
Nakor 17:cee1c66b3133 130 * @param value Value option for mode.
Nakor 17:cee1c66b3133 131 *
Nakor 18:77ec40174c31 132 * - Mode: 01 Display ON/OFF
Nakor 18:77ec40174c31 133 * - Value: 00 OFF
Nakor 18:77ec40174c31 134 * - Value: 01 ON
Nakor 18:77ec40174c31 135 * - Mode: 02 Contrast Adjust
Nakor 18:77ec40174c31 136 * - Value range: 0x00 to 0x0F
Nakor 18:77ec40174c31 137 * - Mode: 03 Display PowerUp/Shutdown (low power mode)
Nakor 18:77ec40174c31 138 * - Value 00 Shutdown
Nakor 18:77ec40174c31 139 * - Value 01 Powerup
Nakor 25:caf134ebfc34 140 *
Nakor 25:caf134ebfc34 141 * Example:
Nakor 25:caf134ebfc34 142 * @code
Nakor 25:caf134ebfc34 143 * // Turn display ON.
Nakor 25:caf134ebfc34 144 * SGC.displayControl(0x01, 0x01)
Nakor 25:caf134ebfc34 145 * // Set contrast to medium.
Nakor 25:caf134ebfc34 146 * SGC.displayControl(0x02, 0x08);
Nakor 25:caf134ebfc34 147 * // Shutdown display.
Nakor 25:caf134ebfc34 148 * SGC.displayControl(0x03, 0x00);
Nakor 25:caf134ebfc34 149 * @endcode
Nakor 1:476dcc382de3 150 */
Nakor 17:cee1c66b3133 151 bool displayControl(char mode, char value);
Nakor 17:cee1c66b3133 152
Nakor 25:caf134ebfc34 153 /** Draw previously defined user bitmap character at specified location (and colour).
Nakor 19:cc4f5d01f080 154 *
Nakor 25:caf134ebfc34 155 * @param character Character index of previously defined bitmap character. Range is 0 to 31 (0x00 to 0x1F). 32 8x8 characters.
Nakor 25:caf134ebfc34 156 * @param x Horizontal display position of character.
Nakor 25:caf134ebfc34 157 * @param y Vertical display position of character.
Nakor 25:caf134ebfc34 158 * @param red Amount of red.
Nakor 25:caf134ebfc34 159 * @param green Amount of green.
Nakor 25:caf134ebfc34 160 * @param blue Amount of blue.
Nakor 26:5a2128799f60 161 *
Nakor 26:5a2128799f60 162 * Example:
Nakor 26:5a2128799f60 163 * @code
Nakor 26:5a2128799f60 164 * // Display bitmapped character stored in index 01, at location (0x,0y), and colour it red.
Nakor 26:5a2128799f60 165 * // (characterIndex, x, y, red, green, blue)
Nakor 26:5a2128799f60 166 * SGC.displayUserBitmappedCharacter(0x01, 0x00, 0x00, 0xFF, 0x00, 0x00);
Nakor 26:5a2128799f60 167 * @endcode
Nakor 1:476dcc382de3 168 */
Nakor 25:caf134ebfc34 169 bool displayUserBitmappedCharacter(char character, char x, char y, short red, short green, short blue);
Nakor 19:cc4f5d01f080 170
Nakor 19:cc4f5d01f080 171 /** Draw a circle.
Nakor 19:cc4f5d01f080 172 *
Nakor 19:cc4f5d01f080 173 * @param x X position of circle center.
Nakor 19:cc4f5d01f080 174 * @param y Y position of circle center.
Nakor 19:cc4f5d01f080 175 * @param radius Radius of the circle.
Nakor 19:cc4f5d01f080 176 * @param red Amount of red.
Nakor 19:cc4f5d01f080 177 * @param green Amount of green.
Nakor 19:cc4f5d01f080 178 * @param blue Amount of blue.
Nakor 26:5a2128799f60 179 *
Nakor 26:5a2128799f60 180 * Example:
Nakor 26:5a2128799f60 181 * @code
Nakor 26:5a2128799f60 182 * // Draw a circle centered at (63x, 63y) with a radius of 34 and colour it green.
Nakor 26:5a2128799f60 183 * // (x, y, radius, red, green, blue)
Nakor 26:5a2128799f60 184 * SGC.drawCircle(0x3F, 0x3F, 0x22, 0x00, 0xFF, 0x00);
Nakor 26:5a2128799f60 185 * @endcode
Nakor 1:476dcc382de3 186 */
Nakor 19:cc4f5d01f080 187 bool drawCircle(char x, char y, char radius, short red, short green, short blue);
Nakor 19:cc4f5d01f080 188
Nakor 25:caf134ebfc34 189 /** Draw ASCII character (text format)
Nakor 19:cc4f5d01f080 190 *
Nakor 25:caf134ebfc34 191 * @param character Inbuilt standard ASCII character. Range 32 to 127 (0x20 to 0x7F).
Nakor 25:caf134ebfc34 192 * @param column Horizontal position of character.
Nakor 25:caf134ebfc34 193 * - range: 0-20 for 5x7 font.
Nakor 25:caf134ebfc34 194 * - range: 0-15 for 8x8 and 8x12 fonts.
Nakor 25:caf134ebfc34 195 * @param row Vertical position of character.
Nakor 25:caf134ebfc34 196 * @param red Amount of red.
Nakor 25:caf134ebfc34 197 * @param green Amount of green.
Nakor 25:caf134ebfc34 198 * @param blue Amount of blue.
Nakor 26:5a2128799f60 199 *
Nakor 26:5a2128799f60 200 * Example:
Nakor 26:5a2128799f60 201 * @code
Nakor 26:5a2128799f60 202 * // Draw character 'A' at column 0, row 0. Colour it white.
Nakor 26:5a2128799f60 203 * // (character, column, row, red, green, blue)
Nakor 26:5a2128799f60 204 * SGC.drawCharacter(0x41, 0x00, 0x00, 0xFF, 0xFF, 0xFF);
Nakor 26:5a2128799f60 205 * @endcode
Nakor 1:476dcc382de3 206 */
Nakor 25:caf134ebfc34 207 bool drawCharacter(char character, char column, char row, short red, short green, short blue);
Nakor 19:cc4f5d01f080 208
Nakor 25:caf134ebfc34 209 /** Display a bitmap image on the screen at specified location and size.
Nakor 19:cc4f5d01f080 210 *
Nakor 25:caf134ebfc34 211 * @param x Image horizontal start position (top left).
Nakor 25:caf134ebfc34 212 * @param y Image vertical start position (top left).
Nakor 25:caf134ebfc34 213 * @param width Horizontal size of the image.
Nakor 25:caf134ebfc34 214 * @param height Vertical size of the image.
Nakor 25:caf134ebfc34 215 * @param colorMode Colour mode to use for the image.
Nakor 25:caf134ebfc34 216 * - 0x08 = 256 colour mode (8bits/1byte per pixel)
Nakor 25:caf134ebfc34 217 * - 0x10 = 65K colour mode (16bits/2bytes per pixel)
Nakor 25:caf134ebfc34 218 * @param *pixels Image pixel data.
Nakor 25:caf134ebfc34 219 * - Colour Mode 0x08 (256 colour mode): Number of pixels = width x height
Nakor 25:caf134ebfc34 220 * - Colour Mode 0x10 (65K colour mode): Number of pixels = 2 x width x height
Nakor 1:476dcc382de3 221 */
Nakor 0:4f009971ac11 222 bool drawImage(char x, char y, char width, char height, char colorMode, char *pixels);
Nakor 19:cc4f5d01f080 223
Nakor 30:41a872ad6155 224 /** Load an image from the uSD and display on the screen at specified location and size.
Nakor 30:41a872ad6155 225 *
Nakor 30:41a872ad6155 226 * @param x Image horizontal start position (top left).
Nakor 30:41a872ad6155 227 * @param y Image vertical start position (top left).
Nakor 30:41a872ad6155 228 * @param width Horizontal size of the image.
Nakor 30:41a872ad6155 229 * @param height Vertical size of the image.
Nakor 30:41a872ad6155 230 * @param colorMode Colour mode to use for the image.
Nakor 30:41a872ad6155 231 * - 0x08 = 256 colour mode (8bits/1byte per pixel)
Nakor 30:41a872ad6155 232 * - 0x10 = 65K colour mode (16bits/2bytes per pixel)
Nakor 30:41a872ad6155 233 * @param sectorHi High sector address.
Nakor 30:41a872ad6155 234 * @param sectorMid Mid sector address.
Nakor 30:41a872ad6155 235 * @param sectorLow Low sector address.
Nakor 30:41a872ad6155 236 */
Nakor 30:41a872ad6155 237 bool drawImageSD_16bit(char x, char y, char width, char height, char colourMode, char sectorHi, char sectorMid, char sectorLow);
Nakor 30:41a872ad6155 238
Nakor 30:41a872ad6155 239
Nakor 19:cc4f5d01f080 240 /** Draw a line.
Nakor 19:cc4f5d01f080 241 *
Nakor 19:cc4f5d01f080 242 * @param x1 Top left horizontal start position.
Nakor 19:cc4f5d01f080 243 * @param y1 Top left vertical start position.
Nakor 19:cc4f5d01f080 244 * @param x2 Bottom right horizontal start position.
Nakor 19:cc4f5d01f080 245 * @param y2 Bottom right vertical end position.
Nakor 19:cc4f5d01f080 246 * @param red Amount of red.
Nakor 19:cc4f5d01f080 247 * @param green Amount of green.
Nakor 19:cc4f5d01f080 248 * @param blue Amount of blue.
Nakor 26:5a2128799f60 249 *
Nakor 26:5a2128799f60 250 * Example:
Nakor 26:5a2128799f60 251 * @code
Nakor 26:5a2128799f60 252 * // Draw a line starting at (0x, 0y) and ending at (43x, 43y). Colour it blue.
Nakor 26:5a2128799f60 253 * // (x1, y1, x2, y2, red, green, blue)
Nakor 26:5a2128799f60 254 * SGC.drawLine(0x00, 0x00, 0x2B, 0x2B, 0x00, 0x00, 0xFF);
Nakor 26:5a2128799f60 255 * @endcode
Nakor 1:476dcc382de3 256 */
Nakor 19:cc4f5d01f080 257 bool drawLine(char x1, char y1, char x2, char y2, short red, short green, short blue);
Nakor 19:cc4f5d01f080 258
Nakor 25:caf134ebfc34 259 /** Draw a polygon (user defined shape) to the screen.
Nakor 21:87a2227c1ad2 260 *
Nakor 25:caf134ebfc34 261 * @param vertices Number of vertices from 3 to 7.
Nakor 25:caf134ebfc34 262 * @param *x Array of vertices' X coordinates.
Nakor 25:caf134ebfc34 263 * @param *y Array of vertices' Y coordinates.
Nakor 25:caf134ebfc34 264 * @param red Amount of red.
Nakor 25:caf134ebfc34 265 * @param green Amount of green.
Nakor 25:caf134ebfc34 266 * @param blue Amount of blue.
Nakor 26:5a2128799f60 267 *
Nakor 26:5a2128799f60 268 * Example:
Nakor 26:5a2128799f60 269 * @code
Nakor 29:757036aa73cd 270 * char x[5] = {0, 18, 26, 44, 54};
Nakor 29:757036aa73cd 271 * char y[5] = {10, 25, 33, 22, 36};
Nakor 29:757036aa73cd 272 * // Draw a white polygon with 5 vertices located at:
Nakor 29:757036aa73cd 273 * // (0x, 10y), (18x, 25y), (26x, 33y), (44x, 22y), (54x, 36y)
Nakor 26:5a2128799f60 274 * // (vertices, *x, *y, red, green, blue)
Nakor 29:757036aa73cd 275 * SGC.drawPolygon(5, x, y, 255, 255, 255);
Nakor 26:5a2128799f60 276 * @endcode
Nakor 1:476dcc382de3 277 */
Nakor 25:caf134ebfc34 278 bool drawPolygon(char vertices, char *x, char *y, short red, short green, short blue);
Nakor 21:87a2227c1ad2 279
Nakor 21:87a2227c1ad2 280 /** Draw a rectangle.
Nakor 21:87a2227c1ad2 281 *
Nakor 21:87a2227c1ad2 282 * @param x Top left horizontal start position.
Nakor 21:87a2227c1ad2 283 * @param y Top left vertical start position.
Nakor 21:87a2227c1ad2 284 * @param width Bottom right horizontal end position.
Nakor 21:87a2227c1ad2 285 * @param height Bottom right vertical end position.
Nakor 21:87a2227c1ad2 286 * @param red Amount of red.
Nakor 21:87a2227c1ad2 287 * @param green Amount of green.
Nakor 21:87a2227c1ad2 288 * @param blue Amount of blue.
Nakor 26:5a2128799f60 289 *
Nakor 26:5a2128799f60 290 * Example:
Nakor 26:5a2128799f60 291 * @code
Nakor 26:5a2128799f60 292 * // Draw rectangle starting at (0x, 0y) and ending at (40x, 40y). Colour red.
Nakor 26:5a2128799f60 293 * // (x, y, width, height, red, green, blue)
Nakor 26:5a2128799f60 294 * SGC.drawRectangle(0, 0, 40, 40, 255, 0, 0);
Nakor 26:5a2128799f60 295 * @endcode
Nakor 1:476dcc382de3 296 */
Nakor 21:87a2227c1ad2 297 bool drawRectangle(char x, char y, char width, char height, short red, short green, short blue);
Nakor 21:87a2227c1ad2 298
Nakor 5:93ea03e2a688 299 /** Draw text to the screen.
Nakor 5:93ea03e2a688 300 *
Nakor 5:93ea03e2a688 301 * @param column X coordinate for text placement.
Nakor 5:93ea03e2a688 302 * @param row Y coordinate for text placement.
Nakor 5:93ea03e2a688 303 * @param font Which font to use (Uses 0, 1, or 2). More fonts can be added.
Nakor 5:93ea03e2a688 304 * @param color Font colour to use.
Nakor 5:93ea03e2a688 305 * @param *text Character array (string) to be displayed.
Nakor 5:93ea03e2a688 306 *
Nakor 5:93ea03e2a688 307 * Example:
Nakor 5:93ea03e2a688 308 * @code
Nakor 26:5a2128799f60 309 * // Draw string "This is text" at (0, 0) with font set 0, coloured white.
Nakor 26:5a2128799f60 310 * // (column, row, font, red, green, blue, "text")
Nakor 29:757036aa73cd 311 * SGC.drawText(0, 0, 0, 0xFF, 0xFF, 0xFF, "This is text");
Nakor 5:93ea03e2a688 312 * @endcode
Nakor 1:476dcc382de3 313 */
Nakor 21:87a2227c1ad2 314 bool drawText(char column, char row, char font, short red, short green, short blue, char *text);
Nakor 21:87a2227c1ad2 315
Nakor 14:3d90211095d4 316 /** Draw unformated text to the screen.
Nakor 14:3d90211095d4 317 * The manual describes this as "graphics format".
Nakor 14:3d90211095d4 318 *
Nakor 14:3d90211095d4 319 * @param x X coordinate for text placement.
Nakor 14:3d90211095d4 320 * @param y Y coordinate for text placement.
Nakor 14:3d90211095d4 321 * @param font Which font to use (Uses 0, 1, or 2). More fonts can be added.
Nakor 14:3d90211095d4 322 * @param red Amount of red in text colour RGB value.
Nakor 14:3d90211095d4 323 * @param green Amount of green in text colour RGB value.
Nakor 14:3d90211095d4 324 * @param blue Amount of blue in text colour RGB value.
Nakor 14:3d90211095d4 325 * @param width Text width.
Nakor 14:3d90211095d4 326 * @param height Text height.
Nakor 14:3d90211095d4 327 * @param *text Character array (string) to be displayed.
Nakor 14:3d90211095d4 328 *
Nakor 14:3d90211095d4 329 * Example:
Nakor 14:3d90211095d4 330 * @code
Nakor 26:5a2128799f60 331 * // Draw unformatted text string "This is text" at (0, 0) with font set 0, coloured white with zero (1x) magnification.
Nakor 26:5a2128799f60 332 * SGC.drawTextUF(0, 0, 0, 255, 255, 255, 1, 1, "This is text");
Nakor 14:3d90211095d4 333 * @endcode
Nakor 14:3d90211095d4 334 */
Nakor 15:06ef508fef4b 335 bool drawTextUF(char x, char y, char font, short red, short green, short blue, char width, char height, char *text);
Nakor 21:87a2227c1ad2 336
Nakor 21:87a2227c1ad2 337 /** Draw a triangle.
Nakor 21:87a2227c1ad2 338 *
Nakor 21:87a2227c1ad2 339 * Vertices must be defined counter clockwise.
Nakor 21:87a2227c1ad2 340 *
Nakor 21:87a2227c1ad2 341 * @param x1 Vertice 1 X coordinate.
Nakor 21:87a2227c1ad2 342 * @param y1 Vertice 1 Y coordinate.
Nakor 21:87a2227c1ad2 343 * @param x2 Vertice 2 X coordinate.
Nakor 21:87a2227c1ad2 344 * @param y2 Vertice 2 Y coordinate.
Nakor 21:87a2227c1ad2 345 * @param x3 Vertice 3 X coordinate.
Nakor 21:87a2227c1ad2 346 * @param y3 Vertice 3 Y coordinate.
Nakor 21:87a2227c1ad2 347 * @param red Amount of red.
Nakor 21:87a2227c1ad2 348 * @param blue Amount of blue.
Nakor 21:87a2227c1ad2 349 * @param green Amount of green.
Nakor 26:5a2128799f60 350 *
Nakor 26:5a2128799f60 351 * Example:
Nakor 26:5a2128799f60 352 * @code
Nakor 26:5a2128799f60 353 * // Draw a red triangle with vertices:
Nakor 29:757036aa73cd 354 * // (0x, 0y), (0x, 40y), (40x, 0y)
Nakor 26:5a2128799f60 355 * // (x1, y1, x2, y2, x3, y3, red, green, blue)
Nakor 29:757036aa73cd 356 * SGC.drawTriangle(0, 0, 0, 40, 40, 0, 255, 0, 0);
Nakor 26:5a2128799f60 357 * @endcode
Nakor 6:080d52539972 358 */
Nakor 21:87a2227c1ad2 359 bool drawTriangle(char x1, char y1, char x2, char y2, char x3, char y3, short red, short green, short blue);
Nakor 21:87a2227c1ad2 360
Nakor 21:87a2227c1ad2 361 /** Clear the screen.
Nakor 21:87a2227c1ad2 362 *
Nakor 21:87a2227c1ad2 363 * Remove everything except the background colour.
Nakor 21:87a2227c1ad2 364 *
Nakor 21:87a2227c1ad2 365 * @param returns success or failure.
Nakor 26:5a2128799f60 366 *
Nakor 26:5a2128799f60 367 * Example:
Nakor 26:5a2128799f60 368 * @code
Nakor 26:5a2128799f60 369 * // Do you really need an example? :)
Nakor 26:5a2128799f60 370 * SGC.eraseScreen();
Nakor 26:5a2128799f60 371 * @endcode
Nakor 1:476dcc382de3 372 */
Nakor 0:4f009971ac11 373 bool eraseScreen();
Nakor 21:87a2227c1ad2 374
Nakor 0:4f009971ac11 375 /** Initialize the screen. This must be completed before any other communication with the device.
Nakor 21:87a2227c1ad2 376 *
Nakor 0:4f009971ac11 377 * Timing allows for at least 500ms delay for initialization.
Nakor 21:87a2227c1ad2 378 *
Nakor 2:559b81f2bb1e 379 * @param returns bool indicating success or failure of initialization.
Nakor 26:5a2128799f60 380 *
Nakor 26:5a2128799f60 381 * Example:
Nakor 26:5a2128799f60 382 * @code
Nakor 26:5a2128799f60 383 * // Must be done before anything else
Nakor 26:5a2128799f60 384 * SGC.init();
Nakor 26:5a2128799f60 385 * @endcode
Nakor 0:4f009971ac11 386 */
Nakor 0:4f009971ac11 387 bool init();
Nakor 21:87a2227c1ad2 388
Nakor 21:87a2227c1ad2 389 /** Set pen size.
Nakor 21:87a2227c1ad2 390 *
Nakor 21:87a2227c1ad2 391 * Sets if objects should be drawn solid or wire frame.
Nakor 21:87a2227c1ad2 392 * Does not apply to polygon function.
Nakor 21:87a2227c1ad2 393 *
Nakor 21:87a2227c1ad2 394 * @param size Sets solid or wire frame.
Nakor 21:87a2227c1ad2 395 * - 0x00 = Solid
Nakor 21:87a2227c1ad2 396 * - 0x01 = Wire frame.
Nakor 26:5a2128799f60 397 *
Nakor 26:5a2128799f60 398 * Example:
Nakor 26:5a2128799f60 399 * @code
Nakor 26:5a2128799f60 400 * // Draw objects solid
Nakor 26:5a2128799f60 401 * SGC.penSize(0);
Nakor 26:5a2128799f60 402 * // Draw objects wire frame
Nakor 26:5a2128799f60 403 * SGC.penSize(1);
Nakor 26:5a2128799f60 404 * @endcode
Nakor 1:476dcc382de3 405 */
Nakor 0:4f009971ac11 406 bool penSize(char size);
Nakor 21:87a2227c1ad2 407
Nakor 22:66401b612b1b 408 /** Draw a coloured pixel at designated position.
Nakor 22:66401b612b1b 409 *
Nakor 22:66401b612b1b 410 * @param x Horizontal position of pixel.
Nakor 22:66401b612b1b 411 * @param y Vertical position of pixel.
Nakor 22:66401b612b1b 412 * @param red Amount of red.
Nakor 22:66401b612b1b 413 * @param green Amount of green.
Nakor 22:66401b612b1b 414 * @param blue Amount of blue.
Nakor 26:5a2128799f60 415 *
Nakor 26:5a2128799f60 416 * Example:
Nakor 26:5a2128799f60 417 * @code
Nakor 29:757036aa73cd 418 * // Draw a blue pixel at (10x, 10y).
Nakor 26:5a2128799f60 419 * // (x, y, red, green, blue)
Nakor 26:5a2128799f60 420 * SGC.putPixel(10, 10, 0, 0, 255);
Nakor 26:5a2128799f60 421 * @endcode
Nakor 1:476dcc382de3 422 */
Nakor 22:66401b612b1b 423 bool putPixel(char x, char y, short red, short green, short blue);
Nakor 22:66401b612b1b 424
Nakor 22:66401b612b1b 425 /** Read the colour of a specified pixel.
Nakor 22:66401b612b1b 426 *
Nakor 22:66401b612b1b 427 * @param x X coordinate.
Nakor 22:66401b612b1b 428 * @param y Y coordinate.
Nakor 22:66401b612b1b 429 * @param returns 2 byte pixel colour in RGB format.
Nakor 22:66401b612b1b 430 * - MSB: R4R3R2R1R0G5G4G3
Nakor 22:66401b612b1b 431 * - LSB: G2G1G0B4B3B2B1B0
Nakor 26:5a2128799f60 432 *
Nakor 26:5a2128799f60 433 * Example:
Nakor 26:5a2128799f60 434 * @code
Nakor 26:5a2128799f60 435 * // Read pixel colour at location (20x, 20y).
Nakor 26:5a2128799f60 436 * short pixelColour = SGC.readPixel(20, 20);
Nakor 26:5a2128799f60 437 * @endcode
Nakor 1:476dcc382de3 438 */
Nakor 0:4f009971ac11 439 short readPixel(char x, char y);
Nakor 22:66401b612b1b 440
Nakor 7:c2fa784eb477 441 /** Replaces the background colour with a new colour.
Nakor 7:c2fa784eb477 442 *
Nakor 26:5a2128799f60 443 * Most functions call this internally.
Nakor 26:5a2128799f60 444 *
Nakor 13:f2b9f249bcff 445 * @param red Red value (0 to 255).
Nakor 13:f2b9f249bcff 446 * @param green Green value (0 to 255).
Nakor 13:f2b9f249bcff 447 * @param blue Blue value (0 to 255).
Nakor 26:5a2128799f60 448 *
Nakor 26:5a2128799f60 449 * Example:
Nakor 26:5a2128799f60 450 * @code
Nakor 26:5a2128799f60 451 * // Set background colour to red.
Nakor 26:5a2128799f60 452 * // (red, green, blue)
Nakor 26:5a2128799f60 453 * SGC.setBackgroundColour(255, 0, 0);
Nakor 26:5a2128799f60 454 * @endcode
Nakor 7:c2fa784eb477 455 */
Nakor 13:f2b9f249bcff 456 bool setBackgroundColour(char red, char green, char blue);
Nakor 22:66401b612b1b 457
Nakor 22:66401b612b1b 458 /** Set font (for future text).
Nakor 22:66401b612b1b 459 *
Nakor 22:66401b612b1b 460 * 3 default fonts are supplied. Further font sets can be added.
Nakor 22:66401b612b1b 461 *
Nakor 22:66401b612b1b 462 * @param font Font selection. Either a default or otherwise.
Nakor 22:66401b612b1b 463 * - DEFAULT: 0x00 = 5x7 small size font set
Nakor 22:66401b612b1b 464 * - DEFAULT: 0x01 = 8x8 medium size font set
Nakor 22:66401b612b1b 465 * - DEFAULT: 0x02 = 8x12 large size font set
Nakor 26:5a2128799f60 466 *
Nakor 26:5a2128799f60 467 * Example:
Nakor 26:5a2128799f60 468 * @code
Nakor 26:5a2128799f60 469 * // Use default 5x7 font set
Nakor 26:5a2128799f60 470 * SGC.setFont(0);
Nakor 26:5a2128799f60 471 * // Use default 8x12 font set
Nakor 26:5a2128799f60 472 * SGC.setFont(2);
Nakor 26:5a2128799f60 473 * @endcode
Nakor 7:c2fa784eb477 474 */
Nakor 22:66401b612b1b 475 bool setFont(char font);
Nakor 22:66401b612b1b 476
Nakor 22:66401b612b1b 477 /** Draw a text button to the screen.
Nakor 22:66401b612b1b 478 *
Nakor 22:66401b612b1b 479 * @param state Button down (0x00) or button up (0x01).
Nakor 22:66401b612b1b 480 * @param x Top left horizontal start position.
Nakor 22:66401b612b1b 481 * @param y Top left vertical start position.
Nakor 22:66401b612b1b 482 * @param red Amount of red (for button not text).
Nakor 22:66401b612b1b 483 * @param green Amount of green (for button not text).
Nakor 22:66401b612b1b 484 * @param blue Amount of blue (for button not text).
Nakor 22:66401b612b1b 485 * @param font Set which font set to use for the button. 3 default font sets are supplied and more can be added.
Nakor 22:66401b612b1b 486 * - DEFAULT: 0x00 = 5x7 small size font set
Nakor 22:66401b612b1b 487 * - DEFAULT: 0x01 = 8x8 medium size font set
Nakor 22:66401b612b1b 488 * - DEFAULT: 0x02 = 8x12 large size font set
Nakor 22:66401b612b1b 489 * @param textRed Amount of red for text.
Nakor 22:66401b612b1b 490 * @param textGreen Amount of green for text.
Nakor 22:66401b612b1b 491 * @param textBlue Amount of blue for text.
Nakor 22:66401b612b1b 492 * @param textWidth Width of characters (text). Affect total width of string and button.
Nakor 22:66401b612b1b 493 * @param textHeight Height of characters (text). Affects total height of string and button.
Nakor 22:66401b612b1b 494 * @param *text Character array (string) to display in the button.
Nakor 26:5a2128799f60 495 *
Nakor 26:5a2128799f60 496 * Example:
Nakor 26:5a2128799f60 497 * @code
Nakor 26:5a2128799f60 498 * // Draw a text button in the unpressed state starting at (0x, 0y).
Nakor 26:5a2128799f60 499 * // Button colour is red, text colour is white. Text magnification is zero (1x).
Nakor 26:5a2128799f60 500 * // (state, x, y, red, green, blue, font, textRed, textGreen, textBlue, textWidth, textHeight, "Text");
Nakor 26:5a2128799f60 501 * SGC.textButton(1, 0, 0, 255, 0, 0, 0, 255, 255, 255, 1, 1, "Button text");
Nakor 26:5a2128799f60 502 * @endcode
Nakor 1:476dcc382de3 503 */
Nakor 22:66401b612b1b 504 bool textButton(char state, char x, char y, short red, short green, short blue, char font, short textRed, short textGreen, short textBlue, char textWidth, char textHeight, char *text);
Nakor 22:66401b612b1b 505
Nakor 23:dd9a280c8be5 506 /** Set text mode (transparent or opaque).
Nakor 23:dd9a280c8be5 507 *
Nakor 23:dd9a280c8be5 508 * Opaque text has a rectangle drawn behind it (blocking out what is under it) and transparent text does not.
Nakor 23:dd9a280c8be5 509 *
Nakor 23:dd9a280c8be5 510 * @param mode Set text to transparent (0x00) or opaque (0x01).
Nakor 26:5a2128799f60 511 *
Nakor 26:5a2128799f60 512 * Example:
Nakor 26:5a2128799f60 513 * @code
Nakor 26:5a2128799f60 514 * // Set text mode to transparent.
Nakor 26:5a2128799f60 515 * SGC.textMode(0);
Nakor 26:5a2128799f60 516 * @endcode
Nakor 1:476dcc382de3 517 */
Nakor 0:4f009971ac11 518 bool textMode(char mode);
Nakor 23:dd9a280c8be5 519
Nakor 23:dd9a280c8be5 520 /** Retrieve current version info of the device.
Nakor 23:dd9a280c8be5 521 *
Nakor 23:dd9a280c8be5 522 * Response:
Nakor 23:dd9a280c8be5 523 *
Nakor 23:dd9a280c8be5 524 * device_type Indicates device type.
Nakor 23:dd9a280c8be5 525 * - 0x00 = micro-OLED
Nakor 23:dd9a280c8be5 526 * - 0x01 = micro-LCD
Nakor 23:dd9a280c8be5 527 * - 0x02 = micro-VGA
Nakor 24:22c2d08f111d 528 *
Nakor 23:dd9a280c8be5 529 * hardware_rev Indicates device hardware version.
Nakor 24:22c2d08f111d 530 *
Nakor 23:dd9a280c8be5 531 * firmware_rev Indicates device firmware version.
Nakor 24:22c2d08f111d 532 *
Nakor 23:dd9a280c8be5 533 * horizontal_res Indicates the horizontal resolution of the display.
Nakor 23:dd9a280c8be5 534 * - 0x22 = 220 pixels
Nakor 23:dd9a280c8be5 535 * - 0x28 = 128 pixels
Nakor 23:dd9a280c8be5 536 * - 0x32 = 320 pixels
Nakor 23:dd9a280c8be5 537 * - 0x60 = 160 pixels
Nakor 23:dd9a280c8be5 538 * - 0x64 = 64 pixels
Nakor 23:dd9a280c8be5 539 * - 0x76 = 176 pixels
Nakor 23:dd9a280c8be5 540 * - 0x96 = 96 pixels
Nakor 24:22c2d08f111d 541 *
Nakor 23:dd9a280c8be5 542 * vertical_res Indicates the vertical resolution of the display.
Nakor 23:dd9a280c8be5 543 * - See horizontal_res (identical).
Nakor 23:dd9a280c8be5 544 *
Nakor 23:dd9a280c8be5 545 * @param onScreen Set output option.
Nakor 23:dd9a280c8be5 546 * - 0x00 = Output to serial port only.
Nakor 23:dd9a280c8be5 547 * - 0x01 = Output to serial port and screen.
Nakor 23:dd9a280c8be5 548 * @param *info Character array to store results.
Nakor 26:5a2128799f60 549 *
Nakor 26:5a2128799f60 550 * Example:
Nakor 26:5a2128799f60 551 * @code
Nakor 26:5a2128799f60 552 * // Request version info, pass in character array to store results.
Nakor 29:757036aa73cd 553 * char info[5];
Nakor 26:5a2128799f60 554 * SGC.versionInfo(1, info);
Nakor 29:757036aa73cd 555 * printf("\n\nVersion info:\n\n");
Nakor 29:757036aa73cd 556 * for(int i = 0; i < 5; i++)
Nakor 29:757036aa73cd 557 * {
Nakor 29:757036aa73cd 558 * printf("0x%X\n", info[i]);
Nakor 29:757036aa73cd 559 * }
Nakor 26:5a2128799f60 560 * @endcode
Nakor 1:476dcc382de3 561 */
Nakor 29:757036aa73cd 562 bool versionInfo(bool onScreen, char info[5]);
Nakor 0:4f009971ac11 563
Nakor 0:4f009971ac11 564
Nakor 0:4f009971ac11 565 protected:
Nakor 0:4f009971ac11 566 Serial _oled;
Nakor 0:4f009971ac11 567 DigitalOut _reset;
Nakor 0:4f009971ac11 568
Nakor 0:4f009971ac11 569 void resetDisplay();
Nakor 8:0a92ceb34cd0 570 };
Nakor 8:0a92ceb34cd0 571
Nakor 8:0a92ceb34cd0 572 #endif