您尚未登录。

楼主 # 2022-12-06 16:36:47

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

LVGL 学习记录

    static lv_indev_drv_t pointer_driver;
    lv_indev_drv_init(&pointer_driver);
    pointer_driver.type = LV_INDEV_TYPE_POINTER;
    pointer_driver.read_cb = lv_win32_pointer_driver_read_callback;
    pointer_driver.feedback_cb = btn_feedback_event_cb;
    lv_win32_pointer_device_object = lv_indev_drv_register(&pointer_driver);
void btn_feedback_event_cb(lv_indev_drv_t* indev_drv, lv_event_code_t event)
{
    printf("btn_feedback_event_cb\n");
    switch (event)
    {
    case LV_EVENT_PRESSED:
        printf("Pressed\n");
        break;

    case LV_EVENT_SHORT_CLICKED:
        printf("Short clicked\n");
        break;

    case LV_EVENT_CLICKED:
        printf("Clicked\n");
        break;

    case LV_EVENT_LONG_PRESSED:
        printf("Long press\n");
        break;

    case LV_EVENT_LONG_PRESSED_REPEAT:
        printf("Long press repeat\n");
        break;

    case LV_EVENT_RELEASED:
        printf("Released\n");
        break;

    default:
        printf("nothing\n");
        break;
    }
}

最近编辑记录 ubuntu (2022-12-07 10:50:43)

离线

楼主 #1 2022-12-06 17:01:11

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

短按触发事件顺序:
Pressed
Released
Short clicked
Clicked

长按触发事件顺序:
Pressed
Long press
Long press repeat
Long press repeat
Long press repeat
Long press repeat
Long press repeat
Long press repeat
Long press repeat
Long press repeat
Long press repeat
Released
Clicked

离线

楼主 #2 2022-12-07 10:32:00

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

_20221207103108.png

_20221207104955.png

全志SDK里面V853 lvgl项目的适配.

最近编辑记录 ubuntu (2022-12-07 10:50:32)

离线

楼主 #3 2022-12-10 12:22:48

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

lv_obj_t* led1 = lv_led_create(lv_scr_act());

茴的三种写法,三种居中方法:

    lv_obj_set_align(led1, LV_ALIGN_CENTER);
    lv_obj_center(led1);
    lv_obj_align(led1, LV_ALIGN_CENTER, 0, 0);

离线

楼主 #4 2022-12-10 19:02:18

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

lv_obj_t* slider1;
lv_obj_t *label1, *label2;

void slider_event_cb(lv_event_t* e)
{
    int32_t value = lv_slider_get_value(slider1);
    char valueStr[32];

    value = lv_slider_get_left_value(slider1);
    snprintf(valueStr, sizeof(valueStr), "%d", value);
    lv_label_set_text(label1, (valueStr));

    value = lv_slider_get_value(slider1);
    snprintf(valueStr, sizeof(valueStr), "%d", value);
    lv_label_set_text(label2, (valueStr));
}

void lv_demo_test2()
{
    slider1 = lv_slider_create(lv_scr_act());

    lv_obj_center(slider1);
    
    lv_slider_set_range(slider1, -255, 255);
    lv_slider_set_mode(slider1, LV_SLIDER_MODE_RANGE);
    lv_obj_add_event_cb(slider1, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    label1 = lv_label_create(lv_scr_act());
    label2 = lv_label_create(lv_scr_act());
    lv_obj_align_to(label1, slider1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
    lv_obj_align_to(label2, slider1, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 10);

}

_20221210190159.png

离线

楼主 #5 2022-12-10 19:20:10

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

lv_obj_t* slider1;
lv_obj_t *label1, *label2;

void button_event_cb(lv_event_t* e)
{
    lv_slider_set_value(slider1, 100, LV_ANIM_OFF);
}

void slider_event_cb(lv_event_t* e)
{
    int32_t value = lv_slider_get_value(slider1);
    char valueStr[32];

    value = lv_slider_get_left_value(slider1);
    snprintf(valueStr, sizeof(valueStr), "%d", value);
    lv_label_set_text(label1, (valueStr));

    value = lv_slider_get_value(slider1);
    snprintf(valueStr, sizeof(valueStr), "%d", value);
    lv_label_set_text(label2, (valueStr));
}

void lv_demo_test2()
{
    slider1 = lv_slider_create(lv_scr_act());

    lv_obj_center(slider1);
    
    lv_slider_set_range(slider1, -255, 255);
    lv_slider_set_mode(slider1, LV_SLIDER_MODE_RANGE);
    lv_obj_add_event_cb(slider1, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    label1 = lv_label_create(lv_scr_act());
    label2 = lv_label_create(lv_scr_act());
    lv_obj_align_to(label1, slider1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
    lv_obj_align_to(label2, slider1, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 10);

    lv_slider_set_left_value(slider1, -100, LV_ANIM_OFF);
    lv_slider_set_value(slider1, 100, LV_ANIM_OFF);
    lv_obj_set_size(slider1, 20, 200);

    lv_obj_t* button1 = lv_btn_create(lv_scr_act());
    lv_obj_t* label3 = lv_label_create(button1);
    lv_label_set_text(label3, "Test");
    lv_obj_add_event_cb(button1, button_event_cb, LV_EVENT_CLICKED, NULL);
    lv_obj_align_to(button1, slider1, LV_ALIGN_OUT_BOTTOM_MID, 0, 30);
}

_20221210191949.png

离线

楼主 #6 2022-12-22 20:44:02

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

LVGL + FFMPEG

离线

楼主 #7 2022-12-23 19:35:37

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

QQ截图20221223193308.png



    else if(code == LV_EVENT_PRESSED) {
        colorwheel->last_change_time = lv_tick_get();
        lv_indev_get_point(lv_indev_get_act(), &colorwheel->last_press_point);
        res = double_click_reset(obj);
        if(res != LV_RES_OK) return;
    }
    else if(code == LV_EVENT_PRESSING) {
        lv_indev_t * indev = lv_indev_get_act();
        if(indev == NULL) return;

        lv_indev_type_t indev_type = lv_indev_get_type(indev);
        lv_point_t p;
        if(indev_type == LV_INDEV_TYPE_ENCODER || indev_type == LV_INDEV_TYPE_KEYPAD) {
            p.x = obj->coords.x1 + lv_obj_get_width(obj) / 2;
            p.y = obj->coords.y1 + lv_obj_get_height(obj) / 2;
        }
        else {
            lv_indev_get_point(indev, &p);
        }

        lv_coord_t drag_limit = indev->driver->scroll_limit;
        if((LV_ABS(p.x - colorwheel->last_press_point.x) > drag_limit) ||
           (LV_ABS(p.y - colorwheel->last_press_point.y) > drag_limit)) {
            colorwheel->last_change_time = lv_tick_get();
            colorwheel->last_press_point.x = p.x;
            colorwheel->last_press_point.y = p.y;
        }

        p.x -= obj->coords.x1;
        p.y -= obj->coords.y1;

        /*Ignore pressing in the inner area*/
        uint16_t w = lv_obj_get_width(obj);

        int16_t angle = 0;
        lv_coord_t cir_w = lv_obj_get_style_arc_width(obj, LV_PART_MAIN);

LVGL双击实现 double click

最近编辑记录 ubuntu (2022-12-23 19:35:49)

离线

楼主 #8 2023-05-04 13:42:59

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

static void drag_event_handler(lv_event_t * e)
{
    lv_obj_t * obj = lv_event_get_target(e);

    lv_indev_t * indev = lv_indev_get_act();
    lv_point_t vect;
    lv_indev_get_vect(indev, &vect);

    lv_coord_t x = lv_obj_get_x(obj) + vect.x;
    lv_coord_t y = lv_obj_get_y(obj) + vect.y;
    lv_obj_set_pos(obj, x, y);
}


/**
 * Make an object dragable.
 */
void lv_example_obj_2(void)
{
    lv_obj_t * obj;
    obj = lv_obj_create(lv_scr_act());
    lv_obj_set_size(obj, 150, 100);
    lv_obj_add_event_cb(obj, drag_event_handler, LV_EVENT_PRESSING, NULL);

    lv_obj_t * label = lv_label_create(obj);
    lv_label_set_text(label, "Drag me");
    lv_obj_center(label);

}

拖拽屏幕上面的控件

离线

楼主 #9 2023-05-04 17:21:27

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

void my_event(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    static uint32_t t;
    if(code == LV_EVENT_PRESSED) {
        t = lv_tick_get();
    } 
    else if(code == LV_EVENT_PRESSING) {
        if(lv_tick_elaps(t) > 3000) {
            /*Do something*/
        }
    }
}

离线

楼主 #10 2023-05-04 23:12:44

ubuntu
会员
注册时间: 2020-03-30
已发帖子: 276
积分: 254

Re: LVGL 学习记录

#include "lvgl/lvgl.h"

#define DOUBLE_CLICK_TIME_MS 300 // 双击事件的最大时间间隔(毫秒)

static uint32_t last_click_time = 0;

static void btn_event_cb(lv_obj_t * obj, lv_event_t event)
{
    if (event == LV_EVENT_SHORT_CLICKED) {
        uint32_t now = lv_tick_get();

        if ((now - last_click_time) < DOUBLE_CLICK_TIME_MS) {
            printf("Double click!\n");
            last_click_time = 0;
        }
        else {
            printf("Single click.\n");
            last_click_time = now;
        }
    }
}

int main(void)
{
    lv_init();

    // 创建一个按钮控件
    lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);

    // 设置按钮的单击事件回调函数
    lv_obj_set_event_cb(btn, btn_event_cb);

    while(1) {
        lv_task_handler(); // 处理 LVGL 任务
    }

    return 0;
}
在上面的示例中,当按钮被单击时,btn_event_cb() 回调函数会被触发,并检查两次事件之间的时间间隔。如果小于固定时间间隔,则输出 "Double click!",否则输出 "Single click."。

请注意,本示例代码使用了 lv_tick_get() 函数来获取当前系统时间,该函数需要您配置并启用 LVGL 的计时器(在 lv_conf.h 中进行配置)。另外,您可以通过修改 DOUBLE_CLICK_TIME_MS 宏来自定义双击事件的时间间隔。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn