General graphics tool

Dependents:   EPD_GDE021A1_demo

Graphic.h

Committer:
steeven
Date:
2015-04-15
Revision:
0:404c38e71c68

File content as of revision 0:404c38e71c68:

/* mbed library for 264*176 pixel 2.7 INCH E-PAPER DISPLAY from Pervasive Displays
 * Copyright (c) 2013 Peter Drescher - DC2PD
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


// 09.11.2013   initial Version

#ifndef Graphic_H
#define Graphic_H

/**
 * Includes
 */
#include "mbed.h"

/** Bitmap
 */
struct Bitmap{
    int xSize;
    int ySize;
    int Byte_in_Line;
    char* data;
    };

/* color definitions   */
#define Black           0x0
#define White           0x3

/** Display control class, based on sDisplay and TextDisplay
 *
 * Example with pinning for KL25Z:
 * @code
 * #include "mbed.h"
 * #include "Graphic.h"
 * #include "Arial28x28.h" 
 * #include "Arial12x12.h"
 * #include "font_big.h"
 * #include "s.h"

 * // the E-Paper board from embedded artists has a LM75 temp sensor to compensate the temperature effect. If it is cold the display reacts slower.
 * // The LM75 need a I2C -> 2 pins : sda and scl 
 * // The display data is written via SPI -> 3 pins : mosi,miso,sck
 * // There are also some control signals 
 * // The pwm pin has to be connected to a PWM enabled pin : pwm
 * // The other signals are connected to normal IO`s
 * //              
 * Graphic epaper(PTD7,            // PWR_CTRL
 *                 PTD6,            // BORDER
 *                 PTE31,           // DISCHARGE
 *                 PTA17,           // RESET_DISP
 *                 PTA16,           // BUSY
 *                 PTC17,           // SSEL
 *                 PTD4,            // PWM
 *                 PTD2,PTD3,PTD1,  // MOSI,MISO,SCLK
 *                 PTE0,PTE1);      // SDA,SCL 
 *
 * int main() {
 *
 *   epaper.cls();                                  // clear screen                        
 *   epaper.set_font((unsigned char*) Arial28x28);  // select the font
 *   epaper.locate(5,20);                           // set cursor
 *   epaper.printf("Hello Mbed");                   // print text
 *   epaper.rect(3,15,150,50,1);                    // draw frame
 *   epaper.write_disp();                           // update screen
 *
 * @endcode
 */
 

class Graphic {

public:

    /**
     * Constructor.
     */ 
    Graphic(uint8_t *buf, int w, int h, int bits = 1);
    
    /**
     * Set color
     */
    void color(int foreground, int background);

    /**
     * Clear the display
     */    
    void clear();
    
    /**
     * set or reset a single pixel
     *
     * @param x horizontal position
     * @param y vertical position
     */ 
    void pixel(int x, int y, unsigned int color);
    
    
    /** draw a 1 pixel line
     *
     * @param x0,y0 start point
     * @param x1,y1 stop point
     */  
    void line(int x0, int y0, int x1, int y1);
    
    /** draw a rect
     *
     * @param x0,y0 top left corner
     * @param x1,y1 down right corner
     */    
    void rect(int x0, int y0, int x1, int y1);
    
    /** draw a filled rect
     *
     * @param x0,y0 top left corner
     * @param x1,y1 down right corner
     */  
    void fillrect(int x0, int y0, int x1, int y1);
    
    /** draw a circle
     *
     * @param x0,y0 center
     * @param r radius
     */    
    void circle(int x0, int y0, int r);
    
    /** draw a filled circle
     *
     * @param x0,y0 center
     * @param r radius
     */  
    void fillcircle(int x0, int y0, int r);
    
    /** setup cursor position
     *
     * @param x x-position (top left)
     * @param y y-position 
     */   
    void locate(int x, int y);
    
    /** calculate the max number of char in a line
     *
     * @returns max columns
     * depends on actual font size
     */ 
    int columns();
    
    /** calculate the max number of columns
     *
     * @returns max column
     * depends on actual font size
     */   
    int rows();
    
    /** put a char on the screen
     *
     * @param value char to print
     * @returns printed char
     */
    void putc(int value);
    
    /** print a string on the screen
     *
     * @param str string to print
     */
    void print(const char *str);

    /** select the font to use
     *
     * @param f pointer to font array 
     *                                                                              
     *   font array can created with GLCD Font Creator from http://www.mikroe.com
     *   you have to add 4 parameter at the beginning of the font array to use: 
     *   - the number of byte / char
     *   - the vertial size in pixel
     *   - the horizontal size in pixel
     *   - the number of byte per vertical line
     *   you also have to change the array to char[]
     */  
    void font(const unsigned char* f);
    
    /** print bitmap to buffer
      *
      * @param bm struct Bitmap in flash
      * @param x  x start
      * @param y  y start 
      *
      */
    void print_bm(Bitmap bm, int x, int y);
    
    

protected:


    uint8_t *_buf; //drawing buffer

    int _w; //screen width
    int _h; //screeen height
    char _bits; //per pix

    int _foreColor;
    int _backgroundColor;

    unsigned char* _font;
    int _charX;
    int _charY;

};
 
 #endif /* Graphic_H */