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