Lvgl库8.1部分学习记录

LVGL是一个高度可裁剪、低资源占用、界面美观且易用的嵌入式系统图形库。

部分常用接口说明

lv_img_set_src

lv_img_set_src是LVGL(Light and Versatile Graphics Library)中用于设置图片源的函数。这个函数允许你为一个图像对象设置一个新的图像源,可以是一个二进制数组(存储在内存中的图像数据),也可以是一个文件路径(例如,使用LVGL的文件系统支持从SD卡或Flash中加载图像)。

函数定义如下:

void lv_img_set_src(lv_obj_t * img, const void * src);
参数说明:

img:要设置图片源的图像对象。
src:新的图片源,可以是一个二进制数组的指针,或者是一个文件路径的字符串。
例如,你可以这样设置一个图像对象的图片源:
lv_img_set_src(img1, "S:/path/to/image");
或者,如果你有一个名为my_image_data的二进制数组,你可以这样设置:
lv_img_set_src(img1, my_image_data);

在上述两个例子中,img1是一个图像对象,我们分别为其设置了一个新的图片源。第一个例子中图片源是一个文件路径,第二个例子中图片源是一个二进制数组。

lv_img_set_zoom

lv_img_set_zoom 是 LeVeL 库中的一个函数,用于设置图像的缩放级别。在 LeVeL 库中,lv_img 是一个用于显示图像的组件,通常用于显示图片、动画或视频。

函数原型如下:

void lv_img_set_zoom(lv_obj_t *img, lv_coord_t factor);

参数说明:

  • img:图像组件的指针。
  • factor:缩放级别,Using the lv_img_set_zoom(img,factor) the images will be zoomed.Set factor to 256 or LV_IMG_ZOOM_NONE to disable zooming. A larger value enlarges the images (e.g. 512 double size), a smaller value shrinks it (e.g. 128 half size). Fractional scale works as well. E.g. 281 for 10% enlargement.

用途:

lv_img_set_zoom 函数通常用于调整图像的大小,以适应不同的屏幕尺寸或分辨率。例如,在显示图像时,可以根据屏幕大小调整图像的大小,以获得最佳的显示效果。

lvgl_img_create

lv_img_create是LVGL库中的一个函数,用于创建一个图像对象。LVGL是一个轻量级的图形库,主要用于嵌入式设备上的图形用户界面。

实现原理:lv_img_create函数通过分配内存来创建一个图像对象,并设置一些基本属性,如图像的宽度和高度等。这个函数通常在创建一个图像控件时使用,例如在创建一个图像按钮或图像标签时。

用途:lv_img_create函数可以用来创建各种图形元素,如图像、图标等,并在LVGL应用中进行使用。

注意事项:在使用lv_img_create函数时,需要确保已经正确地初始化了LVGL库,并且提供了正确的图像数据。同时,还需要处理可能出现的内存分配错误,以确保应用的稳定性。

fb_screeninfo_t *screen_info = get_screen(APPCONFIG_SCREEN_CHANNEL);

这段代码是用于获取屏幕信息的一个函数调用。fb_screeninfo_t 是一个结构体类型,用于存储屏幕的配置信息,如分辨率、颜色深度等。get_screen() 是一个函数,它的作用是获取指定频道的屏幕信息,并将结果存储在 screen_info 指针所指向的结构体中。APPCONFIG_SCREEN_CHANNEL 是一个常量,表示要获取的屏幕信息所在的频道。

这个函数通常用于获取屏幕的配置信息,以便在程序中进行相应的图形界面绘制和显示。在使用这个函数时,需要注意以下几点:

  1. fb_screeninfo_t 结构体的定义可能因不同的硬件和驱动而有所不同,因此需要根据具体的硬件和驱动进行相应的修改。

  2. get_screen() 函数的实现可能需要访问硬件设备,因此需要确保在调用这个函数时,硬件设备已经正确地初始化并处于可访问状态。

  3. 在使用完 screen_info 指针后,需要记得释放指针所指向的结构体内存,以避免内存泄漏。

lv_img_set_size_mode

/**
 * Set the image object size mode.
 *
 * @param obj       pointer to an image object
 * @param mode      the new size mode.
 */
void lv_img_set_size_mode(lv_obj_t * obj, lv_img_size_mode_t mode);

lv_obj_create

/**
 * Create a base object (a rectangle)
 * @param parent    pointer to a parent object. If NULL then a screen will be created.
 * @return          pointer to the new object
 */
lv_obj_t * lv_obj_create(lv_obj_t * parent);

At the highest level of the LVGL object hierarchy is the display which represents the driver for a display device (physical display or simulator). A display can have one or more screens associated with it. Each screen contains a hierarchy of objects for graphical widgets representing a layout that covers the entire display.
When you have created a screen like lv_obj_t * screen = lv_obj_create(NULL), you can make it active with lv_scr_load(screen). The lv_scr_act() function gives you a pointer to the active screen.
If you have multiple displays, it’s important to know that the screen functions operate on the most recently created display or the one explicitly selected with lv_disp_set_default. To get an object’s screen use the lv_obj_get_screen(obj) function.

lv_scr_act

/**
 * Get the active screen of the default display
 * @return pointer to the active screen
 */
static inline lv_obj_t * lv_scr_act(void)
{
    return lv_disp_get_scr_act(lv_disp_get_default());
}

lv_obj_clear_flag

/**
 * Clear one or more flags
 * @param obj   pointer to an object
 * @param f     OR-ed values from `lv_obj_flag_t` to set.
 */
void lv_obj_clear_flag(lv_obj_t * obj, lv_obj_flag_t f);

It’s possible to make an object non-scrollable with lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE).
Non-scrollable objects can still propagate the scrolling (chain) to their parents.
The direction in which scrolling happens can be controlled by lv_obj_set_scroll_dir(obj, LV_DIR_…).
The following values are possible for the direction:
• LV_DIR_TOP only scroll up
• LV_DIR_LEFT only scroll left
• LV_DIR_BOTTOM only scroll down
• LV_DIR_RIGHT only scroll right
• LV_DIR_HOR only scroll horizontally
• LV_DIR_TOP only scroll vertically
• LV_DIR_ALL scroll any directions
OR-ed values are also possible. E.g. LV_DIR_TOP | LV_DIR_LEFT.

lv_label_set_text

/**
 * Set a new text for a label. Memory will be allocated to store the text by the label.
 * @param obj           pointer to a label object
 * @param text          '\0' terminated character string. NULL to refresh with the current text.
 */
void lv_label_set_text(lv_obj_t * obj, const char * text);

lv_img_dsc_t

/** Image header it is compatible with
 * the result from image converter utility*/
typedef struct {
    lv_img_header_t header; /**< A header describing the basics of the image*/
    uint32_t data_size;     /**< Size of the image in bytes*/
    const uint8_t * data;   /**< Pointer to the data of the image*/
} lv_img_dsc_t;

lv_img_header_t

/**
 * The first 8 bit is very important to distinguish the different source types.
 * For more info see `lv_img_get_src_type()` in lv_img.c
 * On big endian systems the order is reversed so cf and always_zero must be at
 * the end of the struct.
 */
#if LV_BIG_ENDIAN_SYSTEM
typedef struct {

    uint32_t h : 11; /*Height of the image map*/
    uint32_t w : 11; /*Width of the image map*/
    uint32_t reserved : 2; /*Reserved to be used later*/
    uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
                                 non-printable character*/
    uint32_t cf : 5;          /*Color format: See `lv_img_color_format_t`*/

} lv_img_header_t;
#else
typedef struct {

    uint32_t cf : 5;          /*Color format: See `lv_img_color_format_t`*/
    uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
                                 non-printable character*/

    uint32_t reserved : 2; /*Reserved to be used later*/

    uint32_t w : 11; /*Width of the image map*/
    uint32_t h : 11; /*Height of the image map*/
} lv_img_header_t;
#endif
  • 24
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值