Value change event on dropdown with encoder indev in v7


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

Pc simulator, visual studio

What do you experience?

The LV_EVENT_VALUE_CHANGED is not happing on dropdown list when the driver is in encoder.
This was working perfect in V6 but now with V7 something goes wrong.

Code to reproduce

for the moment I modified the simulator a bit so I can use an encoder. So I started from the basic lv_ex_dropdow_1

static lv_indev_t * encoder_indev;
static lv_group_t* pxGroup;

static void event_handler(lv_obj_t* obj, lv_event_t event)
    if (event == LV_EVENT_VALUE_CHANGED) {
        char buf[32];
        lv_dropdown_get_selected_str(obj, buf, sizeof(buf));
        printf("Option: %s\n", buf);

void lv_ex_dropdown_custom(void)
    /*Create a normal drop down list*/
    lv_obj_t* ddlist = lv_dropdown_create(lv_scr_act(), NULL);
    lv_dropdown_set_options(ddlist, "Apple\n"

    lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
    lv_obj_set_event_cb(ddlist, event_handler);

    pxGroup = lv_group_create();
    lv_indev_set_group(encoder_indev, pxGroup);
    lv_group_add_obj(pxGroup, ddlist); 

I made this read encoder function, to use the arrows and enter buttons on the keyboard:

static bool prvReadEncoder(lv_indev_drv_t* indev_drv, lv_indev_data_t* data)
    lv_indev_data_t xKeyboardData;
    bool returnValue = keyboard_read(NULL, &xKeyboardData);

    if (returnValue)
        /* check if the button was pressed */
        if (xKeyboardData.key == LV_KEY_ENTER)
            data->state = LV_INDEV_STATE_PR;
        else if (xKeyboardData.key == LV_KEY_LEFT)
        else if (xKeyboardData.key == LV_KEY_RIGHT)
            data->enc_diff = 0;

    return returnValue;

made a small change to the keyboard read function:

bool keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
    (void) indev_drv;      /*Unused*/
    data->state = state;
    data->key = keycode_to_ascii(last_key);

    state = LV_INDEV_STATE_REL;
    return data->state == LV_INDEV_STATE_PR ? true : false;
    //return false;

and I register the encoder like this:

    lv_indev_drv_t encoder_drv;
    encoder_drv.type = LV_INDEV_TYPE_ENCODER;
    encoder_drv.read_cb = prvReadEncoder;
    encoder_indev= lv_indev_drv_register(&encoder_drv);

You almost never want to return true from an input device’s read_cb function. I’m not sure if that causes the issue or not but it’s something to try.

Thanks for the quick response.

Changing the read_cb to always false does not seem to fix the issue.

It was a bug in the library. I fixed it in master.

This solves the issue, thanks a lot!

V7 is great btw (:

Thans! :slight_smile: