I have implemented LVGL on a Raspberry Pi 3B+ using the latest master from the Linux framebuffer repository and also 8.3. The Pi has an HDMI touchscreen attached. I added a cursor to the touch screen and it works fine. However, when a scrollable list is displayed (from the demos) scrolling does not work properly. I can drag the lines a little bit then they pop back to their more-or-less original position. The code below is the read callback.
I can’t find any information as to exactly what I should be returning as far as state. As I said, dragging a cursor around the screen works just fine.
indev_touchpad = lv_indev_create();
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
lv_indev_set_display(indev_touchpad, disp);
lv_indev_set_read_cb(indev_touchpad, touchscreen_read);
lv_obj_t *cursor_img = lv_img_create(lv_scr_act());
lv_img_set_src(cursor_img, LV_SYMBOL_PLUS);
lv_indev_set_cursor(indev_touchpad, cursor_img);
void touchscreen_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
{
static int32_t last_x = 0;
static int32_t last_y = 0;
static int xpos = -1;
static int ypos = -1;
data->state = LV_INDEV_STATE_RELEASED;
bool inPacket = false;
do
{
while(libevdev_has_event_pending(dev))
{
//printf("Pending...\r\n");
inPacket = true;
struct input_event ev;
read_event(dev, &ev);
//printf("Type: %d (%s)\r\n", ev.type, eventType(ev.type));
if(ev.type == EV_MSC)
{
//printf(" Code: %02x (%s)\r\n", ev.code, codeMsc(ev.code));
//printf(" Value: %d\r\n", ev.value);
}
else if (ev.type != 0)
{
//printf(" Code: %02X (%s)\r\n", ev.code, codeType(ev.code));
//printf(" Value: %d\r\n", ev.value);
switch( ev.code )
{
case ABS_MT_POSITION_X:
xpos = ev.value;
break;
case ABS_MT_POSITION_Y:
ypos = ev.value;
break;
case BTN_TOUCH:
touchscreen_pressed = ev.value;
break;
}
}
if (ev.type == SYN_REPORT)
{
if (touchscreen_pressed > 0 )
{
data->state = LV_INDEV_STATE_PRESSED;
if (xpos >= 0 )
last_x = xpos;
if (ypos >= 0 )
last_y = 599 - ypos;
xpos = -1;
ypos = -1;
inPacket = false;
}
//printf("REPORT: %d %d %d\n", last_x, last_y, touchscreen_pressed);
//printf("\r\n");
}
}
} while (inPacket);
data->point.x = last_x;
data->point.y = 599 - last_y;
//printf("Read: %d %d\n", last_x, last_y);
}