Getting an event when an encoder is rotated

Description

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

STM32F769, ARM Embedded Toolchain

What LVGL version are you using?

LVGL 7.11

What do you want to achieve?

I want to get an event when the encoder is rotated with the encoder difference as data.Normally I use the built in handling of the encoder for selecting items in a group and editing. But for a special case I cant use the built in handling .I am receiving LV_EVENT_PRESSED when pressing the encoder but how can I get an event for the rotation? Is it even possible in LVGL?

What have you tried so far?

I added a container to the group of the encoder and focused it. I am receiving LV_EVENT_PRESSED when pressing the encoder but how can I get an event for the rotation?

Code to reproduce

Screenshot and/or video

in the function where you get the “LV_EVENT_PRESSED” event, you should also receive the “LV_EVENT_KEY” event. When you get the “LV_EVENT_KEY” event, you can do the following in the code

  if (event == LV_EVENT_KEY)
    {
      int* ev = (int*)lv_event_get_data();
      if(( *ev == LV_KEY_DOWN) || (*ev == LV_KEY_LEFT))
        {
          //encoder was rotated left or anticlockwise      
        }
        else if((*ev== LV_KEY_UP) || (*ev == LV_KEY_RIGHT))
        {
          //encoder was rotated right or clockwise
        } 
	}

One thing to note, when the encoder is turned, if it outputs say? 5 pulses. The event will be called once for every pulse. It will not be called once with the number of pulses that have occurred.

Hope this helps

1 Like

One thing I had to also do was to set lv_group_set_editing(encoder_group, true). I think this is because normally a container is not “editable” like other lv objects.

Hello. I have the same question but about 8 version. (just switched from 7)
lv_event_get_data no longer available. lv_indev_get_key works only for keypads.

Any news you’ve found regarding this problem in the meantime?