Hardware buttons, tabview and list

Hi,

I have recently started working on LVGL for my 128*64 monochrome LCD with nxp processor.

Currently, I’m trying to create MENU screen which contains three tabs and each tab has it’s own list of options with external buttons for navigation.

I’m facing few issues to do the same.

  1. Each tab has own list with no of options but LCD screen is getting crashed if I give more than two options (LCD can display 2 options at a time). I have done same on the simulator but there screen is not getting crashed.
  2. My hardware has keypad with 7 buttons and I’m trying to use these buttons to navigate tabs and list options but that is not working.

Below is the my code

void menuTab()
{
scrn = lv_obj_create(NULL, NULL);

static lv_style_t style;

lv_style_init(&style);
lv_style_set_text_font(&style, LV_STATE_DEFAULT, LV_THEME_DEFAULT_FONT_SMALL);
lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_text_color(&style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLACK);

static lv_style_t style8;
lv_style_init(&style8)

tabv = lv_tabview_create(scrn, NULL);

// lv_group_add_obj(g, tabv); //LCD Crash

lv_obj_t * title = lv_label_create(tabv, NULL);
lv_label_set_long_mode(title, LV_LABEL_LONG_BREAK);

lv_obj_add_style(title, LV_LABEL_PART_MAIN, &style);
lv_label_set_text(title, "MENU");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_set_pos(title, 0, 0);
lv_obj_set_size(title, LV_HOR_RES_MAX, 0);

t1 = lv_tabview_add_tab(tabv, "Vehicle");
t2 = lv_tabview_add_tab(tabv, "Remote");
t3 = lv_tabview_add_tab(tabv, "Info");

lv_obj_t * list1 = lv_list_create(t1, NULL);
lv_obj_set_size(list1, 128, 40);
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 10);

/*Add buttons to the list*/
lv_obj_t * list_btn;
lv_obj_t *label, *label2;

list_btn = lv_list_add_btn(list1, NULL, NULL);
label = lv_label_create(list_btn, NULL);
label2 = lv_label_create(list_btn, NULL);

lv_label_set_text(label, "LCD Contrast");
lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
lv_label_set_align(label, LV_LABEL_ALIGN_LEFT);
lv_obj_set_size(label, 96, 0);


lv_label_set_text(label2, "1234");
lv_label_set_long_mode(label2, LV_LABEL_LONG_BREAK);
lv_label_set_align(label2, LV_LABEL_ALIGN_RIGHT);
lv_obj_set_size(label2, 20, 0);

lv_obj_set_event_cb(list_btn, event_handler);

list_btn = lv_list_add_btn(list1, NULL, NULL);
label = lv_label_create(list_btn, NULL);
label2 = lv_label_create(list_btn, NULL);

lv_label_set_text(label, "LCD Backlight");
lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
lv_label_set_align(label, LV_LABEL_ALIGN_LEFT);
lv_obj_set_size(label, 96, 0);


lv_label_set_text(label2, "2345");
lv_label_set_long_mode(label2, LV_LABEL_LONG_BREAK);
lv_label_set_align(label2, LV_LABEL_ALIGN_RIGHT);
lv_obj_set_size(label2, 20, 0);

lv_obj_set_event_cb(list_btn, event_handler);

#if 0
list_btn = lv_list_add_btn(list1, NULL, NULL);
label = lv_label_create(list_btn, NULL);
label2 = lv_label_create(list_btn, NULL);

lv_label_set_text(label, "InactivePause");
lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
lv_label_set_align(label, LV_LABEL_ALIGN_LEFT);
lv_obj_set_size(label, 96, 0);


lv_label_set_text(label2, "2345");
lv_label_set_long_mode(label2, LV_LABEL_LONG_BREAK);
lv_label_set_align(label2, LV_LABEL_ALIGN_RIGHT);
lv_obj_set_size(label2, 20, 0);
lv_obj_set_event_cb(list_btn, event_handler);

list_btn = lv_list_add_btn(list1, NULL, NULL);
label = lv_label_create(list_btn, NULL);
label2 = lv_label_create(list_btn, NULL);

lv_label_set_text(label, "AutoOffEnable");
lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
lv_label_set_align(label, LV_LABEL_ALIGN_LEFT);
lv_obj_set_size(label, 96, 0);


lv_label_set_text(label2, "1234");
lv_label_set_long_mode(label2, LV_LABEL_LONG_BREAK);
lv_label_set_align(label2, LV_LABEL_ALIGN_RIGHT);
lv_obj_set_size(label2, 20, 0);
lv_obj_set_event_cb(list_btn, event_handler);

#endif
}

static bool buttons_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
if(buttons.state_down == true)
{
buttons.state_down = false;
data->key = LV_KEY_DOWN;
data->state = LV_INDEV_STATE_PR;
printDebug(“DOWN button \r\n”);
}
else
{
data->key = LV_KEY_DOWN;
data->state = LV_INDEV_STATE_REL;
}

if(buttons.state_up == true)
{
    buttons.state_up = false;
    data->key   = LV_KEY_UP;
    data->state = LV_INDEV_STATE_PR;
    printDebug("UP button \r\n");
}
else
{
    data->key   = LV_KEY_UP;
    data->state = LV_INDEV_STATE_REL;
}

if(buttons.state_left == true)
{
    buttons.state_left = false;
    data->key   = LV_KEY_LEFT;
    data->state = LV_INDEV_STATE_PR;
    printDebug("LEFT button \r\n");
}
else
{
    data->key   = LV_KEY_LEFT;
    data->state = LV_INDEV_STATE_REL;
}

if(buttons.state_right == true)
{
    buttons.state_right = false;
    data->key   = LV_KEY_RIGHT;
    data->state = LV_INDEV_STATE_PR;
    printDebug("RIGHT button \r\n");
}
else
{
    data->key   = LV_KEY_RIGHT;
    data->state = LV_INDEV_STATE_REL;
}

if(buttons.state_enter == true)
{
    buttons.state_enter = false;
    data->key   = LV_KEY_ENTER;
    data->state = LV_INDEV_STATE_PR;
    printDebug("ENTER button \r\n");
}
else
{
    data->key   = LV_KEY_ENTER;
    data->state = LV_INDEV_STATE_REL;
}

return false;

}

void lv_demo_keypad()
{
g = lv_group_create();

lv_indev_drv_t  kp_drv;
lv_indev_drv_init(&kp_drv);
kp_drv.type = LV_INDEV_TYPE_KEYPAD;
kp_drv.read_cb = buttons_read;
lv_indev_t* emulated_kp_indev = lv_indev_drv_register(&kp_drv);

lv_indev_set_group(emulated_kp_indev, g);

}

Below is the lvgl initialization

{
/Create a display buffer/
static lv_disp_buf_t disp_buf;
static lv_color_t buf1_1[LV_HOR_RES_MAX * 10];
lv_disp_buf_init(&disp_buf, buf1_1, NULL, LV_HOR_RES_MAX * 10);

/*Create a display*/
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = displayFlush;
lv_disp_drv_register(&disp_drv);

lv_demo_keypad();

menuTab();
lv_scr_load(scrn);

}


I’m able to see prints from buttons_read() when I press buttons but no action/navigation on screen.

Could anyone help me with above issues?

Thanks…