Newbie Q - Calling lv_tileview_set_tile_act on a button click

Description

I plan to use tileview with swiping disabled and a rotary encoder.
I want button click to move to the appropriate tile
When i call lv_tileview_set_tile_act in my event handler i get an error, if I call it within my BuildGUI function then it works just fine.

Note - hope you don’t mine me posting these newbie Qs here but i think that if these are things i am coming up against many others will benefit from the solutions being documented :slight_smile:

What MCU/Processor/Board and compiler are you using?

Esp32 Arduino 1.8.9 IDE

What do you want to achieve?

See description :slight_smile:

What have you tried so far?

Adding tileview to global lv_obj_t

Code to reproduce

BuildGUI

static void BuildGUI(void)
{

   static lv_point_t valid_pos[] = {{0,0}, {0, 1}, {1,1}};
    lv_obj_t *tileview;
    tileview = lv_tileview_create(lv_scr_act(), NULL);
    lv_tileview_set_valid_positions(tileview, valid_pos, 3);
    lv_tileview_set_edge_flash(tileview, true);

    lv_obj_t * tile1 = lv_obj_create(tileview, NULL);
    lv_obj_set_size(tile1, LV_HOR_RES, LV_VER_RES);
    lv_obj_set_style(tile1, &lv_style_pretty);
    lv_tileview_add_element(tileview, tile1);

    /*Tile1: just a label*/
    lv_obj_t * label = lv_label_create(tile1, NULL);
    lv_label_set_text(label, "Tile 1");
    lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);

      //and button
  
    lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
    lv_obj_set_event_cb(btn1, event_handler);
    lv_obj_align(btn1, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 45);
    lv_btn_set_fit2(btn1, LV_FIT_TIGHT, LV_FIT_TIGHT);
    label = lv_label_create(btn1, NULL);
    lv_label_set_text(label, "Button");
    lv_group_add_obj(g, btn1);
  
  
    /*Tile2: a list*/
    lv_obj_t * list = lv_list_create(tileview, NULL);
    lv_obj_set_size(list, LV_HOR_RES, LV_VER_RES);
    lv_obj_set_pos(list, 0, LV_VER_RES);
    lv_list_set_scroll_propagation(list, true);
    lv_list_set_sb_mode(list, LV_SB_MODE_OFF);
    lv_tileview_add_element(list, list);

    lv_obj_t * list_btn;
    list_btn = lv_list_add_btn(list, NULL, "One");
    lv_tileview_add_element(tileview, list_btn);

    list_btn = lv_list_add_btn(list, NULL, "Two");
    lv_tileview_add_element(tileview, list_btn);

    list_btn = lv_list_add_btn(list, NULL, "Three");
    lv_tileview_add_element(tileview, list_btn);

    list_btn = lv_list_add_btn(list, NULL, "Four");
    lv_tileview_add_element(tileview, list_btn);

    list_btn = lv_list_add_btn(list, NULL, "Five");
    lv_tileview_add_element(tileview, list_btn);

    list_btn = lv_list_add_btn(list, NULL, "Six");
    lv_tileview_add_element(tileview, list_btn);

    list_btn = lv_list_add_btn(list, NULL, "Seven");
    lv_tileview_add_element(tileview, list_btn);

    list_btn = lv_list_add_btn(list, NULL, "Eight");
    lv_tileview_add_element(tileview, list_btn);

    /*Tile3: a button*/
    lv_obj_t * tile3 = lv_obj_create(tileview, tile1);
    lv_obj_set_pos(tile3, LV_HOR_RES, LV_VER_RES);
    lv_tileview_add_element(tileview, tile3);

    lv_obj_t * btn = lv_btn_create(tile3, NULL);
    lv_obj_align(btn, NULL, LV_ALIGN_CENTER, 0, 0);

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


// THIS CALL WORKS HERE BUT I NEED ON BUTTON EVENT NOT ON GUI BUILD
//  lv_tileview_set_tile_act(tileview,0 , 1, LV_ANIM_ON); 

Event handler…

static void event_handler(lv_obj_t * obj, lv_event_t event)
{
  if (event == LV_EVENT_CLICKED) {                   //buttons clicked
    String runcode = lv_list_get_btn_text(obj);

    if (runcode == "Button") 
    lv_tileview_set_tile_act(tileview,0 , 1, LV_ANIM_ON);
    // THIS ERRORS 
    }

errors with cannot convert ‘lv_obj_t {aka _lv_obj_t}’ to ‘lv_obj_t* {aka _lv_obj_t*}’ for argument ‘1’ to ‘void lv_tileview_set_tile_act(lv_obj_t*, lv_coord_t, lv_coord_t, lv_anim_enable_t)’

Do you have a second declaration of tileview anywhere in the file? Possibly a global variable? What is the exact word-for-word output from the compiler (line numbers and all)?

1 Like

Not a problem! The more helpful information available, the better.

1 Like

I tried a lv_obj_t * tileview ; with no success

I get the error on this line of my event handler

lv_tileview_set_tile_act(tileview,0 , 1, LV_ANIM_ON);

and the full error from the compiler (Arduino IDE 1.8.9) word for word is

/home/chris/Arduino/LoopingShredSabrev5.3/LoopingShredSabrev5.3.ino: In function ‘void event_handler(lv_obj_t*, lv_event_t)’:
LoopingShredSabrev5.3:632:52: error: cannot convert ‘lv_obj_t {aka _lv_obj_t}’ to ‘lv_obj_t* {aka _lv_obj_t*}’ for argument ‘1’ to ‘void lv_tileview_set_tile_act(lv_obj_t*, lv_coord_t, lv_coord_t, lv_anim_enable_t)’
lv_tileview_set_tile_act(tileview,0 , 1, LV_ANIM_ON);

exit status 1

cannot convert ‘lv_obj_t {aka _lv_obj_t}’ to ‘lv_obj_t* {aka _lv_obj_t*}’ for argument ‘1’ to ‘void lv_tileview_set_tile_act(lv_obj_t*, lv_coord_t, lv_coord_t, lv_anim_enable_t)’

So the compiler thinks you are using plain lv_obj_t and not lv_obj_t *. Maybe it’s worth rereading the code - you might have missed a *.

1 Like

Ahha you were right… changed my global variable declare to

lv_obj_t * my_title, *tileview ;

and the code compiles, yussss…

Still not out of the woods yet though… If I call

lv_tileview_set_tile_act(tileview,0 , 1, LV_ANIM_ON);

in my BuildGUI function it works perfectly.

If i call the same thing from my event handler the ESP32 does a full reset and the Serial Monitor gives the following…

Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400fea53 PS : 0x00060d30 A0 : 0x800e3b18 A1 : 0x3ffb1df0
A2 : 0x00000000 A3 : 0x3f4010f4 A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0x40404040 A8 : 0x800e430c A9 : 0x3ffb1e10
A10 : 0x00000002 A11 : 0x3f407c04 A12 : 0x00000028 A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x0000001a EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000024 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff

Backtrace: 0x400fea53:0x3ffb1df0 0x400e3b15:0x3ffb1e10 0x400d1b16:0x3ffb1e70 0x400d8e26:0x3ffb1ea0 0x400d8e6b:0x3ffb1ee0 0x400d8bf7:0x3ffb1f00 0x400df5ea:0x3ffb1f50 0x400df689:0x3ffb1f70 0x400d230c:0x3ffb1f90 0x400e5709:0x3ffb1fb0 0x40087a95:0x3ffb1fd0

Rebooting…

Tried a few variations on the function called from Event Handler with no success… hmmm…

Wait… do you have two declarations of the tileview object? Because you showed me one inside BuildGUI but then you referred to another one (lv_obj_t * my_title, *tileview).

If you have two declarations they aren’t going to have the same value. Please double check that as well.

1 Like

The problem should be what @embeddedt suggested.

I’ve just spotted a minor issue. This line

 lv_tileview_add_element(list, list);

should be

lv_tileview_add_element(tileview, list);

I see it’s wrong in the example too. I’ll fix it.

1 Like

Yes!
Thankyou so much, so the solution is…
Make sure you remove

lv_obj_t *tileview;

from your BuildGUI() and move it way up the top as a global variable. It’s all so obvious once you know how! :smile: