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

Committer:
Nakor
Date:
2010-12-26
Revision:
24:22c2d08f111d
Parent:
23:dd9a280c8be5
Child:
25:caf134ebfc34

File content as of revision 24:22c2d08f111d:

/* mbed 4D uOLED Library
 * Originally designed for use with uOLED-96-G1 (SGC)
 * serially controlled .96" screen.
 *
 * This is a modified library originally obtained from
 * Erik van Wijk's library code at:
 * http://mbed.org/users/evwijk/libraries/microOLED/li4nzn
 *
 * This library (uOLED) by Aaron Goselin.
 * 2010
 */

#ifndef _MBED_UOLED_
#define _MBED_UOLED_

#include "mbed.h"

#define     OLED_FONT5X7                    0x01
#define     OLED_FONT8X8                    0x02
#define     OLED_FONT8X12                   0x03

#define     OLED_DISPLAYCONTROL_DISPLAY     0x01
#define     OLED_DISPLAYCONTROL_CONTRAST    0x02
#define     OLED_DISPLAYCONTROL_POWER       0x03

/** uOLED control class using Serial
 *
 * Example:
 * @code
 * // Draw text on the screen.
 * #include "mbed.h"
 * #include "uOLED.h"
 * 
 * uOLED SGC(p9, p10, p11);
 *
 * int main()
 * {    
 *     SGC.drawText(0, 0, 0, FF, "This is text");
 * }
 * @endcode
 */
class uOLED {
public:

    /** Create an instance of the uOLED class.
    * 
    * @param serialTX - mbed TX pin to be used
    * @param serialRX - mbed RX pin to be used
    * @param reset - mbed pin to control reset of the uOLED
    */
    uOLED(PinName serialTX, PinName serialRX, PinName reset);
    
    /** Convert RGB value into the type of value that the uOLED wants.
    * 
    * @param red Red value.
    * @param green Green value.
    * @param blue Blue value.
    */
    short getRGB(char red, char green, char blue);

    /** !!ToDo!!
    * 
    * @param returns something.
    */
    bool addBitmappedCharacter(char character, char data[8]);
    
    /** !!ToDO!!
    * 
    * @param returns something.
    */
    bool blockCopyPaste(char sourceX, char sourceY, char destinationX, char destinationY, char width, char height);
    
    /** Display control.
    * 
    * Display ON/OFF, set contrast, and PowerUp/Shutdown.
    *
    * @param mode Sets specified mode.
    * @param value Value option for mode.
    *
    * - Mode: 01 Display ON/OFF
    *   - Value: 00 OFF
    *   - Value: 01 ON
    * - Mode: 02 Contrast Adjust
    *   - Value range: 0x00 to 0x0F
    * - Mode: 03 Display PowerUp/Shutdown (low power mode)
    *   - Value 00 Shutdown
    *   - Value 01 Powerup
    */
    bool displayControl(char mode, char value);
    
    /** !!ToDo!!
    * 
    * @param returns something.
    */
    bool displayUserBitmappedCharacter(char character, char x, char y, short color);
    
    /** Draw a circle.
    * 
    * @param x X position of circle center.
    * @param y Y position of circle center.
    * @param radius Radius of the circle.
    * @param red Amount of red.
    * @param green Amount of green.
    * @param blue Amount of blue.
    */
    bool drawCircle(char x, char y, char radius, short red, short green, short blue);
    
    /** !!ToDo!!
    * 
    * @param returns something.
    */
    bool drawCharacter(char character, char column, char row, short color);
    
    /** !!ToDo!!
    * 
    * @param returns something.
    */
    bool drawImage(char x, char y, char width, char height, char colorMode, char *pixels);
    
    /** Draw a line.
    * 
    * @param x1 Top left horizontal start position.
    * @param y1 Top left vertical start position.
    * @param x2 Bottom right horizontal start position.
    * @param y2 Bottom right vertical end position.
    * @param red Amount of red.
    * @param green Amount of green.
    * @param blue Amount of blue.
    */
    bool drawLine(char x1, char y1, char x2, char y2, short red, short green, short blue);
    
    /** !!ToDo!!
    * 
    * @param returns something.
    */
    bool drawPolygon(char vertices, char *x, char *y, short color);
    
    /** Draw a rectangle.
    * 
    * @param x Top left horizontal start position.
    * @param y Top left vertical start position.
    * @param width Bottom right horizontal end position.
    * @param height Bottom right vertical end position.
    * @param red Amount of red.
    * @param green Amount of green.
    * @param blue Amount of blue.
    */
    bool drawRectangle(char x, char y, char width, char height, short red, short green, short blue);
    
    /** Draw text to the screen.
    * 
    * @param column X coordinate for text placement.
    * @param row Y coordinate for text placement.
    * @param font Which font to use (Uses 0, 1, or 2).  More fonts can be added.
    * @param color Font colour to use.
    * @param *text Character array (string) to be displayed.
    *
    * Example:
    * @code
    * SGC.drawText(0, 0, 0, FF, "This is text");
    * @endcode
    */
    bool drawText(char column, char row, char font, short red, short green, short blue, char *text);
    
    /** Draw unformated text to the screen.
    * The manual describes this as "graphics format".
    *
    * @param x X coordinate for text placement.
    * @param y Y coordinate for text placement.
    * @param font Which font to use (Uses 0, 1, or 2).  More fonts can be added.
    * @param red Amount of red in text colour RGB value.
    * @param green Amount of green in text colour RGB value.
    * @param blue Amount of blue in text colour RGB value.
    * @param width Text width.
    * @param height Text height.
    * @param *text Character array (string) to be displayed.
    *
    * Example:
    * @code
    * SGC.drawTextUF(0, 0, 0, 20, 20, 255, 1, 1, "This is text");
    * @endcode
    */
    bool drawTextUF(char x, char y, char font, short red, short green, short blue, char width, char height, char *text);
    
    /** Draw a triangle.
    *
    * Vertices must be defined counter clockwise.
    *
    * @param x1 Vertice 1 X coordinate.
    * @param y1 Vertice 1 Y coordinate.
    * @param x2 Vertice 2 X coordinate.
    * @param y2 Vertice 2 Y coordinate.
    * @param x3 Vertice 3 X coordinate.
    * @param y3 Vertice 3 Y coordinate.
    * @param red Amount of red.
    * @param blue Amount of blue.
    * @param green Amount of green.
    */
    bool drawTriangle(char x1, char y1, char x2, char y2, char x3, char y3, short red, short green, short blue);
    
    /** Clear the screen.
    * 
    * Remove everything except the background colour.
    *
    * @param returns success or failure.
    */
    bool eraseScreen();
    
    /** Initialize the screen.  This must be completed before any other communication with the device.
    *
    * Timing allows for at least 500ms delay for initialization.
    *
    * @param returns bool indicating success or failure of initialization.
    */
    bool init();
    
    /** Set pen size.
    * 
    * Sets if objects should be drawn solid or wire frame.
    * Does not apply to polygon function.
    *
    * @param size Sets solid or wire frame.
    * - 0x00 = Solid
    * - 0x01 = Wire frame.
    */
    bool penSize(char size);
    
    /** Draw a coloured pixel at designated position.
    * 
    * @param x Horizontal position of pixel.
    * @param y Vertical position of pixel.
    * @param red Amount of red.
    * @param green Amount of green.
    * @param blue Amount of blue.
    */
    bool putPixel(char x, char y, short red, short green, short blue);
    
    /** Read the colour of a specified pixel.
    * 
    * @param x X coordinate.
    * @param y Y coordinate.
    * @param returns 2 byte pixel colour in RGB format.
    * - MSB: R4R3R2R1R0G5G4G3
    * - LSB: G2G1G0B4B3B2B1B0
    */
    short readPixel(char x, char y);
    
    /** Replaces the background colour with a new colour.
    * 
    * @param red Red value (0 to 255).
    * @param green Green value (0 to 255).
    * @param blue Blue value (0 to 255).
    */
    bool setBackgroundColour(char red, char green, char blue);
    
    /** Set font (for future text).
    *
    * 3 default fonts are supplied.  Further font sets can be added.
    * 
    * @param font Font selection.  Either a default or otherwise.
    * - DEFAULT: 0x00 = 5x7 small size font set
    * - DEFAULT: 0x01 = 8x8 medium size font set
    * - DEFAULT: 0x02 = 8x12 large size font set
    */    
    bool setFont(char font);
    
    /** Draw a text button to the screen.
    * 
    * @param state Button down (0x00) or button up (0x01).
    * @param x Top left horizontal start position.
    * @param y Top left vertical start position.
    * @param red Amount of red (for button not text).
    * @param green Amount of green (for button not text).
    * @param blue Amount of blue (for button not text).
    * @param font Set which font set to use for the button.  3 default font sets are supplied and more can be added.
    * - DEFAULT: 0x00 = 5x7 small size font set
    * - DEFAULT: 0x01 = 8x8 medium size font set
    * - DEFAULT: 0x02 = 8x12 large size font set
    * @param textRed Amount of red for text.
    * @param textGreen Amount of green for text.
    * @param textBlue Amount of blue for text.
    * @param textWidth Width of characters (text).  Affect total width of string and button.
    * @param textHeight Height of characters (text).  Affects total height of string and button.
    * @param *text Character array (string) to display in the button.
    */
    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);
    
    /** Set text mode (transparent or opaque).
    *
    * Opaque text has a rectangle drawn behind it (blocking out what is under it) and transparent text does not.
    * 
    * @param mode Set text to transparent (0x00) or opaque (0x01).
    */
    bool textMode(char mode);
    
    /** Retrieve current version info of the device.
    * 
    * Response:
    * 
    * device_type Indicates device type.
    * - 0x00 = micro-OLED
    * - 0x01 = micro-LCD
    * - 0x02 = micro-VGA
    *
    * hardware_rev Indicates device hardware version.
    *
    * firmware_rev Indicates device firmware version.
    *
    * horizontal_res Indicates the horizontal resolution of the display.
    * - 0x22 = 220 pixels
    * - 0x28 = 128 pixels
    * - 0x32 = 320 pixels
    * - 0x60 = 160 pixels
    * - 0x64 = 64 pixels
    * - 0x76 = 176 pixels
    * - 0x96 = 96 pixels
    *
    * vertical_res Indicates the vertical resolution of the display.
    * - See horizontal_res (identical).
    *
    * @param onScreen Set output option.
    * - 0x00 = Output to serial port only.
    * - 0x01 = Output to serial port and screen.
    * @param *info Character array to store results.
    */
    bool versionInfo(bool onScreen, char *info);
    
    
protected:
    Serial      _oled;
    DigitalOut  _reset;
    
    void resetDisplay();
};

#endif