public class U8g2Graphics extends Object
This is a wrapper class for the U8G2 native graphics interface. It is not advisable to use this class directly unless you know what you are doing. Use the facilities provided in the glcd drivers module.
Modifier and Type | Field and Description |
---|---|
static int |
BUS_HARDWARE
Bus interface using the device hardware specific features for data transport
|
static int |
BUS_SOFTWARE
Bus interface using software bit-banging procedures for data transport
|
static int |
COM_3WSPI
3-Wire SPI protocol
|
static int |
COM_4WSPI
4-Wire SPI protocol
|
static int |
COM_6800
Parallel 8-bit 6800 protocol
|
static int |
COM_8080
Parallel 8-bit 8080 protocol
|
static int |
COM_I2C
I2C Protocol
|
static int |
COM_KS0108
Parallel 6800 protocol for KS0108 (Contains more chip select lines)
|
static int |
COM_SED1520
Special protocol for SED1520
|
static int |
COM_ST7920SPI
4-Wire SPI protocol but does not use DC pin (Used by ST7920 controller)
|
static int |
COM_UART
Serial/UART protocol
|
static int |
ROTATION_MIRROR
No rotation, landscape, display content is mirrored
|
static int |
ROTATION_R0
No rotation
|
static int |
ROTATION_R1
90 degree clockwise rotation
|
static int |
ROTATION_R2
180 degree clockwise rotation
|
static int |
ROTATION_R3
270 degree clockwise rotation
|
static int |
U8G2_DRAW_ALL
Draw the whole shape
|
static int |
U8G2_DRAW_LOWER_LEFT
Draw the lower left portion of the shape
|
static int |
U8G2_DRAW_LOWER_RIGHT
Draw the lower right portion of the shape
|
static int |
U8G2_DRAW_UPPER_LEFT
Draw the upper left portion of the shape
|
static int |
U8G2_DRAW_UPPER_RIGHT
Draw the upper right portion of the shape
|
Constructor and Description |
---|
U8g2Graphics() |
Modifier and Type | Method and Description |
---|---|
static void |
begin(long id)
Simplified setup procedure of the display for the Arduino enviornment.
|
static void |
clear(long id)
Clears all pixel on the display and the buffer.
|
static void |
clearBuffer(long id)
Clears all pixel in the memory frame buffer.
|
static void |
clearDisplay(long id)
Clears all pixel in the internal buffer AND on the connected display.
|
static void |
drawBitmap(long id,
int x,
int y,
int count,
int height,
byte[] bitmap)
Deprecated.
Please use
drawXBM(long, int, int, int, int, byte[]) instead |
static void |
drawBox(long id,
int x,
int y,
int width,
int height)
Draw a box (filled frame), starting at x/y position (upper left edge).
|
static void |
drawCircle(long id,
int x,
int y,
int radius,
int options)
Draw a circle with radus rad at position (x0, y0).
|
static void |
drawDisc(long id,
int x,
int y,
int radius,
int options)
Draw a filled circle with radus rad at position (x0, y0).
|
static void |
drawEllipse(long id,
int x,
int y,
int rx,
int ry,
int options)
Draw ellipse with radus rx and 'ry' at position (x0, y0).
|
static void |
drawFilledEllipse(long id,
int x,
int y,
int rx,
int ry,
int options)
Draw a filled ellipse with radus rx and 'ry' at position (x0, y0).
|
static void |
drawFrame(long id,
int x,
int y,
int width,
int height)
Draw a frame (empty box), starting at x/y position (upper left edge).
|
static void |
drawGlyph(long id,
int x,
int y,
short encoding)
Draw a single character.
|
static void |
drawHLine(long id,
int x,
int y,
int width)
Draw a horizontal line, starting at x/y position (left edge).
|
static void |
drawLine(long id,
int x,
int y,
int x1,
int y1)
Draw a line between two points.
|
static void |
drawPixel(long id,
int x,
int y)
Draw a pixel at the specified x/y position.
|
static void |
drawRoundedBox(long id,
int x,
int y,
int width,
int height,
int radius)
Draw a box with round edges, starting at x/y position (upper left edge).
|
static void |
drawRoundedFrame(long id,
int x,
int y,
int width,
int height,
int radius)
Draw a frame with round edges, starting at x/y position (upper left edge).
|
static void |
drawString(long id,
int x,
int y,
String value)
Draw a string.
|
static void |
drawTriangle(long id,
int x0,
int y0,
int x1,
int y1,
int x2,
int y2)
Draw a triangle (filled polygon).
|
static int |
drawUTF8(long id,
int x,
int y,
String value)
Draw a string which is encoded as UTF-8.
|
static void |
drawVLine(long id,
int x,
int y,
int length)
Draw a vertical line, starting at x/y position (upper end).
|
static void |
drawXBM(long id,
int x,
int y,
int width,
int height,
byte[] data)
Draw a XBM Bitmap.
|
static void |
firstPage(long id)
This command is part of the (picture) loop which renders the content of the display.
|
static int |
getAscent(long id)
Returns the reference height of the glyphs above the baseline (ascent).
|
static int |
getBuffer(long id)
Return the address of the start of the buffer.
|
static int |
getBufferCurrTileRow(long id)
Return the intended position for the content of the pixel buffer (page) on the target display.
|
static int |
getBufferTileHeight(long id)
Return the height of the page buffer in tiles.
|
static int |
getBufferTileWidth(long id)
Return the width of the page buffer in tiles (One tile has a width of 8 pixel).
|
static int |
getDescent(long id)
Returns the reference height of the glyphs below the baseline (descent).
|
static int |
getHeight(long id)
Get the current height of the display instance
|
static int |
getMaxCharHeight(long id)
Each glyph is stored as a bitmap.
|
static int |
getMaxCharWidth(long id)
Each glyph is stored as a bitmap.
|
static int |
getStrWidth(long id,
String text)
Return the pixel width of string.
|
static int |
getUTF8Width(long id,
String text)
Return the pixel width of an UTF-8 encoded string.
|
static int |
getWidth(long id)
Get the current width of the display instance
|
static void |
initDisplay(long id)
Reset and configure the display.
|
static int |
nextPage(long id)
This command is part of the (picture) loop which renders the content of the display.
|
static void |
sendBuffer(long id)
Send the content of the memory frame buffer to the display.
|
static int |
setAutoPageClear(long id,
int mode)
Enables (mode=1) or disables (mode=0) automatic clearing of the pixel buffer by the
firstPage(long)
and nextPage(long) procedures. |
static void |
setBitmapMode(long id,
int mode)
Defines, whether the bitmap functions will write the background color (mode 0/solid, mode = 0) or
not (mode 1/transparent, mode = 1).
|
static void |
setBufferCurrTileRow(long id,
int row)
Set the position of the pixel buffer for the sendBuffer command.
|
static void |
setContrast(long id,
int value)
Set the contrast or brightness for the display (if supported).
|
static void |
setDisplayRotation(long id,
int rotation)
Changes the display rotation.
|
static void |
setDrawColor(long id,
int color)
Defines the bit value (color index) for all drawing functions.
|
static void |
setFlipMode(long id,
boolean enable)
Some displays support a 180 degree rotation of the internal frame buffer.
|
static void |
setFont(long id,
byte[] data)
Define a u8g2 font for the glyph and string drawing functions.
|
static void |
setFont(long id,
String fontKey)
Define a u8g2 font for the glyph and string drawing functions.
|
static void |
setFontDirection(long id,
int direction)
The arguments defines the drawing direction of all strings or glyphs.
|
static void |
setFontMode(long id,
int mode)
Defines, whether the glyph and string drawing functions will write the background color (mode 0/solid,
mode = 0) or not (mode 1/transparent, mode = 1).
|
static void |
setFontPosBaseline(long id)
Change the reference position for the glyph and string draw functions.
|
static void |
setFontPosBottom(long id)
Change the reference position for the glyph and string draw functions.
|
static void |
setFontPosCenter(long id)
Change the reference position for the glyph and string draw functions.
|
static void |
setFontPosTop(long id)
Change the reference position for the glyph and string draw functions.
|
static void |
setFontRefHeightAll(long id)
A call to this procedure will define the calculation method for the ascent and descent of the current
font.
|
static void |
setFontRefHeightExtendedText(long id)
A call to this procedure will define the calculation method for the ascent and descent of the current
font.
|
static void |
setFontRefHeightText(long id)
A call to this procedure will define the calculation method for the ascent and descent of the current
font.
|
static void |
setPowerSave(long id,
boolean enable)
Activates (enable = true) or disables (enable = false) the power save mode of the display.
|
static long |
setup(String setupProc,
int busInterface,
int busInterfaceType,
int rotation,
int address,
byte[] pinConfig,
boolean virtual)
Setup U8G2.
|
public static final int ROTATION_R0
public static final int ROTATION_R1
public static final int ROTATION_R2
public static final int ROTATION_R3
public static final int ROTATION_MIRROR
public static final int BUS_HARDWARE
public static final int BUS_SOFTWARE
public static final int COM_4WSPI
public static final int COM_3WSPI
public static final int COM_6800
public static final int COM_8080
public static final int COM_I2C
public static final int COM_ST7920SPI
public static final int COM_UART
public static final int COM_KS0108
public static final int COM_SED1520
public static final int U8G2_DRAW_UPPER_RIGHT
public static final int U8G2_DRAW_UPPER_LEFT
public static final int U8G2_DRAW_LOWER_LEFT
public static final int U8G2_DRAW_LOWER_RIGHT
public static final int U8G2_DRAW_ALL
public static long setup(String setupProc, int busInterface, int busInterfaceType, int rotation, int address, byte[] pinConfig, boolean virtual)
setupProc
- The setup procedure name. This is equivalent to the u8g2 setup function in c/c++busInterface
- The bus communications interface (e.g. COM_4WSPI
)busInterfaceType
- The bus interface type (HARDWARE = 0, SOFTWARE = 1)rotation
- The display rotation.address
- The device address. This is most commonly used by I2C. Set this to -1 if not applicable to the current
setup.pinConfig
- Array of integers which represents the pin mapping configuration of the displayvirtual
- Set to true
to enable virtual-mode. All display instructions will be re-routed to the U8g2EventDispatcher
public static void drawBox(long id, int x, int y, int width, int height)
Draw a box (filled frame), starting at x/y position (upper left edge). The box has width w and height h. Parts of the box can be outside of the display boundaries. This procedure will use the current color (setDrawColor) to draw the box. For a monochrome display, the color index 0 will clear a pixel and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position of upper left edge.y
- Y-position of upper left edge.width
- Width of the box.height
- Height of the box.@Deprecated public static void drawBitmap(long id, int x, int y, int count, int height, byte[] bitmap)
drawXBM(long, int, int, int, int, byte[])
insteadDraw a bitmap at the specified x/y position (upper left corner of the bitmap). Parts of the bitmap may be outside the display boundaries.The bitmap is specified by the array bitmap. A cleared bit means: Do not draw a pixel. A set bit inside the array means: Write pixel with the current color index.For a monochrome display, the color index 0 will clear a pixel (in solid mode) and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position (left position of the bitmap).y
- Y-position (upper position of the bitmap).count
- Number of bytes of the bitmap in horizontal direction. The width of the bitmap is count * 8height
- Height of the bitmap.bitmap
- Bitmap datapublic static void drawCircle(long id, int x, int y, int radius, int options)
Draw a circle with radus rad at position (x0, y0). The diameter of the circle is 2*rad+1. Depending on opt, it is possible to draw only some sections of the circle.
Possible values for opt are:
These values can be combined with the | operator. This procedure will use the current color (setDrawColor) for drawing.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Position of the center of the circle.y
- Y-Position of the center of the circle.radius
- Defines the size of the circle: Radus = radoptions
- Selects some or all sections of the circle.public static void drawDisc(long id, int x, int y, int radius, int options)
Draw a filled circle with radus rad at position (x0, y0). The diameter of the circle is 2*rad+1. Depending on opt, it is possible to draw only some sections of the disc.
Possible values for options are:
These values can be combined with the | operator. This procedure will use the current color (setDrawColor(long, int)
) for drawing.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Position of the center of the disc.y
- Y-Position of the center of the disc.radius
- Defines the size of the circle: Radus = rad.options
- Selects some or all sections of the disc.public static void drawEllipse(long id, int x, int y, int rx, int ry, int options)
Draw ellipse with radus rx and 'ry' at position (x0, y0). rx*ry must be lower than 512 in 8 Bit mode of u8g2.
Possible values for options are:
The diameter is twice the radius plus one.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Position of the center of the filled circle.y
- Y-Position of the center of the filled circle.rx
- Defines the size of the ellipse.ry
- Defines the size of the ellipse.options
- Selects some or all sections of the ellipse.public static void drawFilledEllipse(long id, int x, int y, int rx, int ry, int options)
Draw a filled ellipse with radus rx and 'ry' at position (x0, y0). rx*ry must be lower than 512 in 8 Bit mode of u8g2.Depending on opt, it is possible to draw only some sections of the disc.
Possible values for options are:
These values can be combined with the | operator.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Position of the center of the filled circle.y
- Y-Position of the center of the filled circle.rx
- X-the size of the ellipse.ry
- Y- the size of the ellipse.options
- Selects some or all sections of the ellipse.public static void drawFrame(long id, int x, int y, int width, int height)
Draw a frame (empty box), starting at x/y position (upper left edge). The box has width w and height h. Parts of the frame can be outside of the display boundaries. This procedure will use the current color (setDrawColor) to draw the box. For a monochrome display, the color index 0 will clear a pixel and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position of upper left edge.y
- Y-position of upper left edge.width
- Width of the frame.height
- Height of the frame.public static void drawGlyph(long id, int x, int y, short encoding)
Draw a single character. The character is placed at the specified pixel posion x and y. U8g2 supports the lower 16 bit of the unicode character range (plane 0/Basic Multilingual Plane): The encoding can be any value from 0 to 65535. The glyph can be drawn only, if the encoding exists in the active font.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Position of the character on the display.y
- Y-Position of the character on the display.encoding
- Unicode value of the character.setFont(long, byte[])
public static void drawHLine(long id, int x, int y, int width)
Draw a horizontal line, starting at x/y position (left edge). The width (length) of the line is w pixel. Parts of the line can be outside of the display boundaries. This procedure uses the current color index to draw the line. Color index 0 will clear a pixel and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Positiony
- Y-Positionwidth
- Length of the horizontal linepublic static void drawVLine(long id, int x, int y, int length)
Draw a vertical line, starting at x/y position (upper end). The height (length) of the line is h pixel. Parts of the line can be outside of the display boundaries. This procedure uses the current color index to draw the line. Color index 0 will clear a pixel and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position.y
- Y-position.length
- Length of the vertical line.public static void drawLine(long id, int x, int y, int x1, int y1)
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position of the first point.y
- Y-position of the first point.x1
- X-position of the second point.y1
- Y-position of the second point.public static void drawPixel(long id, int x, int y)
Draw a pixel at the specified x/y position. Position (0,0) is at the upper left corner of the display. The position may be outside the display boundaries.This procedure uses the current color index to draw the pixel. The color index 0 will clear a pixel and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position.y
- Y-position.public static void drawRoundedBox(long id, int x, int y, int width, int height, int radius)
Draw a box with round edges, starting at x/y position (upper left edge). The box/frame has width w and height h. Parts of the box can be outside of the display boundaries. Edges have radius r. It is required that w >= 2*(r+1) and h >= 2*(r+1). This condition is not checked. Behavior is undefined if w or h is smaller than 2*(r+1). This procedure uses the current color index to draw the box. For a monochrome display, the color index 0 will clear a pixel and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position of upper left edge.y
- Y-position of upper left edge.width
- Width of the box.height
- Height of the box.radius
- Radius for the four edges.public static void drawRoundedFrame(long id, int x, int y, int width, int height, int radius)
Draw a frame with round edges, starting at x/y position (upper left edge). The box/frame has width w and height h. Parts of the box can be outside of the display boundaries. Edges have radius r. It is required that w >= 2*(r+1) and h >= 2*(r+1). This condition is not checked. Behavior is undefined if w or h is smaller than 2*(r+1). This procedure uses the current color index to draw the box. For a monochrome display, the color index 0 will clear a pixel and the color index 1 will set a pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position of upper left edge.y
- Y-position of upper left edge.width
- Width of the box.height
- Height of the box.radius
- Radius for the four edges.public static void drawString(long id, int x, int y, String value)
Draw a string. The first character is placed at position x andy. Use setFont to assign a font before drawing a string on the display. To draw a character with encoding 127 to 255, use the C/C++/Arduino escape sequence "\xab" (hex value ab) or "\xyz" (octal value xyz). This function can not draw any glyph with encoding greater or equal to 256. Use drawUTF8 or drawGlyph to access glyphs with encoding greater or equal to 256.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Position of the first character on the display.y
- Y-Position of the first character on the display.value
- The text to draw on the displaypublic static void drawTriangle(long id, int x0, int y0, int x1, int y1, int x2, int y2)
Draw a triangle (filled polygon). Arguments are 16 bit and the polygon is clipped to the size of the display. Multiple polygons are drawn so that they exactly match without overlap:The left side of a polygon is drawn, the right side is not draw. The upper side is only draw if it is flat.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x0
- X-position point 0.y0
- Y-position point 0.x1
- X-position point 1.y1
- Y-position point 1.x2
- X-position point 2.y2
- Y-position point 2.public static void drawXBM(long id, int x, int y, int width, int height, byte[] data)
Draw a XBM Bitmap. Position (x,y) is the upper left corner of the bitmap. XBM contains monochrome, 1-bit bitmaps.
The current color index is used for drawing (see setColorIndex) pixel values 1. Version
2.15.x of U8g2 introduces a solid and a transparent mode for bitmaps. By default, drawXBM will draw solid
bitmaps. This differs from the previous versions: Use setBitmapMode(1) to switch to the previous behavior. The
XBMP version of this procedure expects the bitmap to be in PROGMEM area (AVR only). Many tools (including GIMP)
can save a bitmap as XBM. A nice step by step instruction is here
(external link). The result will look like this:
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-position.y
- Y-position.width
- Width of the bitmap.height
- Height of the bitmap.data
- Bitmap datasetBitmapMode(long, int)
public static int drawUTF8(long id, int x, int y, String value)
Draw a string which is encoded as UTF-8. There are two preconditions for the use of this function: (A) the C/C++/Arduino compiler must support UTF-8 encoding (this is default for the gnu compiler, which is also used for most Arduino boards) and (B) the code editor/IDE must support and store the C/C++/Arduino code as UTF-8 (true for the Arduino IDE). If these conditions are met, you can use the character with code value greater than 127 directly in the string (of course the character must exist in the font file, see also setFont). Advantage: No escape codes are required and the source code is more readable. The glyph can be copied and paste into the editor from a "char set" tool. Disadvantage: The code is less portable and the strlen function will not return the number of visible characters.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
x
- X-Position of the first character on the display.y
- Y-Position of the first character on the display.value
- UTF-8 encoded textgetUTF8Width(long, String)
,
setFont(long, byte[])
,
drawString(long, int, int, String)
public static int getUTF8Width(long id, String text)
Return the pixel width of an UTF-8 encoded string.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
text
- UTF-8 encoded text.public static void setFont(long id, byte[] data)
Define a u8g2 font for the glyph and string drawing functions. Note: u8x8 font can NOT be used. Available fonts are listed here here. The last two characters of the font name define the type and character set for the font:
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
data
- Font datapublic static void setFont(long id, String fontKey)
Define a u8g2 font for the glyph and string drawing functions. Note: u8x8 font can NOT be used. Available fonts are listed here here. The last two characters of the font name define the type and character set for the font:
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
fontKey
- A key string representing the Fontpublic static void setFontMode(long id, int mode)
Defines, whether the glyph and string drawing functions will write the background color (mode 0/solid, mode = 0) or not (mode 1/transparent, mode = 1). Default mode is 1 (background color of the characters is not changed).
Note: Always choose a suitable font, depending on the font mode:
Font Name | Font Type | Suitable for... |
---|---|---|
FONT_xxx_TX | Transparent gylphs with variable width |
mode = 1 , XOR Mode |
FONT_xxx_MX | Monospace/fixed width glyphs | mode = 0 |
FONT_xxx_HX | Glyphs with variable width and common height | mode = 0 |
FONT_xxx_8X | Monospace/fixed width glyphs in a 8x8 box | mode = 0 |
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
mode
- Enable (1) or disable (0) transparent mode.setDrawColor(long, int)
,
setFont(long, byte[])
public static void setFontDirection(long id, int direction)
The arguments defines the drawing direction of all strings or glyphs.
Argument | String Rotation | Description |
---|---|---|
0 | 0 degree | Left to right |
1 | 90 degree | Top to down |
2 | 180 degree | Right to left |
3 | 270 degree | Down to top |
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
direction
- Writing direction/string rotation.drawString(long, int, int, String)
public static void setFontPosBaseline(long id)
Change the reference position for the glyph and string draw functions. By default the reference position is "Baseline".
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
public static void setFontPosBottom(long id)
Change the reference position for the glyph and string draw functions. By default the reference position is "Baseline".
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
public static void setFontPosTop(long id)
Change the reference position for the glyph and string draw functions. By default the reference position is "Baseline".
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
public static void setFontPosCenter(long id)
Change the reference position for the glyph and string draw functions. By default the reference position is "Baseline".
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
public static void setFontRefHeightAll(long id)
A call to this procedure will define the calculation method for the ascent and descent of the current
font. This method will be used for the current and all other fonts, which will be set with setFont(long,
byte[])
. Changing this calculation method has an effect on getAscent(long)
and getDescent(long)
. Default is setFontRefHeightText(long)
.
Ascent will be the highest ascent of all glyphs of the current font. Descent will be the highest descent of all glyphs of the current font.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getAscent(long)
,
getDescent(long)
public static void setFontRefHeightExtendedText(long id)
A call to this procedure will define the calculation method for the ascent and descent of the current
font. This method will be used for the current and all other fonts, which will be set with setFont(long,
byte[])
. Changing this calculation method has an effect on getAscent(long)
and getDescent(long)
.
Ascent will be the largest ascent of "A", "1" or "(" of the current font. Descent will be the descent of "g" or "(" of the current font.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getAscent(long)
,
getDescent(long)
public static void setFontRefHeightText(long id)
A call to this procedure will define the calculation method for the ascent and descent of the current
font. This method will be used for the current and all other fonts, which will be set with setFont(long,
byte[])
. Changing this calculation method has an effect on getAscent(long)
and getDescent(long)
.
Ascent will be the ascent of "A" or "1" of the current font. Descent will be the descent "g" of the current font (this is the default after startup).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getAscent(long)
,
getDescent(long)
public static void setFlipMode(long id, boolean enable)
Some displays support a 180 degree rotation of the internal frame buffer. This hardware feature can be controlled with this procedure. Important: Redraw the complete display after changing the flip mode. Best is to clear the display first, then change the flip mode and finally redraw the content. Results will be undefined for any existing content on the screen.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
enable
- Enable (true) or disable (false) 180 degree rotation of the display contentpublic static void setPowerSave(long id, boolean enable)
Activates (enable = true) or disables (enable = false) the power save mode of the display. With activated power save mode, nothing will be visible on the display. The content of the RAM of the display is not changed. This procedure is also called from begin.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
enable
- Enable (true) or disable (false) power save mode for the display.begin(long)
public static void setDrawColor(long id, int color)
Defines the bit value (color index) for all drawing functions. All drawing function will change the display
memory to this bit value. Default value is 1. For example the drawBox(long, int, int, int, int)
procedure will set all pixels for the defined area to the bit value, provided here. In v2.11 the new color value
2 will activate the XOR mode. Exceptions:
Both functions will always set the buffer to the pixel value 0. The color argument of setDrawColor is ignored.
Note: Not all graphics procedures will support XOR mode. Especially XOR mode is not supported by
drawCircle, drawDisc, drawEllipse and drawFilledEllipse.
Exceptions:
clear(long)
, clearBuffer(long)
: Both functions will always set the buffer to the pixel
value 0. The color argument of setDrawColor is ignored.Font Mode | Draw Color | Glyph Foreground Color | Glyph Background Color |
---|---|---|---|
0: solid | 0 | 0 | 1 |
0: solid | 1 | 1 | 0 |
0: solid | 2 | XOR | 0 |
1: transparent | 0 | 0 | - |
1: transparent | 1 | 1 | - |
1: transparent | 2 | XOR | - |
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
color
- 0 (clear pixel value in the display RAM), 1 (set pixel value) or 2 (XOR mode)drawBox(long, int, int, int, int)
,
drawGlyph(long, int, int, short)
,
setFontMode(long, int)
public static void initDisplay(long id)
Reset and configure the display. This procedure must be called before any other procedures draw something on the display. This procedure leaves the display in a power save mode. In order to see something on the screen, disable power save mode first (setPowerSave). This procedure is called by the begin procedure. Either begin or initDisplay must be called initially.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
public static void firstPage(long id)
This command is part of the (picture) loop which renders the content of the display. This command must be used together with nextPage. There are some restrictions: Do not change the content when executing this loop. Always redraw everything. It is not possible to redraw only parts of the content. The advantage is lesser RAM consumption compared to a full frame buffer in RAM, see sendBuffer.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
nextPage(long)
public static int nextPage(long id)
This command is part of the (picture) loop which renders the content of the display. This command must be used together with firstPage. There are some restrictions: Do not change the content when executing this loop. Always redraw everything. It is not possible to redraw only parts oft the content. The advantage is lesser RAM consumption compared to a full frame buffer in RAM, see sendBuffer. This procedure will send a refresh message (refreshDisplay) to an e-Paper/e-Ink device after completion of the loop (just before returning 0).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
firstPage(long)
public static int getAscent(long id)
Returns the reference height of the glyphs above the baseline (ascent). This value depends on the current
reference height (see setFontRefHeightAll(long)
).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
setFont(long, byte[])
,
getDescent(long)
,
setFontRefHeightAll(long)
public static int getDescent(long id)
Returns the reference height of the glyphs below the baseline (descent). For most fonts, this value will be
negative. This value depends on the current reference height (see setFontRefHeightAll(long)
).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
setFont(long, byte[])
,
getDescent(long)
,
setFontRefHeightAll(long)
public static int getMaxCharWidth(long id)
Each glyph is stored as a bitmap. This returns the width of the largest bitmap in the font.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getMaxCharHeight(long)
public static int getMaxCharHeight(long id)
Each glyph is stored as a bitmap. This returns the height of the largest bitmap in the font.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getMaxCharWidth(long)
public static void sendBuffer(long id)
Send the content of the memory frame buffer to the display. Use clearBuffer(long)
to clear the
buffer and the draw functions to draw something into the frame buffer. This procedure is useful only with a full
frame buffer in the RAM of the microcontroller (Constructor with buffer option "f", see here). This procedure
will also send a refresh message (refreshDisplay) to an e-Paper/e-Ink device.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
clearBuffer(long)
public static void clearBuffer(long id)
Clears all pixel in the memory frame buffer. Use sendBuffer to transfer the cleared frame buffer to the display. In most cases, this procedure is useful only with a full frame buffer in the RAM of the microcontroller (Constructor with buffer option "f", see here). This procedure will also send a refresh message (refreshDisplay) to an e-Paper/e-Ink device.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
sendBuffer(long)
public static void clearDisplay(long id)
Clears all pixel in the internal buffer AND on the connected display. This procedure is also called from
begin. Usually there is no need to call this function except for the init procedure. Other procedures like sendBuffer(long)
and nextPage(long)
will also overwrite (and clear) the display..
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
begin(long)
public static void begin(long id)
Simplified setup procedure of the display for the Arduino enviornment. See the setup guide for the selection of a suitable U8g2 constructor. This function will reset, configure, clear and disable power save mode of the display. U8g2 can also detect key press events. Up to six buttons can be observed. The Arduino pin number can be assigned here. Use U8X8_PIN_NONE if there is no switch connected to the pin. The switch has to connect the GPIO pin with GND (low active button). Use getMenuEvent to check for any key press event. Select, next and prev pins are also required for the user interface procedures (for example userInterfaceMessage ).
begin will call:
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
initDisplay(long)
,
setPowerSave(long, boolean)
,
clearDisplay(long)
public static int getHeight(long id)
Get the current height of the display instance
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
public static int getWidth(long id)
Get the current width of the display instance
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
public static void clear(long id)
Clears all pixel on the display and the buffer. Puts the cursor for the print function into the upper left corner.
clear will call:
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
clearBuffer(long)
public static int setAutoPageClear(long id, int mode)
Enables (mode=1) or disables (mode=0) automatic clearing of the pixel buffer by the firstPage(long)
and nextPage(long)
procedures. By default this is enabled and in most situation it is not required to
disable this. If disabled, the user is responsible to set ALL pixel of the current pixel buffer to some suitable
state. The buffer can be erased manually with the clearBuffer procedure. One application for using this function
are situation where the background is rendered manually through a direct manipulation of the pixel buffer (see
DirectAccess.ino example).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
mode
- 0, to turn off automatic clearing of the internal pixel buffer. Default value is 1.getBuffer(long)
public static void setBitmapMode(long id, int mode)
Defines, whether the bitmap functions will write the background color (mode 0/solid, mode = 0) or not (mode 1/transparent, mode = 1). Default mode is 0 (solid mode).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
mode
- Enable (1) or disable (0) transparent mode.drawBitmap(long, int, int, int, int, byte[])
,
drawXBM(long, int, int, int, int, byte[])
public static void setContrast(long id, int value)
Set the contrast or brightness for the display (if supported). Range for 'value': 0 (no contrast) to 255 (maximum contrast or brightness).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
value
- Contrast or brightness from 0 to 255.public static void setDisplayRotation(long id, int rotation)
Changes the display rotation. Usually the rotation is defined as part of the constructor. The argment can be one of the following values:
Constant |
Description |
---|---|
|
No rotation, landscape |
|
90 degree clockwise rotation |
|
180 degree clockwise rotation |
|
270 degree clockwise rotation |
|
No rotation, landscape, display content is mirrored (v2.6.x) |
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
rotation
- Display rotation argument.public static int getBuffer(long id)
Return the address of the start of the buffer. This is a also the address of the leftmost tile of the current
page (Byte 0 in the above memory structure). The total memory size of the buffer is 8 *
u8g2.getBufferTileHeight() * u8g2.getBufferTileWidth(). The buffer can be erased with clearBuffer(long)
.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getBufferTileHeight(long)
,
getBufferTileWidth(long)
,
clearBuffer(long)
public static int getBufferTileWidth(long id)
Return the width of the page buffer in tiles (One tile has a width of 8 pixel).
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getBuffer(long)
,
getBufferTileHeight(long)
public static int getBufferTileHeight(long id)
Return the height of the page buffer in tiles. The height of one tile is 8 pixel.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getBuffer(long)
,
getBufferTileWidth(long)
public static int getBufferCurrTileRow(long id)
Return the intended position for the content of the pixel buffer (page) on the target display. If it is
assumed, that the buffer will be placed at the top of the display, then this value is zero. This value is
modified by firstPage(long)
/nextPage(long)
and used by sendBuffer(long)
to place the
content of the pixel buffer at the target position.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
getBuffer(long)
public static void setBufferCurrTileRow(long id, int row)
Set the position of the pixel buffer for the sendBuffer command.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
row
- Location for the pixel buffer on the display. row is the "tile" position and must be multiplied with 8 to
get the pixel position.getBuffer(long)
,
sendBuffer(long)
public static int getStrWidth(long id, String text)
Return the pixel width of string.
id
- The display instance id retrieved via setup(String, int, int, int, int, byte[], boolean)
text
- Text string to be measuredsetFont(long, String)
,
setFont(long, byte[])
,
drawString(long, int, int, String)
Copyright © 2018 Universal Character/Graphics display library. All rights reserved.