Get swipe direction

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation. We will not respond in detail to posts where you haven’t read the relevant documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

how to get swipe direction

What MCU/Processor/Board and compiler are you using?

simulator

What LVGL version are you using?

7.4.0

What do you want to achieve?

get swipe direction when drag on touch panel

What have you tried so far?

i tried print event in tileview callback function.

event: 8 
event: 16
event: 9 
event: 10
event: 8 
event: 16
event: 9 
event: 10
event: 8 
event: 16
event: 9 
event: 10
event: 8 
event: 16
event: 9 
event: 10
event: 8 
event: 16
event: 9 
event: 10

it’s mean,
LV_EVENT_DRAG_BEGIN
LV_EVENT_VALUE_CHANGED
LV_EVENT_DRAG_END
LV_EVENT_DRAG_THROW_BEGIN
i cannot get direction of swipe.

please help.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Hi @nguyennamdsn ,

I think this post will help you achieve your goal.

Kind Regards,

Pete

thank you.
i tried it before start this post. but no LV_EVENT_GESTURE event.
only
LV_EVENT_DRAG_BEGIN
LV_EVENT_VALUE_CHANGED
LV_EVENT_DRAG_END
LV_EVENT_DRAG_THROW_BEGIN
occur when swipe.
i try with bellow code and can get the direction.
____if (event == LV_EVENT_DRAG_BEGIN) {
________lv_indev_t * indev = lv_indev_get_act();
________if (indev != NULL){
____________if (indev->proc.types.pointer.drag_dir == LV_DRAG_DIR_HOR) {
________________if (indev->proc.types.pointer.vect.x > 0) {
____________________print_log(“Left to right\n”);
________________}else if (indev->proc.types.pointer.vect.x < 0) {
____________________print_log(“Right to left\n”);
________________}
____________}else if (indev->proc.types.pointer.drag_dir == LV_DRAG_DIR_VER) {
________________if (indev->proc.types.pointer.vect.y > 0) {
____________________print_log(“Up to down\n”);
________________}
________________else if (indev->proc.types.pointer.vect.y < 0) {
____________________print_log(“Down to up\n”);
________________}
____________}
________}
____}
but i don’t known is this right manner.

and once more question. how do i get coordinate of start drag and stop drag ?

Hi @nguyennamdsn ,

Are you definitely assigning the event handler to lv_scr_act()?

Can you confirm that this simple example works in the simulator for you:

void scr_event_cb(lv_obj_t * obj, lv_event_t e)
{
    if(e == LV_EVENT_GESTURE) {
        lv_gesture_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
        printf("Dir: %d\n\r", dir);
        fflush(stdout);
    }
}


int main(int argc, char **argv)
{
  (void)argc; /*Unused*/
  (void)argv; /*Unused*/

  /*Initialize LVGL*/
  lv_init();

  /*Initialize the HAL (display, input devices, tick) for LVGL*/
  hal_init();

//  lv_demo_widgets();
//  lv_demo_printer();

  lv_obj_set_event_cb(lv_scr_act(), scr_event_cb);

  while (1) {
    /* Periodically call the lv_task handler.
     * It could be done in a timer interrupt or an OS task too.*/
    lv_task_handler();
    usleep(5 * 1000);
  }

  return 0;
}

The output I get from the console for the above code is:

Dir: 3
Dir: 2
Dir: 0
Dir: 1
Dir: 2
used: 5080 ( 8 %), frag: 2 %, biggest free: 59288
Dir: 3
Dir: 0
Dir: 1
Dir: 0
Dir: 1
used: 5072 ( 8 %), frag: 1 %, biggest free: 60448
Dir: 0
Dir: 1
Dir: 3
Dir: 2

as I click and swipe in various directions with the mouse cursor.

Kind Regards,

Pete

The gesture event wasn’t sent before v7.4 if the objects were dragged. However, it was changed in v7.4. See the changelog.

Are you sure you are using the v7.4?

In earlier versions this line prevented sending gesture while dragging. You can check if it’s there for you.