General graphics tool

Dependents:   EPD_GDE021A1_demo

Embed: (wiki syntax)

« Back to documentation index

Graphic Class Reference

Graphic Class Reference

Display control class, based on sDisplay and TextDisplay. More...

#include <Graphic.h>

Public Member Functions

 Graphic (uint8_t *buf, int w, int h, int bits=1)
 Constructor.
void color (int foreground, int background)
 Set color.
void clear ()
 Clear the display.
void pixel (int x, int y, unsigned int color)
 set or reset a single pixel
void line (int x0, int y0, int x1, int y1)
 draw a 1 pixel line
void rect (int x0, int y0, int x1, int y1)
 draw a rect
void fillrect (int x0, int y0, int x1, int y1)
 draw a filled rect
void circle (int x0, int y0, int r)
 draw a circle
void fillcircle (int x0, int y0, int r)
 draw a filled circle
void locate (int x, int y)
 setup cursor position
int columns ()
 calculate the max number of char in a line
int rows ()
 calculate the max number of columns
void putc (int value)
 put a char on the screen
void print (const char *str)
 print a string on the screen
void font (const unsigned char *f)
 select the font to use
void print_bm (Bitmap bm, int x, int y)
 print bitmap to buffer

Detailed Description

Display control class, based on sDisplay and TextDisplay.

Example with pinning for KL25Z:

 #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

Definition at line 78 of file Graphic.h.


Constructor & Destructor Documentation

Graphic ( uint8_t *  buf,
int  w,
int  h,
int  bits = 1 
)

Constructor.

Definition at line 7 of file Graphic.cpp.


Member Function Documentation

void circle ( int  x0,
int  y0,
int  r 
)

draw a circle

Parameters:
x0,y0center
rradius

Definition at line 150 of file Graphic.cpp.

void clear (  )

Clear the display.

Definition at line 14 of file Graphic.cpp.

void color ( int  foreground,
int  background 
)

Set color.

Definition at line 20 of file Graphic.cpp.

int columns (  )

calculate the max number of char in a line

Returns:
max columns depends on actual font size

Definition at line 193 of file Graphic.cpp.

void fillcircle ( int  x0,
int  y0,
int  r 
)

draw a filled circle

Parameters:
x0,y0center
rradius

Definition at line 170 of file Graphic.cpp.

void fillrect ( int  x0,
int  y0,
int  x1,
int  y1 
)

draw a filled rect

Parameters:
x0,y0top left corner
x1,y1down right corner

Definition at line 128 of file Graphic.cpp.

void font ( const unsigned char *  f )

select the font to use

Parameters:
fpointer 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[]

Definition at line 252 of file Graphic.cpp.

void line ( int  x0,
int  y0,
int  x1,
int  y1 
)

draw a 1 pixel line

Parameters:
x0,y0start point
x1,y1stop point

Definition at line 46 of file Graphic.cpp.

void locate ( int  x,
int  y 
)

setup cursor position

Parameters:
xx-position (top left)
yy-position

Definition at line 187 of file Graphic.cpp.

void pixel ( int  x,
int  y,
unsigned int  color 
)

set or reset a single pixel

Parameters:
xhorizontal position
yvertical position

Definition at line 27 of file Graphic.cpp.

void print ( const char *  str )

print a string on the screen

Parameters:
strstring to print

Definition at line 256 of file Graphic.cpp.

void print_bm ( Bitmap  bm,
int  x,
int  y 
)

print bitmap to buffer

Parameters:
bmstruct Bitmap in flash
xx start
yy start

Definition at line 263 of file Graphic.cpp.

void putc ( int  value )

put a char on the screen

Parameters:
valuechar to print
Returns:
printed char

Definition at line 205 of file Graphic.cpp.

void rect ( int  x0,
int  y0,
int  x1,
int  y1 
)

draw a rect

Parameters:
x0,y0top left corner
x1,y1down right corner

Definition at line 104 of file Graphic.cpp.

int rows (  )

calculate the max number of columns

Returns:
max column depends on actual font size

Definition at line 199 of file Graphic.cpp.