I’m just beginning to wrap my head around LVGL. I have a EleCrow 7” with the ESP32.
I’ve successfully added a button, compiles fine, uploads, and works on the display. My issue is now adding an event callback to it always compiles with my callback not being declared in this scope. I’m at a loss. My callback is there. I’m running release 8 of the LGVL library. I know there is newer but it wreaks havic with other code that will need updating and I’m beating my head against the wall already without going down that path too at the moment.
/***************************/
/* Build the GIU unterface */
/***************************/
lv_obj_t *ui_GUI;
lv_obj_t *ui_Label2;
lv_obj_t *ui_btn_control;
lv_obj_t *ui_control_label;
lv_obj_t *ui_btn_cab_select;
lv_obj_t *ui_btn_full_stop;
lv_obj_t *ui_btn_headlight_toggle;
lv_obj_t *ui_btn_play_sound;
lv_obj_t *ui_slider_throttle;
/***********************************/
/* Respond to Control button event */
/***********************************/
static void control_cb(lv_event_t * e){
Serial.println("A1");
}
/************************************/
/* Build the GIU interface controls */
/************************************/
void ui_init() {
lv_disp_t *dispp = lv_disp_get_default();
lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), true, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
ui_GUI = lv_obj_create(NULL); // Create a screen object
lv_obj_clear_flag(ui_GUI, LV_OBJ_FLAG_SCROLLABLE);
//ui_Label2 = lv_label_create(ui_Inicio); // Create a label
//lv_obj_set_align(ui_Label2, LV_ALIGN_CENTER); // Align the label at the center
//lv_label_set_text(ui_Label2, "Hello :D"); // Set label text
//lv_obj_set_style_text_font(ui_Label2, &lv_font_montserrat_36, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_btn_control = lv_btn_create(ui_GUI); // Button to toggle control on/off
lv_obj_set_pos(ui_btn_control,20,20);
lv_obj_set_size(ui_btn_control, 100, 50); // Width: 100px, Height: 50px
lv_obj_add_event_cb(ui_btn_control, control_cb, LV_EVENT_ALL, NULL);
ui_control_label = lv_label_create(ui_btn_control);
lv_label_set_text(ui_control_label, "Control");
lv_disp_load_scr(ui_GUI); // Load the screen into the display
}