ERM19264_UC1609  1.8.0
Arduino Eco-system Library for ERM19264 LCD driven by UC1609 controller.
ERM19264_graphics.h
Go to the documentation of this file.
1 
10 #ifndef _ERM19264_GRAPHICS_H
11 #define _ERM19264_GRAPHICS_H
12 
13 #if ARDUINO >= 100
14  #include "Arduino.h"
15  #include "Print.h"
16 #else
17  #include "WProgram.h"
18 #endif
19 
20 #define ERM19264_swap(a, b) { int16_t t = a; a = b; b = t; }
21 
23 enum LCD_rotate_e : uint8_t
24 {
29 };
30 
32 enum LCD_Return_Codes_e : uint8_t
33 {
44 };
45 
47 enum LCD_Font_Type_e : uint8_t
48 {
60  UC1609Font_Dedica = 12
61 };
62 
64 class ERM19264_graphics : public Print {
65 
66  public:
67 
68  ERM19264_graphics(int16_t w, int16_t h);
69 
70  // This is defined by the subclass:
71  virtual void drawPixel(int16_t x, int16_t y, uint8_t color) = 0;
72 
73  // Shape related
74  void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color);
75  void drawFastVLine(int16_t x, int16_t y, int16_t h, uint8_t color);
76  void drawFastHLine(int16_t x, int16_t y, int16_t w, uint8_t color);
77  void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
78  void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
79  void fillScreen(uint8_t color);
80 
81  void drawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
82  void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
83  uint8_t color);
84  void fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
85  void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
86  int16_t delta, uint8_t color);
87  void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
88  int16_t x2, int16_t y2, uint8_t color);
89  void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
90  int16_t x2, int16_t y2, uint8_t color);
91  void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
92  int16_t radius, uint8_t color);
93  void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
94  int16_t radius, uint8_t color);
95 
96  // Bitmap related
97  LCD_Return_Codes_e drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
98  int16_t w, int16_t h, uint8_t color, uint8_t bg);
99  void setDrawBitmapAddr(boolean mode);
100 
101  // Text related
102  void setCursor(int16_t x, int16_t y);
103  void setTextColor(uint8_t c);
104  void setTextColor(uint8_t c, uint8_t bg);
105  void setTextSize(uint8_t s);
106  void setTextWrap(boolean w);
107  void setFontNum(LCD_Font_Type_e FontNumber);
108  LCD_Return_Codes_e drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color , uint8_t bg);
109  LCD_Return_Codes_e drawText(uint8_t x, uint8_t y, char *pText, uint8_t color, uint8_t bg);
110  LCD_Return_Codes_e drawChar(int16_t x, int16_t y, unsigned char c, uint8_t color, uint8_t bg, uint8_t s);
111  LCD_Return_Codes_e drawText(uint8_t x, uint8_t y, char *pTxt, uint8_t c, uint8_t bg, uint8_t s);
112 
113 #if ARDUINO >= 100
114  virtual size_t write(uint8_t);
115 #else
116  virtual void write(uint8_t);
117 #endif
118 
119  // Screen related
120  int16_t height(void) const;
121  int16_t width(void) const;
122  void setRotation(LCD_rotate_e );
124 
125  protected:
126 
127  const int16_t WIDTH;
128  const int16_t HEIGHT;
129  int16_t _width;
130  int16_t _height;
131  int16_t _cursorX;
132  int16_t _cursorY;
135  uint8_t _textColor= 0x00;
136  uint8_t _textBgColor= 0x01;
137  uint8_t _textSize= 1;
138  boolean _textWrap;
140  boolean drawBitmapAddr;
141 private:
143  enum LCD_Font_width_e : uint8_t
144  {
151  UC1609Font_width_16 = 16
152  };
153 
155  enum LCD_Font_offset_e : uint8_t
156  {
160  UC1609Font_offset_zero = 0x30
161  };
162 
164  enum LCD_Font_height_e : uint8_t
165  {
171  };
172 
174  enum LCD_Font_Length_e : uint8_t
175  {
180  UC1609FontLenAll = 255
181  };
182 
183  uint8_t _FontNumber = 1;
184  uint8_t _CurrentFontWidth =5;
185  uint8_t _CurrentFontoffset = 0;
186  uint8_t _CurrentFontheight = 8;
187  uint8_t _CurrentFontLength = 128;
189 };
190 
191 #endif
LCD_rotate_e
Definition: ERM19264_graphics.h:24
@ LCD_Degrees_270
Definition: ERM19264_graphics.h:28
@ LCD_Degrees_90
Definition: ERM19264_graphics.h:26
@ LCD_Degrees_180
Definition: ERM19264_graphics.h:27
@ LCD_Degrees_0
Definition: ERM19264_graphics.h:25
LCD_Font_Type_e
Definition: ERM19264_graphics.h:48
@ UC1609Font_ArialRound
Definition: ERM19264_graphics.h:57
@ UC1609Font_Default
Definition: ERM19264_graphics.h:49
@ UC1609Font_Thick
Definition: ERM19264_graphics.h:50
@ UC1609Font_Seven_Seg
Definition: ERM19264_graphics.h:51
@ UC1609Font_Tiny
Definition: ERM19264_graphics.h:53
@ UC1609Font_Dedica
Definition: ERM19264_graphics.h:60
@ UC1609Font_Wide
Definition: ERM19264_graphics.h:52
@ UC1609Font_Mia
Definition: ERM19264_graphics.h:59
@ UC1609Font_ArialBold
Definition: ERM19264_graphics.h:58
@ UC1609Font_Mednum
Definition: ERM19264_graphics.h:56
@ UC1609Font_Homespun
Definition: ERM19264_graphics.h:54
@ UC1609Font_Bignum
Definition: ERM19264_graphics.h:55
LCD_Return_Codes_e
Definition: ERM19264_graphics.h:33
@ LCD_BitmapNullptr
Definition: ERM19264_graphics.h:39
@ LCD_WrongFont
Definition: ERM19264_graphics.h:35
@ LCD_BitmapScreenBounds
Definition: ERM19264_graphics.h:40
@ LCD_CharFontASCIIRange
Definition: ERM19264_graphics.h:37
@ LCD_Success
Definition: ERM19264_graphics.h:34
@ LCD_CharScreenBounds
Definition: ERM19264_graphics.h:36
@ LCD_BitmapLargerThanScreen
Definition: ERM19264_graphics.h:41
@ LCD_BitmapVerticalSize
Definition: ERM19264_graphics.h:42
@ LCD_CharArrayNullptr
Definition: ERM19264_graphics.h:38
@ LCD_BitmapHorizontalSize
Definition: ERM19264_graphics.h:43
Graphics class to hold graphic related functions.
Definition: ERM19264_graphics.h:64
uint8_t _FontNumber
Definition: ERM19264_graphics.h:183
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
Fills a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).
Definition: ERM19264_graphics.cpp:345
virtual void write(uint8_t)
: called by the print class after it converts the data to a character
Definition: ERM19264_graphics.cpp:494
ERM19264_graphics(int16_t w, int16_t h)
init the LCD Graphics class object
Definition: ERM19264_graphics.cpp:26
void setRotation(LCD_rotate_e)
Sets the rotation of the display.
Definition: ERM19264_graphics.cpp:961
LCD_Font_height_e
Definition: ERM19264_graphics.h:165
@ UC1609Font_height_8
Definition: ERM19264_graphics.h:166
@ UC1609Font_height_32
Definition: ERM19264_graphics.h:170
@ UC1609Font_height_24
Definition: ERM19264_graphics.h:169
@ UC1609Font_height_16
Definition: ERM19264_graphics.h:168
@ UC1609Font_height_12
Definition: ERM19264_graphics.h:167
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint8_t color)
Draws a vertical line starting at (x,y) with height h.
Definition: ERM19264_graphics.cpp:239
void setDrawBitmapAddr(boolean mode)
sets the data addressing mode in drawBitmap function.
Definition: ERM19264_graphics.cpp:674
boolean drawBitmapAddr
Definition: ERM19264_graphics.h:140
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color)
draws a circle where (x0,y0) are center coordinates an r is circle radius.
Definition: ERM19264_graphics.cpp:47
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint8_t color)
Used internally by drawRoundRect.
Definition: ERM19264_graphics.cpp:84
boolean _textWrap
Definition: ERM19264_graphics.h:138
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color)
draws a line from (x0,y0) to (x1,y1).
Definition: ERM19264_graphics.cpp:174
LCD_Return_Codes_e drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint8_t color, uint8_t bg)
Draw a 1-bit color bitmap.
Definition: ERM19264_graphics.cpp:425
int16_t _height
Definition: ERM19264_graphics.h:130
void setTextColor(uint8_t c)
set the text color
Definition: ERM19264_graphics.cpp:646
LCD_Font_width_e
Definition: ERM19264_graphics.h:144
@ UC1609Font_width_16
Definition: ERM19264_graphics.h:151
@ UC1609Font_width_6
Definition: ERM19264_graphics.h:148
@ UC1609Font_width_8
Definition: ERM19264_graphics.h:150
@ UC1609Font_width_4
Definition: ERM19264_graphics.h:146
@ UC1609Font_width_7
Definition: ERM19264_graphics.h:149
@ UC1609Font_width_5
Definition: ERM19264_graphics.h:147
@ UC1609Font_width_3
Definition: ERM19264_graphics.h:145
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color)
fills a circle where (x0,y0) are center coordinates an r is circle radius.
Definition: ERM19264_graphics.cpp:127
LCD_rotate_e getRotation(void)
Gets the _rotation of the display.
Definition: ERM19264_graphics.cpp:954
LCD_Return_Codes_e drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t bg)
writes a char (c) on the LCD
Definition: ERM19264_graphics.cpp:793
void setTextWrap(boolean w)
turn on or off screen _textWrap of the text (fonts 1-6)
Definition: ERM19264_graphics.cpp:664
LCD_rotate_e LCD_rotate
Definition: ERM19264_graphics.h:133
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint8_t color)
draws a rectangle with rounded edges
Definition: ERM19264_graphics.cpp:288
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint8_t color)
Draws a horizontal line starting at (x,y) with width w.
Definition: ERM19264_graphics.cpp:251
uint8_t _CurrentFontoffset
Definition: ERM19264_graphics.h:185
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color)
draws rectangle at (x,y) where h is height and w is width of the rectangle.
Definition: ERM19264_graphics.cpp:223
int16_t _width
Definition: ERM19264_graphics.h:129
int16_t height(void) const
Gets the height of the display (per current rotation)
Definition: ERM19264_graphics.cpp:688
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint8_t color)
Fills a rectangle with rounded edges.
Definition: ERM19264_graphics.cpp:310
const int16_t WIDTH
Definition: ERM19264_graphics.h:127
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint8_t color)
Used internally by fill circle fillRoundRect and fillcircle.
Definition: ERM19264_graphics.cpp:136
uint8_t _textBgColor
Definition: ERM19264_graphics.h:136
void setTextSize(uint8_t s)
set the text size , starts at 1
Definition: ERM19264_graphics.cpp:638
uint8_t _CurrentFontWidth
Definition: ERM19264_graphics.h:184
uint8_t _CurrentFontheight
Definition: ERM19264_graphics.h:186
void setFontNum(LCD_Font_Type_e FontNumber)
Set the font type.
Definition: ERM19264_graphics.cpp:694
const int16_t HEIGHT
Definition: ERM19264_graphics.h:128
int16_t width(void) const
Gets the width of the display (per current rotation)
Definition: ERM19264_graphics.cpp:682
LCD_Return_Codes_e drawText(uint8_t x, uint8_t y, char *pText, uint8_t color, uint8_t bg)
Writes text string (*ptext) on the LCD.
Definition: ERM19264_graphics.cpp:884
LCD_Font_offset_e
Definition: ERM19264_graphics.h:156
@ UC1609Font_offset_none
Definition: ERM19264_graphics.h:157
@ UC1609Font_offset_zero
Definition: ERM19264_graphics.h:160
@ UC1609Font_offset_minus
Definition: ERM19264_graphics.h:159
@ UC1609Font_offset_space
Definition: ERM19264_graphics.h:158
uint8_t _CurrentFontLength
Definition: ERM19264_graphics.h:187
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
draws a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).
Definition: ERM19264_graphics.cpp:327
uint8_t _textSize
Definition: ERM19264_graphics.h:137
void fillScreen(uint8_t color)
Fills the whole screen with a given color.
Definition: ERM19264_graphics.cpp:275
LCD_Font_Length_e
Definition: ERM19264_graphics.h:175
@ UC1609FontLenNumeric
Definition: ERM19264_graphics.h:176
@ UC1609FontLenAlphaNumNoLCase
Definition: ERM19264_graphics.h:177
@ UC1609FontLenAlphaNum
Definition: ERM19264_graphics.h:178
@ UC1609FontLenAll
Definition: ERM19264_graphics.h:180
@ UC1609FontLenHalf
Definition: ERM19264_graphics.h:179
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color)
fills a rectangle starting from coordinates (x,y) with width of w and height of h.
Definition: ERM19264_graphics.cpp:264
int16_t _cursorX
Definition: ERM19264_graphics.h:131
uint8_t _textColor
Definition: ERM19264_graphics.h:135
void setCursor(int16_t x, int16_t y)
set the cursor position
Definition: ERM19264_graphics.cpp:629
int16_t _cursorY
Definition: ERM19264_graphics.h:132