Qbcode

The qbcode widget can be used to create or display qrcode and barcode. You can set the border, location and size attribute for qbcode widget. Qbcode widget support text and binary data for qrcode encode, and support text for barcode encode. The qrcode widget follows the QR Code Model 2 standard, upports various specifications from 1 to 40, and supports 4 error correction levels and 4 character encoding modes. By default, the error correction level of QR codes is set to the highest level. For barcode, it supports the code128 format.

Usage

Create Widget

To create a qbcode widget, you can use the function gui_qbcode_create(). Whether a qrcode or barcode is created depends on the encodeType parameter. The encodeType enumeration types are as follows:

typedef enum
{
    QRCODE_ENCODE_TEXT,
    QRCODE_ENCODE_BINARY,
    BARCODE_ENCODE_TEXT,
} T_QBCODE_ENCODE_TYPE;

Set Size and Border

Use the function gui_qbcode_config() to set the size and border of qbcode.

Qrcode Encode Notes

The encoded data for qrcode can exceeded the max bytes by default, which can modify the max version is 15. You can modify the version according to the document: https://www.qrcode.com/zh/about/version.html

Example

Qrcode

#include "gui_qbcode.h"
#define QRCODE_WIDTH     320
#define QRCODE_HEIGHT    320
#define DISPLAY_TYPE     QRCODE_DISPLAY_IMAGE //QRCODE_DISPLAY_SECTION
#define ENCODED_TYPE     QRCODE_ENCODE_TEXT   // QRCODE_ENCODE_BINARY

char* str = "123455678901234567890123455678901234567890123455678901234567890123455678901234567890123455678901234567890";

gui_qbcode_t * qrcode = gui_qbcode_create(parent,
                                          "qrcode",
                                          454/2 - QRCODE_WIDTH/2,
                                          454/2 - QRCODE_HEIGHT/2,
                                          QRCODE_WIDTH,
                                          QRCODE_HEIGHT,
                                          DISPLAY_TYPE,
                                          ENCODED_TYPE);

gui_qbcode_config(qrcode, str, strlen(str), 3);
https://foruda.gitee.com/images/1735625417520694131/22cd8acc_13408154.jpeg

Barcode

#define BARCODE_WIDTH     (143 * 3)
#define BARCODE_HEIGHT    143
#define DISPLAY_TYPE     BARCODE_DISPLAY_IMAGE //BARCODE_DISPLAY_SECTION
#define ENCODED_TYPE     BARCODE_ENCODE_TEXT

char* str = "1234567890";

gui_qbcode_t * barcode = gui_qbcode_create(parent,
                                          "qrcode",
                                          454/2 - BARCODE_WIDTH/2,
                                          454/2 - BARCODE_HEIGHT/2,
                                          BARCODE_WIDTH,
                                          BARCODE_HEIGHT,
                                          DISPLAY_TYPE,
                                          ENCODED_TYPE);

gui_qbcode_config(qrcode, str, strlen(str) + 1, 10);
https://foruda.gitee.com/images/1735625432077099404/d426bd63_13408154.jpeg

API

Enums

enum T_QBCODE_ENCODE_TYPE

T_QBCODE_ENCODE_TYPE structure.

Values:

enumerator QRCODE_ENCODE_TEXT
enumerator QRCODE_ENCODE_BINARY
enumerator BARCODE_ENCODE_TEXT
enum T_QBCODE_DISPLAY_TYPE

T_QBCODE_DISPLAY_TYPE structure.

Values:

enumerator QRCODE_DISPLAY_SECTION
enumerator QRCODE_DISPLAY_IMAGE
enumerator BARCODE_DISPLAY_SECTION
enumerator BARCODE_DISPLAY_IMAGE

Functions

gui_qbcode_t *gui_qbcode_create(void *parent, const char *name, int16_t x, int16_t y, int16_t w, int16_t h, T_QBCODE_DISPLAY_TYPE type, T_QBCODE_ENCODE_TYPE encodeType)

Create a qrcode widget.

Note

this function just create a qrcode object, qbcode data and param should be config by gui_qbcode_config() api.

Parameters:
  • parent – the father widget

  • filename – this qrcode widget’s name.

  • x – the X-axis coordinate relative to parent widget

  • y – the Y-axis coordinate relative to parent widget

  • w – qrcode image display width including border

  • h – qrcode image display height including border

  • type – QRCODE_DISPLAY_SECTION (gui in real-time) or QRCODE_DISPLAY_IMAGE(save in psRAM by default) or BARCODE_DISPLAY_SECTION or BARCODE_DISPLAY_IMAGE.

  • encodeType – QRCODE_ENCODE_TEXT or QRCODE_ENCODE_BINARY or BARCODE_ENCODE_TEXT supported.

Returns:

gui_qbcode_t* success, NULL failed.

void gui_qbcode_config(gui_qbcode_t *qbcode, uint8_t *data, uint32_t data_len, uint8_t border_size)

config qbcode data and border param for a qbcode object.

Parameters:
  • qbcode – a qbcode object pointer.

  • data – input data encoded for qbcode

  • data_len – input data length for encode data

  • border_size – qrode border size, can be 1, 2, 3… by qbcode size, default white color border;

Returns:

null

struct gui_qbcode_t

qrcode widget structure

Public Members

gui_obj_t base
int16_t offset_x
int16_t offset_y
uint16_t border_size
float scale_x
float scale_y
void *data
void *image_data
gui_img_t *qbcode_img
T_QBCODE_DISPLAY_TYPE type
T_QBCODE_ENCODE_TYPE encodeType