niepangu
2021-08-19 11:04
采纳率: 75%
浏览 760

LVGL 无法 同时使用触摸屏和物理按键,求解

使用LVGL 在IMX6ULL上做界面,刚开始不久,之前一直使用触摸屏操作,昨天下加入物理按键的支持,但是加入物理按键后按键能用,但发现触摸屏不能用了,求解?
代码中有在屏幕上显示2个Button,目前触摸屏操作这两个Button,不会触发事件
代码如下:
int main(void)
{
/LittlevGL init/
lv_init();

/*Linux frame buffer device init*/
fbdev_init();

/*A small buffer for LittlevGL to draw the screen's content*/
static lv_color_t buf[DISP_BUF_SIZE];

/*Initialize a descriptor for the buffer*/
static lv_disp_draw_buf_t disp_buf;
lv_disp_draw_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);

/*Initialize and register a display driver*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf   = &disp_buf;
disp_drv.flush_cb   = fbdev_flush;
disp_drv.hor_res    = 800;
disp_drv.ver_res    = 480;
disp_drv.sw_rotate  = 1;
disp_drv.rotated    = LV_DISP_ROT_NONE;
disp_drv.antialiasing = 1;

lv_disp_t * disp  = lv_disp_drv_register(&disp_drv);
lv_theme_t * th = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
lv_disp_set_theme(disp, th);

lv_group_t * group = lv_group_create();
lv_group_set_default(group);

/* Linux input device init */
evdev_init();

/* Initialize and register a display input driver */
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);      /*Basic initialization*/

indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = evdev_read;   //lv_gesture_dir_t lv_indev_get_gesture_dir(const lv_indev_t * indev)
lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);

keyboard_init();
static lv_indev_drv_t indev_drv_btn;
lv_indev_drv_init(&indev_drv_btn);
indev_drv_btn.type = LV_INDEV_TYPE_BUTTON;
indev_drv_btn.read_cb = keypad_read;
lv_indev_t *indev_keypad = lv_indev_drv_register(&indev_drv_btn);
lv_indev_set_group(indev_keypad, group);
    /*Assign buttons to points on the screen*/
static const lv_point_t btn_points[2] = {
        {0, 0},   /*Button 0 -> x:10; y:10*/
        {50, 50},  /*Button 1 -> x:40; y:100*/
};
lv_indev_set_button_points(indev_keypad, btn_points);


lv_obj_t *scr = lv_scr_act();
lv_obj_t *btn1 = lv_btn_create(scr);
lv_obj_set_size(btn1,100,100);    
lv_obj_set_pos(btn1,0,0);
lv_obj_add_event_cb(btn1, event_callback,LV_EVENT_CLICKED, NULL);

lv_obj_t *btn2 = lv_btn_create(scr);
lv_obj_set_size(btn2,100,100);
lv_obj_set_pos(btn2,100,100);
   lv_obj_add_event_cb(btn2, event_callback,LV_EVENT_CLICKED, NULL);

   lv_group_add_obj(group ,btn1);
lv_group_add_obj(group ,btn2);

lv_group_set_editing(group,true);

/*Handle LitlevGL tasks (tickless mode)*/
while(1) {
    lv_task_handler();
    usleep(5000);
}

return 0;

}

1条回答 默认 最新

相关推荐 更多相似问题