Implementing LVGL

Hi, I am relatively new to LVGL and it would be great if anyone could provide a clear guide on how to setup the libraries to access the LVGL functions? I tried compiling a simple code for a button with label but it said that there were some errors. I included the library: “display/lvgl.h” and I was wondering whether I was doing the right thing?

1 Like

Docs Here

The first step to getting started with LVGL is to include pros/apix.h in your main.h file or other header files.

Custom LVGL code cannot be displayed at the same time as the LLEMU. As a result, you must remove the LLEMU code ( pros::lcd ) that is present in main.cpp by default in a new project.

2 Likes

I included pros/apix.h in my main.h file, but the last line still includes an error:

lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);         
lv_obj_set_pos(btn1, 10, 10);                                    
lv_obj_set_event_cb(btn1, btn_event_cb);

The error says: use of undeclared identifier ‘btn_event_cb’

Did I not include all the correct libraries or is something wrong with this piece of code?

if you share your main.cpp file I may be able to help but with just that line it’s kind of hard. It seems you don’t have a btn action function declared in that scope.

Sorry, I am relatively new to LVGL, so can you elaborate on what is a “btn action function” ?

spend a few hours with the LVGL documentation. (look for the docs on version 5.3 which I think PROS is using).

Things like “btn_event_cb” you have to provide in your code.

6 Likes

You can find LVGL version 5.3 docs here

1 Like

btn_event_cb needs to be defined
An example of this is
static lv_res_t btn_event_cb(lv_obj_t * btn){
//code here
return LV_RES_OK; //don't delete object
}

I ran this piece of code:

static void btn_event_cb(lv_obj_t * obj, lv_event_t event) {
  if(event == LV_RES_OK) {
    printf("clicked\n");
  }
}

void initialize() {
  lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
  lv_obj_set_pos(btn, 10, 10);
  lv_obj_set_event_cb(btn, btn_event_cb);

  lv_obj_t * label = lv_label_create(btn, NULL);
  lv_label_set_text(label, "Button");
}

but when I compiled it there was a error that said: "unknown type name lv_event_t

can anyone explain why there is this error?

Don’t know where you got the lv_event_t. The btn action function must be lv_res_t return type.
Here is some example code from the manual.

image

@majorjoel2 the event parameter was shown here in the lvgl docs:

image

docs for what version. The version of LVGL PROS uses is V5.3.0 which is found in include/display/lv_version.h. I pulled that example code from examples for that version

Does this line have to appear at the start for the LVGL to work?

lv_scr_load(lv_scr_act());

what exactly does this function do?

also, if I were to use it, do I have to put some sort of delay?

No. I’m pretty sure the PROS docs tell you that you don’t need to.

As for your above questions, as others have said, make sure you are using the 5.3 docs. Events don’t exist in 5.3.

4 Likes

lv_scr_act() is the function that returns the current active screen. You need that because LVGL creates an active screen by default.