RT-Thread qemu LVGL9.5 LV_LOG_USER 输出打印适配

说明

  • RT-Thread : 5.2.0

  • LVGL 9.5

  • BSP : qemu-vexpress-a9

默认 LVGL LV_LOG_USER 没有输出,想对接到 RT-Thread 的控制台输出 rt_kprinf

LVGL 的 LOG开启

  • LVGL 的 lv_conf.h 中,配置设置如下,如果没有就添加
c 复制代码
#define LV_USE_LOG                  1
#define LV_LOG_LEVEL                LV_LOG_LEVEL_USER
  • 等级 LV_LOG_LEVEL_USER 说明 LV_LOG_USER 可以输出

注册 LVGL log 输出的 callback

  • lv_log_register_print_cb 可以设置 LVGL 的打印回调函数,回调函数中,采用 rt_kprintf 输出即可
c 复制代码
void rtt_log_cb(lv_log_level_t level, const char * buf)
{
    rt_kprintf(buf);
}

void lv_user_gui_init(void)
{
    lv_log_register_print_cb(rtt_log_cb);
    lv_example_button_1();
}

测试示例

c 复制代码
#include <stdint.h>
#include <stdio.h>
#include <rtthread.h>
#include <lvgl.h>

void rtt_log_cb(lv_log_level_t level, const char * buf)
{
    rt_kprintf(buf);
}

static void event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);

    if(code == LV_EVENT_CLICKED) {
        LV_LOG_USER("Clicked");
    }
    else if(code == LV_EVENT_VALUE_CHANGED) {
        LV_LOG_USER("Toggled");
    }
}

void lv_example_button_1(void)
{
    lv_obj_t * label;

    lv_obj_t * btn1 = lv_button_create(lv_screen_active());
    lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
    lv_obj_remove_flag(btn1, LV_OBJ_FLAG_PRESS_LOCK);

    label = lv_label_create(btn1);
    lv_label_set_text(label, "Button");
    lv_obj_center(label);

    lv_obj_t * btn2 = lv_button_create(lv_screen_active());
    lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
    lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
    lv_obj_set_height(btn2, LV_SIZE_CONTENT);

    label = lv_label_create(btn2);
    lv_label_set_text(label, "Toggle");
    lv_obj_center(label);
}

void lv_user_gui_init(void)
{
    lv_log_register_print_cb(rtt_log_cb);
    lv_example_button_1();
}

int main(void)
{
    rt_kprintf("Hello RT-Thread!\n");

    return 0;
}

输出效果

  • LVGL 的 LOG 通过 RT-Thread 默认的 rt_kprintf 打印
相关推荐
张世争1 天前
RT-Thread qemu LVGL9.5 显示驱动更新 lv_port_disp.c
lcd·qemu·rt-thread·lvgl9.5
张世争1 天前
RT-Thread qemu LVGL9.5 鼠标 indev 驱动更新 lv_port_indev.c
qemu·rt-thread·indev·lvgl9.5
张世争3 天前
RT-Thread bsp qemu-vexpress-a9 编译环境
qemu·rt-thread·编译
daqinzl22 天前
银河麒麟V10下使用QEMU安装Windows虚拟机
qemu·windows 10·银河麒麟v10
春蕾夏荷_72829772522 天前
c++ easylogging 使用示例
c++·log·easylogging
YoungHong199223 天前
【Python进阶】告别繁琐Debug!Loguru一键输出异常日志与变量值
python·debug·异常处理·日志·loguru·log·logger
SXSBJS_XYT1 个月前
在资源有限的M0单片机上运行RTOS
单片机·rt-thread·rtos
ejinxian1 个月前
Linux 虚拟化技术 KVM/ESXI/Docker
linux·运维·docker·qemu·openvz
明早你自己说1 个月前
RT-Thread 在SD卡实现ulog+时间戳保存不同日志方法
stm32·rt-thread·ulog