Using LVGL how to get the name of the active screen?

383 Views Asked by At

I am using LVGL to run a basic UI on an Arduino ESP32. There are multiple screens built. When the user changes screens, I want to get the name of the screen and store that in the EEPROM so after a power cycle, I can load the last screen by reading the EEPROM. I am confident that I can program that aspect, but I can't seem to figure out how to set a variable to the name of the active screen using lv_scr_act(). Can anyone help?

2

There are 2 best solutions below

0
On BEST ANSWER

I don't think you can print/save/get the name of the screen, but maybe you can try to set a custom user_data to the screen e.g the name of the screen:

lv_obj_set_user_data(screen1, "Screen_1");

and get it back with:

lv_obj_get_user_data(screen1);
0
On

You can compare the return value from lv_scr_act() to the handle you use for that screen. Presumably have that defined somewhere.

If you are using squareline studio these are defined automatically with the format ui_<screen name>

For example in my code:

lv_obj_t * s = lv_scr_act(); //get active screen
if(s == ui_HOME) do_stuff(); //ui_HOME is the handle of the home screen