Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
color16_graphics Class Referenceabstract

Class to handle fonts and graphics of color 16 bit display. More...

#include <color16_graphics_RDL.hpp>

Inheritance diagram for color16_graphics:
Inheritance graph
[legend]

Public Types

enum  pixel_color565_e : uint16_t {
  RDLC_BLACK = 0x0000 , RDLC_BLUE = 0x001F , RDLC_RED = 0xF800 , RDLC_GREEN = 0x07E0 ,
  RDLC_CYAN = 0x07FF , RDLC_MAGENTA = 0xF81F , RDLC_YELLOW = 0xFFE0 , RDLC_WHITE = 0xFFFF ,
  RDLC_TAN = 0xED01 , RDLC_GREY = 0x9CD1 , RDLC_BROWN = 0x6201 , RDLC_DGREEN = 0x01C0 ,
  RDLC_ORANGE = 0xFC00 , RDLC_NAVY = 0x000F , RDLC_DCYAN = 0x03EF , RDLC_MAROON = 0x7800 ,
  RDLC_PURPLE = 0x780F , RDLC_OLIVE = 0x7BE0 , RDLC_LGREY = 0xC618 , RDLC_DGREY = 0x7BEF ,
  RDLC_GYELLOW = 0xAFE5 , RDLC_PINK = 0xFC18 , RDLC_LBLUE = 0x7E5F , RDLC_BEIGE = 0xB5D2
}
 16-bit color definitions (RGB565 format). More...
 
enum  display_rotate_e : uint8_t { Degrees_0 = 0 , Degrees_90 , Degrees_180 , Degrees_270 }
 
- Public Types inherited from Print
enum  BaseNum : uint8_t { RDL_DEC = 10 , RDL_HEX = 16 , RDL_OCT = 8 , RDL_BIN = 2 }
 

Public Member Functions

 color16_graphics ()
 Construct a new graphics class object.
 
virtual void setAddrWindow (uint16_t, uint16_t, uint16_t, uint16_t)=0
 define in the sub class
 
void fillScreen (uint16_t color)
 Fills the whole screen with a given color.
 
void setCursor (int16_t x, int16_t y)
 Set the Cursor Position on screen.
 
void drawPixel (uint16_t, uint16_t, uint16_t)
 Draw a pixel to screen.
 
rdlib::Return_Codes_e drawDotGrid (int16_t x, int16_t y, int16_t w, int16_t h, uint8_t DotGridGap, uint16_t color)
 Draws a grid of dots on the screen starting from the given coordinates. This function draws a grid of pixels with a specified gap between them. It checks that the provided coordinates and dimensions are within the screen bounds and adjusts them if necessary. It also validates The grid of dots gap value and defaults it to 2 if invalid.
 
void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
 draws a line from (x0,y0) to (x1,y1).
 
rdlib::Return_Codes_e drawFastVLine (uint16_t x, uint16_t y, uint16_t h, uint16_t color)
 Draws a vertical line starting at (x,y) with height h.
 
rdlib::Return_Codes_e drawFastHLine (uint16_t x, uint16_t y, uint16_t w, uint16_t color)
 Draws a horizontal line starting at (x,y) with width w.
 
void drawLineAngle (int16_t x, int16_t y, int angle, uint8_t start, uint8_t length, int offset, uint16_t color)
 Draws a line using an angle and length as parameters. This function draws a line starting from (x, y), extending in the direction specified by angle, with a given length. The function also allows applying an offset to the angle before computing the line’s end coordinates.
 
void drawRectWH (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
 draws rectangle at (x,y) where h is height and w is width of the rectangle.
 
rdlib::Return_Codes_e fillRectangle (uint16_t, uint16_t, uint16_t, uint16_t, uint16_t)
 fills a rectangle starting from coordinates (x,y) with width of w and height of h.
 
void fillRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
 fills a rectangle at (x,y) where h is height and w is width of the rectangle.
 
void drawRoundRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t color)
 draws a rectangle with rounded edges
 
void fillRoundRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t color)
 Fills a rectangle with rounded edges.
 
void drawCircle (int16_t x0, int16_t y0, int16_t r, uint16_t color)
 draws a circle where (x0,y0) are center coordinates an r is circle radius.
 
void fillCircle (int16_t x0, int16_t y0, int16_t r, uint16_t color)
 fills a circle where (x0,y0) are center coordinates an r is circle radius.
 
void drawEllipse (int16_t cx, int16_t cy, int16_t semiMajorAxis, int16_t semiMinorAxis, bool fill, uint16_t color)
 Draw an ellipse on the display. This function uses the midpoint ellipse algorithm to efficiently draw an ellipse centered at (cx, cy) with the given semi-major (horizontal) and semi-minor (vertical) axes.
 
void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
 draws a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).
 
void fillTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
 Fills a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).
 
void drawQuadrilateral (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint16_t color)
 Draws a quadrilateral (four-sided polygon) by connecting four points with lines. This function draws a quadrilateral by drawing four lines between the given vertices. The lines are drawn in the order: (x0, y0) to (x1, y1), (x1, y1) to (x2, y2), (x2, y2) to (x3, y3), and finally (x3, y3) back to (x0, y0).
 
void fillQuadrilateral (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint16_t color, bool useTriangleSplit=true)
 Fills a quadrilateral with the specified color using triangles. This function fills a quadrilateral by dividing it into triangles and filling them individually. The quadrilateral is filled by calling the fillTriangle function three times with appropriate vertex coordinates. The useTriangleSplit parameter determines whether the quadrilateral is divided into two triangles or if only one triangle is used.
 
rdlib::Return_Codes_e drawPolygon (int16_t x, int16_t y, uint8_t sides, int16_t diameter, float rotation, bool fill, uint16_t color)
 Draws a polygon with a specified number of sides, diameter, rotation, and color. This function draws a regular polygon by connecting points equally spaced around a circle, with each point having a distance defined by the diameter. The polygon is rotated by the given angle (in degrees) before being drawn. The number of sides is enforced to be at least 3.
 
void drawSimpleArc (int16_t cx, int16_t cy, int16_t radius, float startAngle, float endAngle, uint16_t color)
 Draw a simple arc of one pixel on the display( no offsets , thickness or maximum arc calculations) This function draws an arc between two angles (start and end) on a circle with a given radius.
 
void drawArc (uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness, float startAngle, float endAngle, uint16_t color)
 Draw an arc on the TFT display. This function draws an arc between two angles (start and end) on a circle with a given radius.
 
float getArcAngleMax () const
 Get the current maximum angle of the arc.
 
void setArcAngleMax (float arcAngleMax)
 Set a new maximum angle for the arc.
 
int getArcAngleOffset () const
 Get the current angle offset.
 
void setArcAngleOffset (int arcAngleOffset)
 Set a new angle offset.
 
virtual size_t write (uint8_t) override
 write method used in the print class when user calls print
 
rdlib::Return_Codes_e writeChar (int16_t x, int16_t y, char value)
 Write 1 character on Display.
 
rdlib::Return_Codes_e writeCharString (int16_t x, int16_t y, char *text)
 Write Text character array on display.
 
void setTextWrap (bool w)
 turn on or off screen wrap of the text (fonts 1-6)
 
void setTextColor (uint16_t c, uint16_t bg)
 Set text color foreground and background.
 
void setTextColor (uint16_t c)
 Set text color foreground.
 
rdlib::Return_Codes_e drawIcon (uint16_t x, uint16_t y, uint16_t w, uint16_t color, uint16_t bgcolor, const std::span< const uint8_t > data)
 Draws an custom Icon of X by 8 size to screen , where X = 0 to 127.
 
rdlib::Return_Codes_e drawBitmap (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t bgcolor, const std::span< const uint8_t > data)
 : Draws an bi-color bitmap to screen
 
rdlib::Return_Codes_e drawBitmap24 (uint16_t x, uint16_t y, const std::span< const uint8_t > data, uint16_t w, uint16_t h)
 Draws an 24 bit color bitmap to screen from a data array.
 
rdlib::Return_Codes_e drawBitmap16 (uint16_t x, uint16_t y, const std::span< const uint8_t > data, uint16_t w, uint16_t h)
 : Draws an 16 bit color bitmap to screen from a data array
 
rdlib::Return_Codes_e drawSprite (uint16_t x, uint16_t y, const std::span< const uint8_t > data, uint16_t w, uint16_t h, uint16_t backgroundColor)
 : Draws an 16 bit color sprite bitmap to screen with transparent background
 
int16_t Color565 (int16_t, int16_t, int16_t)
 : Convert: 24-bit color to 565 16-bit color
 
int getDisplaySPIBlockSize () const
 Gets the maximum SPI transaction block size.
 
void setDisplaySPIBlockSize (int size)
 Sets the maximum SPI transaction block size.
 
- Public Member Functions inherited from display_Fonts
 display_Fonts ()
 init the OLED font class object constructor
 
rdlib::Return_Codes_e setFont (display_Font_name_e)
 SetFont.
 
void setInvertFont (bool invertStatus)
 setInvertFont
 
bool getInvertFont (void)
 getInvertFont
 
- Public Member Functions inherited from Print
int getWriteError ()
 gets the error flag status, zero no error
 
void clearWriteError ()
 clears the error flag by setting it to zero
 
virtual size_t write (const uint8_t *buffer, size_t size)
 define in the sub class
 
size_t write (const char *str)
 Writes a string to the output.
 
size_t write (const char *buffer, size_t size)
 Writes a buffer of a specified size to the output.
 
virtual int availableForWrite ()
 define in the sub class
 
size_t print (const char[])
 print an array
 
size_t print (char)
 print an character
 
size_t print (int, int=RDL_DEC)
 print an integer of base number system
 
size_t print (unsigned int, int=RDL_DEC)
 print an unsigned integer of base number system
 
size_t print (long, int=RDL_DEC)
 print an long integer of base number system
 
size_t print (unsigned long, int=RDL_DEC)
 print an unsigned long integer of base number system
 
size_t print (double, int=2)
 print an double
 
size_t print (const std::string &)
 print an C++ string object
 
size_t println (const char[])
 Prints a character array followed by a newline.
 
size_t println (char)
 print an character followed by new line
 
size_t println (int, int=RDL_DEC)
 print an integer of base number system followed by new line
 
size_t println (unsigned int, int=RDL_DEC)
 print an unsigned integer of base number system followed by new line
 
size_t println (long, int=RDL_DEC)
 print an long integer of base number system followed by new line
 
size_t println (unsigned long, int=RDL_DEC)
 print an unsigned long integer of base number system followed by new line
 
size_t println (double, int=2)
 print an double
 
size_t println (void)
 Goto to new line.
 
size_t println (const std::string &s)
 print an C++ string object followed by new line
 
template<typename T >
size_t print (const std::vector< T > &v, int format=defaultFormat< T >())
 Print a vector of any type.
 
template<typename T >
size_t println (const std::vector< T > &vec, int format=defaultFormat< T >())
 Print a vector of elements followed by a newline.
 
template<typename T , size_t N>
size_t print (const std::array< T, N > &arr, int format=defaultFormat< T >())
 Print a std::array of any type.
 
template<typename T , size_t N>
size_t println (const std::array< T, N > &arr, int format=defaultFormat< T >())
 Print a std::array of elements followed by a newline.
 

Protected Member Functions

void pushColor (uint16_t color)
 pushColor
 
void writeCommand (uint8_t)
 : Write an SPI command to
 
void writeData (uint8_t)
 Write an SPI data byte to device.
 
void spiWrite (uint8_t)
 Write byte to SPI.
 
void spiWriteDataBuffer (uint8_t *spidata, int len)
 Write a buffer to SPI, both Software and hardware SPI supported.
 
- Protected Member Functions inherited from Print
void setWriteError (int err=0)
 

Protected Attributes

bool _textwrap = true
 
uint16_t _textcolor = 0xFFFF
 
uint16_t _textbgcolor = 0x0000
 
int16_t _cursorX = 0
 
int16_t _cursorY = 0
 
uint16_t _width
 
uint16_t _height
 
uint8_t _XStart = 0
 
uint8_t _YStart = 0
 
float _arcAngleMax = 360.0f
 
int _arcAngleOffset = 0
 
int8_t _Display_DC
 
int8_t _Display_RST
 
int8_t _Display_CS
 
int8_t _Display_SCLK
 
int8_t _Display_SDATA
 
int8_t _Display_MISO
 
int _DeviceNumGpioChip = 0
 
int _GpioHandle = 0
 
bool _hardwareSPI =true
 
uint16_t _HighFreqDelay = 0
 
int _spiHandle = 0
 
- Protected Attributes inherited from display_Fonts
std::span< const uint8_t > _FontSelect = pFontDefault
 
uint8_t _Font_X_Size = 0x08
 
uint8_t _Font_Y_Size = 0x08
 
uint8_t _FontOffset = 0x20
 
uint8_t _FontNumChars = 0x5F
 

Private Attributes

int _Display_SPI_BLK_SIZE = 65536
 

Detailed Description

Class to handle fonts and graphics of color 16 bit display.

Member Enumeration Documentation

◆ display_rotate_e

TFT rotate modes in degrees

Enumerator
Degrees_0 

No rotation 0 degrees

Degrees_90 

Rotation 90 degrees

Degrees_180 

Rotation 180 degrees

Degrees_270 

Rotation 270 degrees

◆ pixel_color565_e

16-bit color definitions (RGB565 format).

Enumerator
RDLC_BLACK 

Black

RDLC_BLUE 

Blue

RDLC_RED 

Red

RDLC_GREEN 

Green

RDLC_CYAN 

Cyan

RDLC_MAGENTA 

Magenta

RDLC_YELLOW 

Yellow

RDLC_WHITE 

White

RDLC_TAN 

Tan

RDLC_GREY 

Grey

RDLC_BROWN 

Brown

RDLC_DGREEN 

Dark Green

RDLC_ORANGE 

Orange

RDLC_NAVY 

Navy

RDLC_DCYAN 

Dark Cyan

RDLC_MAROON 

Maroon

RDLC_PURPLE 

Purple

RDLC_OLIVE 

Olive

RDLC_LGREY 

Light Grey

RDLC_DGREY 

Dark Grey

RDLC_GYELLOW 

Greenish Yellow

RDLC_PINK 

Pink

RDLC_LBLUE 

Light Blue

RDLC_BEIGE 

Beige

Member Function Documentation

◆ Color565()

int16_t color16_graphics::Color565 ( int16_t  r,
int16_t  g,
int16_t  b 
)

: Convert: 24-bit color to 565 16-bit color

Parameters
rcolor red
gcolor green
bcolor blue
Returns
16 bit color value
Note
3 byte to 2 byte, Red Green Blue. RRRR RRRR GGGG GGGG BBBB BBBB => 565 color mode => RRRRR GGGGGG BBBBB

◆ drawArc()

void color16_graphics::drawArc ( uint16_t  cx,
uint16_t  cy,
uint16_t  radius,
uint16_t  thickness,
float  startAngle,
float  endAngle,
uint16_t  color 
)

Draw an arc on the TFT display. This function draws an arc between two angles (start and end) on a circle with a given radius.

Parameters
cxX-coordinate of the center of the circle.
cyY-coordinate of the center of the circle.
radiusThe radius of the circle.
thicknessthe thickness of the arc
startAngleThe starting angle of the arc (in degrees).
endAngleThe ending angle of the arc (in degrees).
colorThe color of the arc.

variables _arcAngleMax and _arcAngleOffset which can be set by user with setters to define behaviour of arc. _arcAngleOffset is zero default, means 0 degree is positive X axis , Arc is drawn counterclockwise XXX 270 XXX 180 XXX 000 XXX 090 XXX This function uses a modified midpoint circle algorithm combined with scanline filling to efficiently draw an arc with a specified thickness. It calculates pixel positions using trigonometric boundary checks and slopes for accurate rendering. For more information, see: https://en.wikipedia.org/wiki/Midpoint_circle_algorithm

◆ drawBitmap()

rdlib::Return_Codes_e color16_graphics::drawBitmap ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color,
uint16_t  bgcolor,
const std::span< const uint8_t bitmap 
)

: Draws an bi-color bitmap to screen

Parameters
xX coordinate
yY coordinate
wwidth of the bitmap in pixels
hheight of the bitmap in pixels
colorbitmap foreground colors ,is bi-color
bgcolorbitmap background colors ,is bi-color
bitmapbitmap data, horizontally addressed.
Returns
enum rdlib::Return_Codes_e
  1. rdlib::Success for success
  2. rdlib::BitmapScreenBounds Error
  3. rdlib::BitmapDataEmpty Error
  4. rdlib::BitmapHorizontalSize Error
  5. rdlib::MemoryAError Error

◆ drawBitmap16()

rdlib::Return_Codes_e color16_graphics::drawBitmap16 ( uint16_t  x,
uint16_t  y,
const std::span< const uint8_t bitmap,
uint16_t  w,
uint16_t  h 
)

: Draws an 16 bit color bitmap to screen from a data array

Parameters
xX coordinate
yY coordinate
bitmapdatabuffer containing Bitmap data
wwidth of the bitmap in pixels
hheight of the bitmap in pixels
Returns
enum rdlib::Return_Codes_e
  1. rdlib::Success for success
  2. rdlib::BitmapScreenBounds Error
  3. rdlib::BitmapDataEmpty Error
  4. rdlib::MemoryAError Error

◆ drawBitmap24()

rdlib::Return_Codes_e color16_graphics::drawBitmap24 ( uint16_t  x,
uint16_t  y,
const std::span< const uint8_t bitmap,
uint16_t  w,
uint16_t  h 
)

Draws an 24 bit color bitmap to screen from a data array.

Parameters
xX coordinate
yY coordinate
bitmapA span to the data buffer containing Bitmap data
wwidth of the bitmap in pixels
hheight of the bitmap in pixels
Returns
enum rdlib::Return_Codes_e
  1. rdlib::Success for success
  2. rdlib::BitmapScreenBounds Error
  3. rdlib::BitmapDataEmpty Error
  4. rdlib::MemoryAError Error
Note
24 bit color converted to 16 bit color

◆ drawCircle()

void color16_graphics::drawCircle ( int16_t  x0,
int16_t  y0,
int16_t  r,
uint16_t  color 
)

draws a circle where (x0,y0) are center coordinates an r is circle radius.

Parameters
x0circle center x position
y0circle center y position
rradius of circle
colorThe color of the circle , 565 16 Bit color

◆ drawDotGrid()

rdlib::Return_Codes_e color16_graphics::drawDotGrid ( int16_t  x,
int16_t  y,
int16_t  w,
int16_t  h,
uint8_t  DotGridGap,
uint16_t  color 
)

Draws a grid of dots on the screen starting from the given coordinates. This function draws a grid of pixels with a specified gap between them. It checks that the provided coordinates and dimensions are within the screen bounds and adjusts them if necessary. It also validates The grid of dots gap value and defaults it to 2 if invalid.

Parameters
xThe x-coordinate of the top-left corner where The grid of dots will start.
yThe y-coordinate of the top-left corner where The grid of dots will start.
wThe width of the area to draw The grid of dots, from the starting x-coordinate.
hThe height of the area to draw The grid of dots, from the starting y-coordinate.
DotGridGapThe gap between each dot gap line, controlling the spacing between drawn pixels.
colorThe color of the pixels to draw in The grid of dots.
Returns
rdlib::Return_Codes_e Returns a status code indicating success or failure. Possible return values:

◆ drawEllipse()

void color16_graphics::drawEllipse ( int16_t  cx,
int16_t  cy,
int16_t  semiMajorAxis,
int16_t  semiMinorAxis,
bool  fill,
uint16_t  color 
)

Draw an ellipse on the display. This function uses the midpoint ellipse algorithm to efficiently draw an ellipse centered at (cx, cy) with the given semi-major (horizontal) and semi-minor (vertical) axes.

Parameters
cxX-coordinate of the ellipse center.
cyY-coordinate of the ellipse center.
semiMajorAxisLength of the semi-major axis (horizontal radius).
semiMinorAxisLength of the semi-minor axis (vertical radius).
fillif false draw Ellipse , if true fill it!
color16-bit color value for the ellipse.

◆ drawFastHLine()

rdlib::Return_Codes_e color16_graphics::drawFastHLine ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  color 
)

Draws a horizontal line starting at (x,y) with width w.

Parameters
xThe starting x coordinate
yThe starting y coordinate
wThe width of the line
colorThe color of the line 565 16 Bit color
Returns
enum rdlib::Return_Codes_e
  1. rdlib::Success for success
  2. rdlib::ShapeScreenBounds Error

◆ drawFastVLine()

rdlib::Return_Codes_e color16_graphics::drawFastVLine ( uint16_t  x,
uint16_t  y,
uint16_t  h,
uint16_t  color 
)

Draws a vertical line starting at (x,y) with height h.

Parameters
xThe starting x coordinate
yThe starting y coordinate
hThe height of the line
colorThe color of the line 565 16 Bit color
Returns
enum rdlib::Return_Codes_e
  1. rdlib::Success for success
  2. rdlib::ShapeScreenBounds Error

◆ drawIcon()

rdlib::Return_Codes_e color16_graphics::drawIcon ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  color,
uint16_t  backcolor,
const std::span< const uint8_t character 
)

Draws an custom Icon of X by 8 size to screen , where X = 0 to 127.

Parameters
xX coordinate
yY coordinate
w0-MAX_Y possible values width of icon in pixels , height is fixed at 8 pixels
coloricon foreground colors ,is bi-color
backcoloricon background colors ,is bi-color
charactericon data vertically addressed.
Returns
enum rdlib::Return_Codes_e
  1. rdlib::Success for success
  2. rdlib::BitmapScreenBounds Error
  3. rdlib::BitmapDataEmpty Error

◆ drawLine()

void color16_graphics::drawLine ( int16_t  x0,
int16_t  y0,
int16_t  x1,
int16_t  y1,
uint16_t  color 
)

draws a line from (x0,y0) to (x1,y1).

Parameters
x0x start coordinate
y0y start coordinate
x1x end coordinate
y1y end coordinate
colorcolor to fill rectangle 565 16-bit

◆ drawLineAngle()

void color16_graphics::drawLineAngle ( int16_t  x,
int16_t  y,
int  angle,
uint8_t  start,
uint8_t  length,
int  offset,
uint16_t  color 
)

Draws a line using an angle and length as parameters. This function draws a line starting from (x, y), extending in the direction specified by angle, with a given length. The function also allows applying an offset to the angle before computing the line’s end coordinates.

Parameters
xThe starting x-coordinate (horizontal position).
yThe starting y-coordinate (vertical position).
angleThe angle (in degrees) at which the line is drawn.
startcalculates a new starting position by moving start units along the given angle.
lengthThe length of the line.
offsetAn additional offset applied to the angle before calculating the endpoint.
colorThe color of the line (RGB565 format).

◆ drawPixel()

void color16_graphics::drawPixel ( uint16_t  x,
uint16_t  y,
uint16_t  color 
)

Draw a pixel to screen.

Parameters
xColumn co-ord
yrow co-ord
color565 16-bit

◆ drawPolygon()

rdlib::Return_Codes_e color16_graphics::drawPolygon ( int16_t  x,
int16_t  y,
uint8_t  sides,
int16_t  diameter,
float  rotation,
bool  fill,
uint16_t  color 
)

Draws a polygon with a specified number of sides, diameter, rotation, and color. This function draws a regular polygon by connecting points equally spaced around a circle, with each point having a distance defined by the diameter. The polygon is rotated by the given angle (in degrees) before being drawn. The number of sides is enforced to be at least 3.

Parameters
xThe x-coordinate of the center of the polygon.
yThe y-coordinate of the center of the polygon.
sidesThe number of sides the polygon will have. Must be at least 3.
diameterThe diameter of the circle inscribed by the polygon.
rotationThe angle (in degrees) by which to rotate the polygon.
fillif false draw ,if true fill
colorThe color of the polygon edges.
Returns
error code GenericError , if user inputs incorrect sides value

◆ drawQuadrilateral()

void color16_graphics::drawQuadrilateral ( int16_t  x0,
int16_t  y0,
int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
int16_t  x3,
int16_t  y3,
uint16_t  color 
)

Draws a quadrilateral (four-sided polygon) by connecting four points with lines. This function draws a quadrilateral by drawing four lines between the given vertices. The lines are drawn in the order: (x0, y0) to (x1, y1), (x1, y1) to (x2, y2), (x2, y2) to (x3, y3), and finally (x3, y3) back to (x0, y0).

Parameters
x0The x-coordinate of the first vertex.
y0The y-coordinate of the first vertex.
x1The x-coordinate of the second vertex.
y1The y-coordinate of the second vertex.
x2The x-coordinate of the third vertex.
y2The y-coordinate of the third vertex.
x3The x-coordinate of the fourth vertex.
y3The y-coordinate of the fourth vertex.
colorThe 565 color used to draw the lines of the quadrilateral.

◆ drawRectWH()

void color16_graphics::drawRectWH ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

draws rectangle at (x,y) where h is height and w is width of the rectangle.

Parameters
xx start coordinate
yy start coordinate
wwidth of the rectangle
hheight of the rectangle
colorcolor to fill rectangle 565 16-bit

◆ drawRoundRect()

void color16_graphics::drawRoundRect ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  r,
uint16_t  color 
)

draws a rectangle with rounded edges

Parameters
xx start coordinate
yy start coordinate
wwidth of the rectangle
hheight of the rectangle
rr: radius of the rounded edges
colorcolor to fill rectangle 565 16-bit

◆ drawSimpleArc()

void color16_graphics::drawSimpleArc ( int16_t  cx,
int16_t  cy,
int16_t  radius,
float  startAngle,
float  endAngle,
uint16_t  color 
)

Draw a simple arc of one pixel on the display( no offsets , thickness or maximum arc calculations) This function draws an arc between two angles (start and end) on a circle with a given radius.

Parameters
cxX-coordinate of the center of the circle.
cyY-coordinate of the center of the circle.
radiusThe radius of the circle.
startAngleThe starting angle of the arc (in degrees).
endAngleThe ending angle of the arc (in degrees).
colorThe color of the arc.

0 degree is positive X axis , arc is drawn counterclockwise

◆ drawSprite()

rdlib::Return_Codes_e color16_graphics::drawSprite ( uint16_t  x,
uint16_t  y,
const std::span< const uint8_t sprite,
uint16_t  w,
uint16_t  h,
uint16_t  backgroundColor 
)

: Draws an 16 bit color sprite bitmap to screen with transparent background

Parameters
xX coordinate
yY coordinate
spritespan to sprite data
wwidth of the sprite in pixels
hheight of the sprite in pixels
backgroundColorthe background color of sprite (16 bit 565) this will be made transparent
Note
Does not use buffer, just draw pixel
Returns
  1. Success=success
  2. BitmapDataEmpty=invalid pointer object
  3. BitmapScreenBounds=Co-ordinates out of bounds
  4. BitmapSize=Sprite data out of bounds

◆ drawTriangle()

void color16_graphics::drawTriangle ( int16_t  x0,
int16_t  y0,
int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
uint16_t  color 
)

draws a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).

Parameters
x0x start coordinate point 1
y0y start coordinate point 1
x1x start coordinate point 2
y1y start coordinate point 2
x2x start coordinate point 3
y2y start coordinate point 3
colorcolor to draw triangle 565 16-bit

◆ fillCircle()

void color16_graphics::fillCircle ( int16_t  x0,
int16_t  y0,
int16_t  r,
uint16_t  color 
)

fills a circle where (x0,y0) are center coordinates an r is circle radius.

Parameters
x0circle center x position
y0circle center y position
rradius of circle
colorcolor of the circle , 565 16 Bit color

◆ fillQuadrilateral()

void color16_graphics::fillQuadrilateral ( int16_t  x0,
int16_t  y0,
int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
int16_t  x3,
int16_t  y3,
uint16_t  color,
bool  useTriangleSplit = true 
)

Fills a quadrilateral with the specified color using triangles. This function fills a quadrilateral by dividing it into triangles and filling them individually. The quadrilateral is filled by calling the fillTriangle function three times with appropriate vertex coordinates. The useTriangleSplit parameter determines whether the quadrilateral is divided into two triangles or if only one triangle is used.

Parameters
x0The x-coordinate of the first vertex.
y0The y-coordinate of the first vertex.
x1The x-coordinate of the second vertex.
y1The y-coordinate of the second vertex.
x2The x-coordinate of the third vertex.
y2The y-coordinate of the third vertex.
x3The x-coordinate of the fourth vertex.
y3The y-coordinate of the fourth vertex.
colorThe color used to fill the quadrilateral.
useTriangleSplitA boolean flag that determines whether the quadrilateral should be divided into two or three triangles.

◆ fillRect()

void color16_graphics::fillRect ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

fills a rectangle at (x,y) where h is height and w is width of the rectangle.

Parameters
xx start coordinate
yy start coordinate
wwidth of the rectangle
hheight of the rectangle
colorcolor to fill rectangle 565 16-bit

◆ fillRectangle()

rdlib::Return_Codes_e color16_graphics::fillRectangle ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

fills a rectangle starting from coordinates (x,y) with width of w and height of h.

Parameters
xx coordinate
yy coordinate
wwidth of the rectangle
hheight of the rectangle
colorcolor to fill rectangle 565 16-bit
Note
uses spiWriteDataBuffer method
Returns
enum rdlib::Return_Codes_e
  1. rdlib::Success for success
  2. rdlib::ShapeScreenBounds Error
  3. rdlib::MemoryAError Error

◆ fillRoundRect()

void color16_graphics::fillRoundRect ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  r,
uint16_t  color 
)

Fills a rectangle with rounded edges.

Parameters
xx start coordinate
yy start coordinate
wwidth of the rectangle
hheight of the rectangle
rr: radius of the rounded edges
colorcolor to fill rectangle 565 16-bit

◆ fillScreen()

void color16_graphics::fillScreen ( uint16_t  color)

Fills the whole screen with a given color.

Parameters
color565 16-bit

◆ fillTriangle()

void color16_graphics::fillTriangle ( int16_t  x0,
int16_t  y0,
int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
uint16_t  color 
)

Fills a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).

Parameters
x0x start coordinate point 1
y0y start coordinate point 1
x1x start coordinate point 2
y1y start coordinate point 2
x2x start coordinate point 3
y2y start coordinate point 3
colorcolor to fill , 565 16-bit

◆ getArcAngleMax()

float color16_graphics::getArcAngleMax ( ) const

Get the current maximum angle of the arc.

Returns
The current maximum angle in degrees.

◆ getArcAngleOffset()

int color16_graphics::getArcAngleOffset ( ) const

Get the current angle offset.

Returns
The current angle offset in degrees.

◆ getDisplaySPIBlockSize()

int color16_graphics::getDisplaySPIBlockSize ( ) const

Gets the maximum SPI transaction block size.

Returns
The current block size of the SPI transaction.

◆ pushColor()

void color16_graphics::pushColor ( uint16_t  color)
protected

pushColor

Parameters
color

◆ setAddrWindow()

virtual void color16_graphics::setAddrWindow ( uint16_t  ,
uint16_t  ,
uint16_t  ,
uint16_t   
)
pure virtual

define in the sub class

Implemented in ILI9341_TFT, SSD1331_OLED, ST7735_TFT, and ST7789_TFT.

◆ setArcAngleMax()

void color16_graphics::setArcAngleMax ( float  arcAngleMax)

Set a new maximum angle for the arc.

Parameters
arcAngleMaxThe new maximum angle in degrees (should be positive).

◆ setArcAngleOffset()

void color16_graphics::setArcAngleOffset ( int  arcAngleOffset)

Set a new angle offset.

Parameters
arcAngleOffsetThe new angle offset in degrees.

◆ setCursor()

void color16_graphics::setCursor ( int16_t  x,
int16_t  y 
)

Set the Cursor Position on screen.

Parameters
xthe x co-ord of the cursor position
ythe y co-ord of the cursor position

◆ setDisplaySPIBlockSize()

void color16_graphics::setDisplaySPIBlockSize ( int  size)

Sets the maximum SPI transaction block size.

Parameters
sizeThe new block size to set.
Note
Maximum block size supported by lg library is 65536 see LG_MAX_SPI_DEVICE_COUNT in lg library. Also your Computer may have limit on spi transaction size

◆ setTextColor() [1/2]

void color16_graphics::setTextColor ( uint16_t  c)

Set text color foreground.

Parameters
ctext foreground color , Color definitions 16-Bit Color Values R5G6B5

◆ setTextColor() [2/2]

void color16_graphics::setTextColor ( uint16_t  c,
uint16_t  b 
)

Set text color foreground and background.

Parameters
ctext foreground color , Color definitions 16-Bit Color Values R5G6B5
btext background color , Color definitions 16-Bit Color Values R5G6B5

◆ setTextWrap()

void color16_graphics::setTextWrap ( bool  w)

turn on or off screen wrap of the text (fonts 1-6)

Parameters
wTRUE on

◆ spiWrite()

void color16_graphics::spiWrite ( uint8_t  spidata)
protected

Write byte to SPI.

Parameters
spidatabyte to write
Note
uses _HIGHFREQ_DELAY to slowdown software SPI if CPU frequency too fast

◆ spiWriteDataBuffer()

void color16_graphics::spiWriteDataBuffer ( uint8_t spidata,
int  len 
)
protected

Write a buffer to SPI, both Software and hardware SPI supported.

Parameters
spidatato send
lenlength of buffer
Note
The maximum size of an SPI transaction by default in lgpio library is 65536 or _Display_SPI_BLK_SIZE. SO a buffer larger than this must be sent in blocks of 65536 bytes. The largest current expected size is for a full screen write to a 240x320 display currently which is 240x320x2 = 153600 bytes. spidev.bufsiz must also be set to 65536 or higher see Readme for display for more details.

◆ write()

size_t color16_graphics::write ( uint8_t  character)
overridevirtual

write method used in the print class when user calls print

Parameters
characterthe character to print
Returns
Will return
  1. 1. success
  2. rdlib::Return_Codes_e enum error code, An error in the writeChar method.upstream

Implements Print.

◆ writeChar()

rdlib::Return_Codes_e color16_graphics::writeChar ( int16_t  x,
int16_t  y,
char  value 
)

Write 1 character on Display.

Parameters
xcharacter starting position on x-axis. Valid values
ycharacter starting position on x-axis. Valid values
valueCharacter to be written.
Note
uses spiWriteDataBuffer method to write each character as a buffer for speed. Much faster than pixel by pixel spi byte writes
Returns
Will return rdlib::Return_Codes_e enum
  1. rdlib::Success success
  2. rdlib::CharScreenBounds co-ords out of bounds check x and y
  3. rdlib::CharFontASCIIRange Character out of ASCII Font bounds, check Font range
  4. rdlib::MemoryAError Could not assign memory for character buffer

◆ writeCharString()

rdlib::Return_Codes_e color16_graphics::writeCharString ( int16_t  x,
int16_t  y,
char pText 
)

Write Text character array on display.

Parameters
xcharacter starting position on x-axis.
ycharacter starting position on y-axis.
pTextPointer to the array of the text to be written.
Returns
Will return
  1. rdlib::Success Success
  2. rdlib::CharArrayNullptr String pText Array invalid pointer object
  3. Failure code from writeChar method upstream

◆ writeCommand()

void color16_graphics::writeCommand ( uint8_t  spicmdbyte)
protected

: Write an SPI command to

Parameters
spicmdbytecommand byte to send

◆ writeData()

void color16_graphics::writeData ( uint8_t  spidatabyte)
protected

Write an SPI data byte to device.

Parameters
spidatabytebyte to send

Member Data Documentation

◆ _arcAngleMax

float color16_graphics::_arcAngleMax = 360.0f
protected

Maximum angle of Arc , used by drawArc

◆ _arcAngleOffset

int color16_graphics::_arcAngleOffset = 0
protected

used by drawArc, offset for adjusting the starting angle of arc. default positive X-axis (0°)

◆ _cursorX

int16_t color16_graphics::_cursorX = 0
protected

Current X co-ord cursor position

◆ _cursorY

int16_t color16_graphics::_cursorY = 0
protected

Current Y co-ord cursor position

◆ _DeviceNumGpioChip

int color16_graphics::_DeviceNumGpioChip = 0
protected

The device number of a gpiochip ls /dev/gpio

◆ _Display_CS

int8_t color16_graphics::_Display_CS
protected

GPIO for chip select line, Software SPI only

◆ _Display_DC

int8_t color16_graphics::_Display_DC
protected

GPIO for data or command line

◆ _Display_MISO

int8_t color16_graphics::_Display_MISO
protected

GPIO for MISO line, Software SPI only

◆ _Display_RST

int8_t color16_graphics::_Display_RST
protected

GPIO for reset line

◆ _Display_SCLK

int8_t color16_graphics::_Display_SCLK
protected

GPIO for Clock line, Software SPI only

◆ _Display_SDATA

int8_t color16_graphics::_Display_SDATA
protected

GPIO for MOSI line, Software SPI only

◆ _Display_SPI_BLK_SIZE

int color16_graphics::_Display_SPI_BLK_SIZE = 65536
private

max block size SPI Transaction, lgpio lib default(LG_MAX_SPI_DEVICE_COUNT)

◆ _GpioHandle

int color16_graphics::_GpioHandle = 0
protected

This holds a handle to a gpiochip device opened by lgGpiochipOpen

◆ _hardwareSPI

bool color16_graphics::_hardwareSPI =true
protected

True for Hardware SPI on , false fpr Software SPI on

◆ _height

uint16_t color16_graphics::_height
protected

Display h as modified by current rotation

◆ _HighFreqDelay

uint16_t color16_graphics::_HighFreqDelay = 0
protected

uS GPIO Communications delay, SW SPI ONLY

◆ _spiHandle

int color16_graphics::_spiHandle = 0
protected

Hold a handle for the SPI device on the channel.

◆ _textbgcolor

uint16_t color16_graphics::_textbgcolor = 0x0000
protected

16 bit BackGround color for text

◆ _textcolor

uint16_t color16_graphics::_textcolor = 0xFFFF
protected

16 bit ForeGround color for text

◆ _textwrap

bool color16_graphics::_textwrap = true
protected

wrap text around the screen on overflow

◆ _width

uint16_t color16_graphics::_width
protected

Display w as modified by current rotation

◆ _XStart

uint8_t color16_graphics::_XStart = 0
protected

Used to store _colstart changed by current rotation

◆ _YStart

uint8_t color16_graphics::_YStart = 0
protected

Used to store _rowstart changed by current rotation


The documentation for this class was generated from the following files: