Printf object name

Hi,
When I’m debugging, I’d like to print what objects are created or which button is pressed with their names.
For instance, as I declared some variable, I can use printf function to watch it on putty window.

uint_8 i = 0; 
printf("i is %d", i);

As above, when a start screen is created, its data type is lv_obj_t, I wonder what command is needed.

lv_obj_t * start_screen;
start_screen = lv_obj_create(NULL, NULL);
printf("The current screen is [    ]", start_screen);

I’m wondering how to put the blank [ ].

You can store a name in the object’s user data:

lv_obj_set_user_data(start_screen, "Screen 1")

And in printf:

const char * name =  lv_obj_get_user_data(obj);
printf("The current screen is %s", name ? name : "N/A");

1 Like