LVGL 8 Keypad problem

Hi there
I am amir and very glad to meet LVGL awesome library.
I love it and thanks a lot for start and developing this project.
I migrate from LVGL 7 to LVGL 8 in Linux with fbdev implementation every thing ok but now want to add Keypad to my project and unfortunately didn’t successed.
the call back of keypad call periodically and the “data->key” fill correctly with the related key’s value.
but no changes appear in the group.

in main i use:
My Main indev call:

	lv_port_indev_init();
	KeypadGroup = lv_group_create();
	printf("the Indev keypad = %p \n", indev_keypad);
	lv_indev_set_group(indev_keypad, KeypadGroup);

My indev keypad read function:


static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
    static uint32_t last_key = 0;

    uint32_t act_key = keypad_get_key();
    if(act_key != 0) {
        data->state = LV_INDEV_STATE_PR;

        /* Translate the keys to LVGL control characters according to your key definitions*/
        switch (act_key) {
            //case 0x01: act_key = LV_KEY_ESC; break;
        case 0x01:
            printf("Hit Down \n");
            last_key = LV_KEY_DOWN;
            break; // Down
        //case 0x04: act_key = LV_KEY_Fn; break;   
        case 0x02:
            last_key = LV_KEY_NEXT;
            printf("Hit TAB \n");
            //LV_KEY_DEL;
            break;
            //case 0x10: act_key = LV_KEY_OPEN; break;
        case 0x04:
            printf("Hit Up \n");
            last_key = LV_KEY_UP; break; // Up
        //case 0x40: act_key = LV_KEY_CLOSE; break;
        case 0x08:
            printf("Hit Enter \n");
            last_key = LV_KEY_ENTER; break;
            //case 0x04: act_key = LV_KEY_LEFT; break;
            //case 0x08: act_key = LV_KEY_RIGHT; break;
        }

        last_key = 0;
    } else
    {
        data->state = LV_INDEV_STATE_REL;
    }

    data->key = last_key;  
}

Hi,

Happy to hear that you like LVGL :slight_smile:

Unless I’m messed up with the brackets you set last_key to a value in the switch, break from it and set last_key=0. So last_key will be always zero.

yes I am sorry I had changed the code more and more and remove some variables and did this mistake but still, I had a problem. data->key fill with correct value but any changes showes in the list or other keypad group elements with arrow keys.

static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
    static uint32_t last_key = 0;
    /*Get the current x and y coordinates*/
    //mouse_get_xy(&data->point.x, &data->point.y);
    /*Get whether the a key is pressed and save the pressed key*/
    uint32_t act_key = keypad_get_key();
    if(act_key != 0) {
        data->state = LV_INDEV_STATE_PR;

        /* Translate the keys to LVGL control characters according to your key definitions*/
        switch (act_key) {

        case 0x01: // Down
            printf("Hit Down \n");
            last_key = LV_KEY_DOWN;
            break; 
        case 0x02: // TAB
            last_key = LV_KEY_NEXT;
            printf("Hit TAB \n");
            break;
        case 0x04: // Up
            printf("Hit Up \n");
            last_key = LV_KEY_UP;
            break; 
        case 0x08: // Enter
            printf("Hit Enter \n");
            last_key = LV_KEY_ENTER;
            break;
        }
    }
    else
    {
        data->state = LV_INDEV_STATE_REL;
    }
    data->key = last_key;
    printf("Value of data->key = %d \r", data->key);
}

I cant solve this problem, could you please help me?

Please send the log of the printfs in your keypad_read.

The framebuffer device was opened successfully.
800x480, 16bpp
The framebuffer device was mapped to memory successfully.
[Info]  (0.011, +11)     lv_obj_create: begin   (in lv_obj.c line #188)
[Info]  (0.011, +0)      lv_obj_create: begin   (in lv_obj.c line #188)
[Info]  (0.011, +0)      lv_obj_create: begin   (in lv_obj.c line #188)
Indev Keypad = 0xdd5d98
the Indev keypad = 0xdd5d98
[Info]  (0.017, +6)      lv_obj_create: begin   (in lv_obj.c line #188)
[Info]  (0.020, +3)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.023, +3)      lv_obj_create: begin   (in lv_obj.c line #188)
[Info]  (0.024, +1)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.025, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.026, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.027, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.028, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.029, +1)      lv_list_create: begin  (in lv_list.c line #58)
[Info]  (0.030, +1)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.030, +0)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.032, +2)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.032, +0)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.032, +0)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.033, +1)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.033, +0)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.036, +3)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.036, +0)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.037, +1)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.038, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.038, +0)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.039, +1)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.040, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.044, +4)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.045, +1)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.045, +0)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.046, +1)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.047, +1)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.048, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.049, +1)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.050, +1)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.051, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.051, +0)      lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.055, +4)      lv_list_add_btn: begin         (in lv_list.c line #78)
[Info]  (0.056, +1)      lv_img_create: begin   (in lv_img.c line #59)
[Info]  (0.057, +1)      lv_label_create: begin         (in lv_label.c line #75)
[Info]of(0.059, +2)= 0   lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.060, +1)      flex_update: update 0xdd6388 container         (in lv_flex.c line #207)
[Info]  (0.064, +4)      flex_update: update 0xdd63c0 container         (in lv_flex.c line #207)
[Info]  (0.066, +2)      flex_update: update 0xdd67ac container         (in lv_flex.c line #207)
[Info]  (0.067, +1)      flex_update: update 0xdd67d4 container         (in lv_flex.c line #207)
[Info]  (0.068, +1)      flex_update: update 0xdd6bc0 container         (in lv_flex.c line #207)
[Info]  (0.070, +2)      flex_update: update 0xdd6dd0 container         (in lv_flex.c line #207)
[Info]  (0.072, +2)      flex_update: update 0xdd6fe4 container         (in lv_flex.c line #207)
[Info]  (0.075, +3)      flex_update: update 0xdd71f8 container         (in lv_flex.c line #207)
[Info]  (0.076, +1)      flex_update: update 0xdd7404 container         (in lv_flex.c line #207)
[Info]  (0.077, +1)      flex_update: update 0xdd62dc container         (in lv_flex.c line #207)
[Info]  (0.078, +1)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.079, +1)      flex_update: update 0xdd6388 container         (in lv_flex.c line #207)
[Info]  (0.085, +6)      flex_update: update 0xdd63c0 container         (in lv_flex.c line #207)
[Info]  (0.085, +0)      flex_update: update 0xdd67ac container         (in lv_flex.c line #207)
[Info]  (0.086, +1)      flex_update: update 0xdd67d4 container         (in lv_flex.c line #207)
[Info]  (0.087, +1)      flex_update: update 0xdd6bc0 container         (in lv_flex.c line #207)
[Info]  (0.088, +1)      flex_update: update 0xdd6dd0 container         (in lv_flex.c line #207)
[Info]  (0.089, +1)      flex_update: update 0xdd6fe4 container         (in lv_flex.c line #207)
[Info]  (0.089, +0)      flex_update: update 0xdd71f8 container         (in lv_flex.c line #207)
[Info]  (0.090, +1)      flex_update: update 0xdd7404 container         (in lv_flex.c line #207)
[Info]  (0.091, +1)      flex_update: update 0xdd62dc container         (in lv_flex.c line #207)
[Info]  (0.092, +1)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.093, +1)      flex_update: update 0xdd6388 container         (in lv_flex.c line #207)
[Info]  (0.093, +0)      flex_update: update 0xdd63c0 container         (in lv_flex.c line #207)
[Info]  (0.095, +2)      flex_update: update 0xdd67ac container         (in lv_flex.c line #207)
[Info]  (0.096, +1)      flex_update: update 0xdd67d4 container         (in lv_flex.c line #207)
[Info]  (0.096, +0)      flex_update: update 0xdd6bc0 container         (in lv_flex.c line #207)
[Info]  (0.097, +1)      flex_update: update 0xdd6dd0 container         (in lv_flex.c line #207)
[Info]  (0.097, +0)      flex_update: update 0xdd6fe4 container         (in lv_flex.c line #207)
[Info]  (0.101, +4)      flex_update: update 0xdd71f8 container         (in lv_flex.c line #207)
[Info]  (0.101, +0)      flex_update: update 0xdd7404 container         (in lv_flex.c line #207)
[Info]  (0.102, +1)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.102, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.125, +23)     lv_label_create: begin         (in lv_label.c line #75)
[Info]  (0.129, +4)      lv_label_create: begin         (in lv_label.c line #75)
[Info]of(0.172, +43) 0   lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.172, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(0.377, +205)0   lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.377, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Down data->key = 0
[Info]of(0.584, +207)18  indev_keypad_proc: 18 key is pressed   (in lv_indev.c line #406)
Hit Down
Hit Down data->key = 18
Hit Down data->key = 18
[Info]of(0.707, +123)18  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (0.708, +1)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Down
Hit Down data->key = 18
Hit Down data->key = 18
Hit Down data->key = 18
Hit Down data->key = 18
Hit Down data->key = 18
Hit Down data->key = 18
[Info]of(1.042, +334)18  indev_keypad_proc: 18 key is released  (in lv_indev.c line #490)
[Info]  (1.042, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(1.371, +329)18  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (1.371, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Enter ata->key = 18
[Info]of(1.460, +89) 10  indev_keypad_proc: 10 key is pressed   (in lv_indev.c line #406)
Hit Enter
Hit Enter ata->key = 10
Hit Enter ata->key = 10
Hit Enter ata->key = 10
Hit Enter ata->key = 10
Hit Enter ata->key = 10
[Info]of(1.708, +248)10  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Enter
Hit Enter ata->key = 10
Hit Enter ata->key = 10
Hit Enter ata->key = 10
Hit Enter ata->key = 10
Hit Enter ata->key = 10
[Info]of(1.997, +289)10  indev_keypad_proc: 10 key is released  (in lv_indev.c line #490)
[Info]of(2.038, +41) 10  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(2.368, +330)10  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(2.698, +330)10  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Up f data->key = 10
[Info]of(2.784, +86) 17  indev_keypad_proc: 17 key is pressed   (in lv_indev.c line #406)
Hit Up
Hit Up f data->key = 17
Hit Up f data->key = 17
Hit Up f data->key = 17
Hit Up f data->key = 17
Hit Up f data->key = 17
[Info]of(3.030, +246)17  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Up
Hit Up f data->key = 17
Hit Up f data->key = 17
[Info]of(3.201, +171)17  indev_keypad_proc: 17 key is released  (in lv_indev.c line #490)
[Info]of(3.365, +164)17  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (3.365, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(3.695, +330)17  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(4.031, +336)17  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (4.038, +7)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(4.329, +291)17  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (4.329, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Down data->key = 17
[Info]of(4.621, +292)18  indev_keypad_proc: 18 key is pressed   (in lv_indev.c line #406)
Hit Down
[Info]of(4.662, +41) 18  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit Down
[Info]of(4.747, +85) 18  indev_keypad_proc: 18 key is released  (in lv_indev.c line #490)
[Info]of(4.993, +246)18  lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]  (4.993, +0)      lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit TAB  data->key = 18
[Info]of(5.199, +206)9   indev_keypad_proc: 9 key is pressed    (in lv_indev.c line #406)
Hit TAB
Hit TAB  data->key = 9
Hit TAB  data->key = 9
[Info]of(5.322, +123)9   lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
Hit TAB
Hit TAB  data->key = 9
[Info]of(5.452, +130)9   indev_keypad_proc: 9 key is released   (in lv_indev.c line #490)
[Info]of(5.656, +204)9   lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(5.984, +328)9   lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)
[Info]of(6.313, +329)9   lv_obj_update_layout: Layout update begin      (in lv_obj_pos.c line #302)

the printfs are ok i can see the value of
LV_KEY_ENTER
LV_KEY_UP
LV_KEY_NEXT
LV_KEY_DOWN
but i think in the 8 version of lvgl I should set a flag in the lv_conf file or something like this to using keypad group!?.

My main indev init:

	lv_port_indev_init();
	KeypadGroup = lv_group_create();
	printf("the Indev keypad = %p \n", indev_keypad);
	lv_indev_set_group(indev_keypad, KeypadGroup);

using group:

	lv_group_add_obj(KeypadGroup, MenuList);
	lv_group_focus_obj(MenuList);

I check with message box and simple widgets but they don’t works too.

I have no idea :frowning:

Form the log is seems LVGL recognizes the keys.

But there something strange in lines like these:

[Info]of(0.584, +207)18  indev_keypad_proc: 18 key is pressed   (in lv_indev.c line #406)

What is the of after [Info]? And 18 after +207)?

thanks for the reply,
“of” and “18” are the output of myself printf in the end of keypad_read proc from this
printf(“Value of data->key = %d \r”, data->key);
not “\n” and there is no problem.
I think everything is ok but i can’t use group indev like v7 ?!
is any flag or setting added to v8 ? to active the grope or using the keypad?

i found the problem…
after group create we should call

lv_group_set_default(KeypadGroup);

the problem is solved.

I used some keypad features but the functionality of keypad was changed.
I can’t use the tab to switch between elements and when I create new widgets I cant use the keypad for control it? in new widget the old handlar function called.

It just automatically adds the widgets to the given group.

Please send a short code snippet t o see how you:

  • add the group to the keypad
  • create 2 buttons
  • add them to the group

my problem is solved.