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