u8g2图像库c语言函数

前言:

u8g2官方函数库手册链接:

u8g2reference · olikraus/u8g2 Wiki · GitHub

大部分函数是基于c++和Arduino的,部分函数有基于c的形式。由于本次实验设计主要是基于c语言的stm32开发,在这里主要介绍一些c语言的u8g2图像库函数。

1. clearBuffer

void u8g2_ClearBuffer(u8g2_t *u8g2);
  • Description: 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.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -

2. clearDisplay

void u8g2_ClearDisplay(u8g2_t *u8g2);
  • Description: 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 and nextPage will also overwrite (and clear) the display.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -
  • Notes:
    • This command can be used with all constructors (_F__1__2_).
    • Do not use this command within the picture loop (between firstPage and nextPage).

3. drawBitmap

void u8g2_DrawBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap)
  • Description: Draw 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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position (left position of the bitmap).
    • y: Y-position (upper position of the bitmap).
    • cnt: Number of bytes of the bitmap in horizontal direction. The width of the bitmap is cnt*8.
    • h: Height of the bitmap.
  • Returns:-
  • Note: This function should not be used any more, please use drawXBM instead.(不再被使用,换成drawXBM函数了,drawXBM下文介绍)

4. drawBox

void u8g2_DrawBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
  • Description: 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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position of upper left edge.
    • y: Y-position of upper left edge.
    • w: Width of the box.
    • h: Height of the box.
  • Returns:
  • Example:u8g2.drawBox(3,7,25,15);
u8g2.drawBox(3,7,25,15);

 5. drawButtonUTF8

void u8g2_DrawButtonUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t flags, u8g2_uint_t width, u8g2_uint_t padding_h, u8g2_uint_t padding_v, const char *text)
  • Description: Draw a frame / box around a provided text. This is similar to drawUTF8, but adds some decoration to the text.

  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • xy: Position of the first character on the display. If U8G2_BTN_HCENTER is used, then this is the center position of the text.
    • flags: See table above. Multiple flags can be used with the "or" operator.
    • width: Minimum width of the text. If 0 (or lower than the text width), then the text width is used for the frame.
    • padding_h: Extra space before and after the text.
    • padding_v: Extra space above and below the text.
    • text: UTF8 encoded string which will be drawn on the display.
  • Returns:
  • Note: Font mode is set to 1 by this function (see setFontMode)
  • Example 1: Left adjusted text with 2 pixel space (padding_h=2 and padding_v=2) around the text and a 2 pixel border (BW2).
  • u8g2.setFont(u8g2_font_helvR08_tr);
    u8g2.drawButtonUTF8(62, 20, U8G2_BTN_BW2, 0,  2,  2, "Btn" );

  • Example 2: Centered text
  • u8g2.setFont(u8g2_font_helvR08_tr);
    u8g2.drawButtonUTF8(62, 20, U8G2_BTN_HCENTER|U8G2_BTN_BW2, 34,  2,  2, "Btn" );

  • Example 3: Centered text with shadow. Note: The shadow thickness is always equal to the frame border width. The gap between frame and shadow is specified by the flag.
  • u8g2.setFont(u8g2_font_helvR08_tr);
    u8g2.drawButtonUTF8(62, 20, U8G2_BTN_SHADOW1|U8G2_BTN_HCENTER|U8G2_BTN_BW2, 34,  2,  2, "Btn" );

    Example 4: Left adjusted text with 2 pixel space around the text. The text (including the 2 pixel space) is inverted.

  • u8g2.setFont(u8g2_font_helvR08_tr);
    u8g2.drawButtonUTF8(62, 20, U8G2_BTN_INV, 0,  2,  2, "Btn" );

     

  • Example 5: Left adjusted inverted text with 2 pixel space and 2 pixel border. The border is just added around the pixel space.
  • u8g2.setFont(u8g2_font_helvR08_tr);
    u8g2.drawButtonUTF8(62, 20, U8G2_BTN_INV|U8G2_BTN_BW2, 0,  2,  2, "Btn" );

  • Example 6: Text at position (5, 20) within a full display width inverted bar: The text width is expanded to u8g2.getDisplayWidth()-5*2 pixel. Then another 5 pixel space is added before and after the text (total width: 5+u8g2.getDisplayWidth()-5*2+5).
  • u8g2.setFont(u8g2_font_helvR08_tr);
    u8g2.drawButtonUTF8(5, 20, U8G2_BTN_INV, u8g2.getDisplayWidth()-5*2,  5,  2, "Btn" );

5. drawCircle(画空心圆)

void u8g2_DrawCircle(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t opt)
  • Description: 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:U8G2_DRAW_UPPER_RIGHTU8G2_DRAW_UPPER_LEFTU8G2_DRAW_LOWER_LEFTU8G2_DRAW_LOWER_RIGHTU8G2_DRAW_ALL. These values can be combined with the | operator. This procedure will use the current color (setDrawColor) for drawing.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x0y0: Position of the center of the circle.
    • rad: Defines the size of the circle: Radus = rad.
    • opt: Selects some or all sections of the circle.
      • U8G2_DRAW_UPPER_RIGHT
      • U8G2_DRAW_UPPER_LEFT
      • U8G2_DRAW_LOWER_LEFT
      • U8G2_DRAW_LOWER_RIGHT
      • U8G2_DRAW_ALL
  • Returns:
  • Note: Draw color 2 (XOR Mode) is not supported.
  • Example 1:
  •   u8g2.drawCircle(20, 25, 10, U8G2_DRAW_ALL);

  • Example 2:

    u8g2_DrawCircle(&u8g2,20, 25, 10, U8G2_DRAW_UPPER_RIGHT|U8G2_DRAW_UPPER_LEFT);

     

6. drawDisc(画实心圆)

void u8g2_DrawDisc(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t opt)
  • Description: 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 opt are:U8G2_DRAW_UPPER_RIGHTU8G2_DRAW_UPPER_LEFTU8G2_DRAW_LOWER_LEFTU8G2_DRAW_LOWER_RIGHTU8G2_DRAW_ALL. These values can be combined with the | operator. This procedure will use the current color (setDrawColor) for drawing.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x0y0: Position of the center of the disc.
    • rad: Defines the size of the circle: Radus = rad.
    • opt: Selects some or all sections of the disc.
      • U8G2_DRAW_UPPER_RIGHT
      • U8G2_DRAW_UPPER_LEFT
      • U8G2_DRAW_LOWER_LEFT
      • U8G2_DRAW_LOWER_RIGHT
      • U8G2_DRAW_ALL
  • Returns:
  • Note: Draw color 2 (XOR Mode) is not supported.
  • Example:
  • 	u8g2_DrawDisc(&u8g2, 20, 25,10,U8G2_DRAW_ALL);

7. drawEllipse

void u8g2_DrawEllipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t opt)
  • Description: Draw 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 opt are:U8G2_DRAW_UPPER_RIGHTU8G2_DRAW_UPPER_LEFTU8G2_DRAW_LOWER_LEFTU8G2_DRAW_LOWER_RIGHTU8G2_DRAW_ALL. These values can be combined with the | operator. The diameter is twice the radius plus one.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x0y0: Position of the center of the filled circle.
    • rxry: Defines the size of the ellipse.
    • opt: Selects some or all sections of the ellipse.
      • U8G2_DRAW_UPPER_RIGHT
      • U8G2_DRAW_UPPER_LEFT
      • U8G2_DRAW_LOWER_LEFT
      • U8G2_DRAW_LOWER_RIGHT
      • U8G2_DRAW_ALL
  • Returns:
  • Note: Draw color 2 (XOR Mode) is not supported.
  • Example:
  •   u8g2.drawEllipse(20, 25, 15, 10, U8G2_DRAW_ALL);

8. drawFilledEllipse

void u8g2_DrawFilledEllipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t opt)
void u8g2_DrawFilledEllipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t opt)
  • Description: 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 opt are:U8G2_DRAW_UPPER_RIGHTU8G2_DRAW_UPPER_LEFTU8G2_DRAW_LOWER_LEFTU8G2_DRAW_LOWER_RIGHTU8G2_DRAW_ALL.These values can be combined with the | operator.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x0y0: Position of the center of the filled circle.
    • rxry: Defines the size of the ellipse.
    • opt: Selects some or all sections of the ellipse.
      • U8G2_DRAW_UPPER_RIGHT
      • U8G2_DRAW_UPPER_LEFT
      • U8G2_DRAW_LOWER_LEFT
      • U8G2_DRAW_LOWER_RIGHT
      • U8G2_DRAW_ALL
  • Returns:
  • Note: Draw color 2 (XOR Mode) is not supported.

9. drawFrame

void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
  • Description: 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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position of upper left edge.
    • y: Y-position of upper left edge.
    • w: Width of the frame.
    • h: Height of the frame.
  • Returns:
  • Example:
  • u8g2.drawFrame(3,7,25,15);

10. drawGlyph(非常有趣,强大并且可爱的函数,需要配合u8g2_SetFont一起使用,u8g2_SetFont函数下文讲解,考虑出专栏ing)

u8g2_uint_t u8g2_DrawGlyph(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint16_t encoding);
u8g2_uint_t u8g2_DrawGlyphX2(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint16_t encoding);
  • Description: 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. The X2 variant of this function will double the size of the glyph but will ignore the font direction setting.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • xy: Position of the character on the display.
    • encoding: Unicode value of the character.
  • Returns: Width of the character.
  • Note: This drawing function depends on the current font mode and drawing color.
  • Example: The "snowman" glyph is part of the unicode weather symbols and has the unicode 9731 (dezimal) / 2603 (hex): "☃". The "snowman" is also part of the u8g2 font u8g2_font_unifont_t_symbols (see below).
  •     u8g2.setFont(u8g2_font_unifont_t_symbols);
        u8g2.drawGlyph(5, 20, 0x2603);	/* dec 9731/hex 2603 Snowman */

     该函数可以绘制超多超多Fonts里面有的小图案、汉字(甚至部分古文)、他国语言文字、奇形怪状的符号等等,具体内容会在setFonts中讲解,只要Fonts中有的,这个函数都可以给绘制出来,很牛掰!!

  • 想要显示中文某个汉字的步骤:第一,打开某个在线中文转unicode的网站,如:Unicode编码转换 - 站长工具 (chinaz.com)

  • 输入想要的汉字,将转换后得到的4位unicode码复制下来,前加0x作为第四个参数。

  • 注意:部分Fonts中不含某些不常用的汉字,如果发现汉字无法显示,可以考虑更换Fonts。

11. drawHLine

  void u8g2_DrawHLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w)
  • Description: 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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position.
    • y: Y-position.
    • w: Length of the horizontal line.
  • Returns: -

12. drawLine

void u8g2_DrawLine(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t x1, u8g2_uint_t y1)
  • Description: Draw a line between two points. This procedure will use the current color (setDrawColor).
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x0: X-position of the first point.
    • y0: Y-position of the first point.
    • x1: X-position of the second point.
    • y1: Y-position of the second point.
  • Returns:
  • See also: drawPixel setDrawColor
  • Example:
  • u8g2.drawLine(20, 5, 5, 32);

13. drawPixel

void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
  • Description: 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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position.
    • y: Y-position.
  • Returns:

14. drawRBox/drawRFrame

void u8g2_DrawRBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
void u8g2_DrawRFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
  • Description: Draw a box/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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position of upper left edge.
    • y: Y-position of upper left edge.
    • w: Width of the box.
    • h: Height of the box.
    • r: Radius for the four edges.
  • Returns: -
  • Example:
  •     u8g2.drawRFrame(20,15,30,22,7);

15. drawStr

u8g2_uint_t u8g2_DrawStr(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *s);
u8g2_uint_t u8g2_DrawStrX2(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *s);
  • Description: 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. The X2 variant will double the size of the sting but will ignore the font direction setting.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • xy: Position of the first character on the display.
    • s: Text.
  • Returns: Width of the string.
  • Note 1: This drawing function depends on the current font mode and drawing color.
  • Note 2: Use the print function to print the value of a numeric variable.
  • Example:
  •     u8g2.setFont(u8g2_font_ncenB14_tr);
        u8g2.drawStr(0,15,"Hello World!");

16. drawTriangle

void u8g2_DrawTriangle(u8g2_t *u8g2, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
  • Description: 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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • 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.
  • Returns: -
  • Example:
  • u8g2.drawTriangle(20,5, 27,50, 5,32);

17. drawUTF8(与drawGlyph不同的是,这个更类似drawStr,是将“”中的UTF8的内容直接打印出来)

u8g2_uint_t u8g2_DrawUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *s);
u8g2_uint_t u8g2_DrawUTF8X2(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *s);
  • Description: 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. Use getUTF8Len instead of strlen. The X2 variant will double the size of the UTF8 sting but will ignore the font direction setting.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • xy: Position of the first character on the display.
    • s: UTF-8 encoded text.
  • Returns: Width of the string.
  • Note 1: This drawing function depends on the current font mode and drawing color.
  • Note 2: Use the print function to print the value of a numeric variable.
  • See also: setFont drawStr print
  • Example:
  •     u8g2.setFont(u8g2_font_unifont_t_symbols);
        u8g2.drawUTF8(5, 20, "Snowman: ☃");	

18. drawVLine

  void u8g2_DrawVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t h)
  • Description: 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.
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position.
    • y: Y-position.
    • h: Length of the vertical line.
  • Returns: -

19. drawXBM

void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
void u8g2_DrawXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
  • Description: 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 video instruction is here (external link). The result will look like this:
#define u8g_logo_width 38
#define u8g_logo_height 24
static unsigned char u8g_logo_bits[] = {
   0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xe0, 0xe0,
...
   0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x3f };

This could can be copied directly into your code. Use drawXBM to draw this bitmap at (0,0):

u8g2.drawXBM( 0, 0, u8g_logo_width, u8g_logo_height, u8g_logo_bits);
  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • x: X-position.
    • y: Y-position.
    • w: Width of the bitmap.
    • h: Height of the bitmap.
    • bitmap: Pointer to the start of the bitmap.
  • Returns:
  • Note: The XBMP version requires, that the bitmap array is defined in this way:
static const unsigned char u8g_logo_bits[] U8X8_PROGMEM = { ...

补充:将bmp文件转换为XBM格式可以在网上搜索在线转换,以下为两个转换的网站链接示例:

1. PNG轉XBM轉換器。在线自由 — Convertio

2. 在线BMP转XBM转换器, 在线转换器 - 转换视频, 音乐, 图像, PDF - Office-Converter.com

1好像每天只能免费转换10次,2不清楚。

20. firstPage

void u8g2_FirstPage(u8g2_t *u8g2);
  • Description: 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.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -
  • Note: This procedure sets the current page position to zero.
  • Example:
  u8g2.firstPage();
  do {
    /* all graphics commands have to appear within the loop body. */    
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(0,20,"Hello World!");
  } while ( u8g2.nextPage() );

21. initDisplay

void u8g2_InitDisplay(u8g2_t *u8g2);
  • Description: 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.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -

22. initInterface

void u8g2_InitInterface(u8g2_t *u8g2);
  • Description: Start and configure the communication procedures to the display. This call will not communicate to the display at all: No init code is sent to the display and also the content is not cleared. initInterface can be used in cases where the display already shows some useful content but the controller just comes out of deep sleep mode. If used, then it replaces begin or initDisplay.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -
  • See also: initDisplay begin
  • Example:
  if ( power_on_reset ) 
    u8g2.begin();        // do a proper reset of the display
  else
    u8g2.initInterface();        // assume that the display already works

23. nextPage

uint8_t u8g2_NextPage(u8g2_t *u8g2);
  • Description: 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 of 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).
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: 0, once the loop is completed (all data transfered to the display).
  • Note: This procedure adds the height (in tile rows) of the current buffer to the current page position.
  • See also: firstpage
  • Example:
  u8g2.firstPage();
  do {
    /* all graphics commands have to appear within the loop body. */    
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(0,20,"Hello World!");
  } while ( u8g2.nextPage() );

24. sendBuffer

void u8g2_SendBuffer(u8g2_t *u8g2);
  • Description: Send the content of the memory frame buffer to the display. Use clearBuffer 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.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -
  • Note: Actually this procedure will send the current page to the display. This means, the content of the internal pixel buffer will be placed in the tile row given by the current page position. This means, that this procedure could be used for partial updates on paged devices (constructor with buffer option "1" or "2"). However, this will only work for LCDs. It will not work with most e-Paper/e-Ink devices because of the buffer switch in the display controller. Conclusion: Use this command only together with full buffer constructors. It will then work with all LCDs and e-Paper/e-Ink devices.
  • See also: clearBufferupdateDisplay
  • Example:
  • void loop(void) {
      u8g2.clearBuffer();
      // ... write something to the buffer 
      u8g2.sendBuffer();
      delay(1000);

    25. setBitmapMode

void u8g2_SetBitmapMode(u8g2_t *u8g2, uint8_t is_transparent);
  • Description: Defines, whether the bitmap functions will write the background color (mode 0/solid, is_transparent = 0) or not (mode 1/transparent, is_transparent = 1). Default mode is 0 (solid mode).
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • is_transparent: Enable (1) or disable (0) transparent mode.
  • Returns: -
  • See also: drawBitmap drawXBM
  • Note: This function will be available with v2.15.x
  • Example:
  • u8g2.setDrawColor(1);
    u8g2.setBitmapMode(0);
    u8g2.drawXBM(4,3, u8g2_logo_97x51_width, u8g2_logo_97x51_height,  u8g2_logo_97x51_bits);
    u8g2.drawXBM(12,11, u8g2_logo_97x51_width, u8g2_logo_97x51_height,  u8g2_logo_97x51_bits);

    u8g2.setDrawColor(1);
    u8g2.setBitmapMode(1);
    u8g2.drawXBM(4,3, u8g2_logo_97x51_width, u8g2_logo_97x51_height,  u8g2_logo_97x51_bits);
    u8g2.drawXBM(12,11, u8g2_logo_97x51_width, u8g2_logo_97x51_height,  u8g2_logo_97x51_bits);

26. setClipWindow

void u8g2_SetClipWindow(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t x1, u8g2_uint_t y1 );
  • Description: Restricts all graphics output to the specified range. The range is defined from x0 (included) to x1 (excluded) and y0 (included) to y1 (excluded). Use setMaxClipWindow to restore writing to the complete window.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • x0: Left edge of the visible area.
    • y0: Upper edge of the visible area.
    • x1: Right edge +1 of the visible area.
    • y1: Lower edge +1 of the visible area.
  • Returns: -
  • Example:
  • u8g2.setClipWindow(10, 10, 85, 30);
    u8g2.setDrawColor(1);
    u8g2.drawStr(3, 32, "U8g2");

27. setContrast(对比度/亮度)

void u8g2_SetContrast(u8g2_t *u8g2, uint8_t value);
  • Description: Set the contrast or brightness for the display (if supported). Range for 'value': 0 (no contrast) to 255 (maximum contrast or brightness).
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • value: Contrast or brightness from 0 to 255.
  • Returns: -
  • 注意:0也不是熄灭状态,只是暗了点

28. setDisplayRotation

void u8g2_SetDisplayRotation(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);

Description: Changes the display rotation. Usually the rotation is defined as part of the U8g2 constructor. The argment u8g2_cb can be one of the following values:

  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • u8g2_cb: Display rotation argument.

29. setDrawColor

void u8g2_SetDrawColor(u8g2_t *u8g2, uint8_t color);
  • Description: 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 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:
    • clearclearBuffer: Both functions will always set the buffer to the pixel value 0. The color argument of setDrawColor is ignored.
    • drawGlyph: All font drawing procedures will use this color argument as foreground color. In none-transparent (solid) mode (setFontMode) the complement of the color value will be the background color and is set to 0 for color value 2 (However, suggestion is not to use solid and XOR mode together):
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • color: 0 (clear pixel value in the display RAM), 1 (set pixel value) or 2 (XOR mode)
  • Returns: -
  • Note: Not all graphics procedures will support XOR mode. Especially XOR mode is not supported by drawCircledrawDiscdrawEllipse and drawFilledEllipse.
  • Example 1: String on background pattern with color values 0 and 1 in transparent mode:
  • Example 2: Transparent font mode with different color values:
u8g2.setFontMode(1);  /* activate transparent font mode */
u8g2.setDrawColor(1); /* color 1 for the box */
u8g2.drawBox(22, 2, 35, 50);
u8g2.setFont(u8g2_font_ncenB14_tf);
u8g2.setDrawColor(0);
u8g2.drawStr(5, 18, "abcd");
u8g2.setDrawColor(1);
u8g2.drawStr(5, 33, "abcd");
u8g2.setDrawColor(2);
u8g2.drawStr(5, 48, "abcd");

 30. setFlipMode

void u8g2_SetFlipMode(u8g2_t *u8g2, uint8_t is_enable);
  • Description: 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.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • is_enable: Enable (1) or disable (0) 180 degree rotation of the display content
  • Returns: -

31. setFont(非常强大的Font库,具体使用考虑后续出专栏,这里不再赘述)

void u8g2_SetFont(u8g2_t *u8g2, const uint8_t *font);
  • Description: Define a u8g2 font for the glyph and string drawing functions. Note: u8x8 font can NOT be used. Available fonts are listed here. The last two characters of the font name define the type and character set for the font:

  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • font: Point to a u8g2 font. A list of available fonts is here.
  • Returns: -

32. setFontDirection

void u8g2_SetFontDirection(u8g2_t *u8g2, uint8_t dir)
  • Description: The arguments defines the drawing direction of all strings or glyphs.

  • Arguments:
    • u8g2 : Pointer to the u8g2 structure (C interface only).
    • dir: Writing direction/string rotation.
  • Returns:
  • Example:
u8g2.setFont(u8g2_font_ncenB14_tf);
u8g2.setFontDirection(0);
u8g2.drawStr(15, 20, "Abc");
u8g2.setFontDirection(1);
u8g2.drawStr(15, 20, "Abc");

 33.  setFontMode

void u8g2_SetFontMode(u8g2_t *u8g2, uint8_t is_transparent);
  • Description: Defines, whether the glyph and string drawing functions will write the background color (mode 0/solid, is_transparent = 0) or not (mode 1/transparent, is_transparent = 1). Default mode is 0 (background color of the characters is overwritten).
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • is_transparent: Enable (1) or disable (0) transparent mode.
  • Returns: -
  • Note: Always choose a suitable font, depending on the font mode:

  • Example: This example shows four combinations with the color value 0 and 1 (setDrawColor).
  • /* write background pattern, then: */
    u8g2.setFontMode(0);
    u8g2.setDrawColor(1);
    u8g2.drawStr(3, 15, "Color=1, Mode 0");
    u8g2.setDrawColor(0);
    u8g2.drawStr(3, 30, "Color=0, Mode 0");
    u8g2.setFontMode(1);
    u8g2.setDrawColor(1);
    u8g2.drawStr(3, 45, "Color=1, Mode 1");
    u8g2.setDrawColor(0);
    u8g2.drawStr(3, 60, "Color=0, Mode 1");

34. setFontPosBaseline/setFontPosBottom/setFontPosTop/setFontPosCenter

void u8g2_SetFontPosBaseline(u8g2_t *u8g2);
void u8g2_SetFontPosBottom(u8g2_t *u8g2);
void u8g2_SetFontPosTop(u8g2_t *u8g2);
void u8g2_SetFontPosCenter(u8g2_t *u8g2);
  • Description: Change the reference position for the glyph and string draw functions. By default the reference position is "Baseline".
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -
  • Example:

 35. setMaxClipWindow

void u8g2_SetMaxClipWindow(u8g2_t *u8g2);
  • Description: Removes the effect of setClipWindow. Graphics is written to the complete display.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
  • Returns: -

36. setPowerSave

void u8g2_setPowerSave(u8g2_t *u8g2, uint8_t is_enable)
  • Description: Activates (is_enable = 1) or disables (is_enable = 0) 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.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • is_enable: Enable (1) or disable (0) power save mode for the display.
  • Returns: -

37. updateDisplay/updateDisplayArea

void u8g2_UpdateDisplay(u8g2_t *u8g2)
void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t  tx, uint8_t ty, uint8_t tw, uint8_t th)
  • Description: Updates all or the specified rectangle area of the display. The member function updateDisplay() is almost identical to sendBuffer(). Member function updateDisplayArea() will update the specified rectangle area: Only the specified area is copied from the internal buffer to the display. The area has to be specified in tiles. One tile is a 8x8 pixel area. To get the pixel value, multiply the tile value with 8 (for U8G2_R0). The tile coordinates are independent from the applied rotation in the U8g2 constructor but have the same orientation as U8G2_R0. For other rotations the calculation between pixel value tile position is more complicated. The three member functions sendBufferupdateDisplay and updateDisplayArea are designed for the full buffer mode (constructor with _F_ in the name). However sendBuffer and updateDisplay can be used in page mode also. If updateDisplay is used together with ePaper displays, ensure that a proper refresh sequence is send to the display. Differences between sendBufferupdateDisplay and updateDisplayArea:

  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • txty: Upper left corner of the area, given as tile position.
    • twth: Width and height of the area in tiles.
  • Returns: -
  • Note 1: updateDisplay() will work for all display controllers. updateDisplayArea() will not fully work for the following controllers: SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0xx
  • Note 2: Range for tx0..getBufferTileWidth()-1 and for ty0..getBufferTileHeight()-1. There is no overflow check. The area must fully fit into the display area. Especially the following conditions must be true: tx+tw <= getBufferTileWidth() and ty+th <= getBufferTileHeight().
  • Note 3: setClipWindow vs updateDisplayArea: Both may generate similar visual effects, however...
    • setClipWindow
      • Pixel coordinates
      • Used within the firstPage/nextPage loop
      • Valid for full and page buffer mode
      • Will limit the number of pixel drawn into the buffer
      • Performance increase due to lesser pixel painting
      • Will work with any rotation command in the constructor
      • Will work with any setting for u8g2.setFlipMode()
    • updateDisplayArea
      • Tile coordinates
      • Must be used outside the firstPage/nextPage loop
      • Valid only for full buffer mode
      • Will limit the data transfer to the display
      • Performance increase due to lesser data transfer to the display
      • Will work with any rotation command in the constructor, but requires more complicated calculation for the tile coordinates if the rotation is not U8G2_R0.
      • Will work with any setting for u8g2.setFlipMode()
  • Note 4: More discussion happend here: Only update the changed pixels in full buffer mode · Issue #736 · olikraus/u8g2 · GitHub
  • Example: u8g2/UpdateArea.ino at master · olikraus/u8g2 · GitHub

38. userInterfaceInputValue

uint8_t u8g2_UserInterfaceInputValue(u8g2_t *u8g2, const char *title, const char *pre, uint8_t *value, uint8_t lo, uint8_t hi, uint8_t digits, const char *post);
  • Description: Requests the input of a 8-bit value. All display output and key processing is done inside this function.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • title: Multiline description for the value (Lines have to be separated with \n).
    • pre: Text before the value.
    • value: A pointer to a variable which will be filled with the input from the user.
    • lo: Lowest value, which can be selected by the user.
    • hi: Highest value, which can be selected by the user.
    • digits: Number of digits (1 to 3).
    • post: Text after the value.
  • Returns: 1, if the user has pressed the select button. 0 if the user has pressed the home/cancel button. The selected value will be stored in value only if the user has pressed the select key.
  • Example:
  • u8g2.userInterfaceInputValue("Select Voltage", "DAC= ", &v, 0, 5, 1, " V");

39. userInterfaceMessage

uint8_t u8g2_UserInterfaceMessage(u8g2_t *u8g2, const char *title1, const char *title2, const char *title3, const char *buttons);
  • Description: Displays a message text and wait for user input. The user can press one button or select between two or more buttons.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • title1: First multiline description (Lines have to be separated with \n).
    • title2: Second singleline description (One line is drawn until first \n or \0).
    • title3: Third multiline description (Lines have to be separated with \n).
    • button: One or more buttons, separated with \n.
  • Returns: 1 to n for if one of the buttons had been selected. 0 if the user has pressed the home/cancel button.
  • Example:
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setFontRefHeightAll();  	/* this will add some extra space for the text inside the buttons */
u8g2.userInterfaceMessage("Title1", "Title2", "Title3", " Ok \n Cancel ");

 40. userInterfaceSelectionList

uint8_t u8g2_UserInterfaceSelectionList(u8g2_t *u8g2, const char *title, uint8_t start_pos, const char *sl)
  • Description: Display a list of scrollable and selectable options. The user can select one of the options.
  • Arguments:
    • u8g2: A pointer to the u8g2 structure.
    • start_pos: The element, which is highlighted first (starts with 1).
    • sl: List of options, one per line (Lines have to be separated with \n).
  • Returns: 1 to n for if one of the buttons had been selected. 0 if the user has pressed the home/cancel button.
  • Example:
  • u8g2.userInterfaceSelectionList("Title", 2, "abcdef\nghijkl\nmnopqr");

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值