Ui_events.c not work good for me

What do you want to achieve?

ui_events.c to work correctly

What have you tried so far?

have no idea

Screenshot or video

Others

  • SquareLine Studio version:
  • Operating system:
  • Target hardware: ESP32 with TFT

Hello, I use PLATFORMIO. When I put my code in ui_events.c, I always get errors like, function not defined, or so on.
Does ui_events.c has to be initialized somewhere before use?

Hi,

What is the exact error message?

It is not error, rather it can not see my subs in the main.cpp.

If you call not LVGL or SquareLine rlated functions in ui_events.c (e.g. uart_send("hello")) those functions really needs to be declared like in any other C file.

Just a suggestion and im not stating that it is the correct one, however I initially copied all the functions in the events.c and put them in my main.cpp instead along with the code i want to fire when the event occurs. After this, then i just simply delete the generated events.c from my platformio project after each export (it has none of my code in it anyways, just empty function calls) and all is good! Again, that may not be the intended way to do things, but in those events i need to do things with variables defined in my main.cpp file and without going through the whole mutex thing, this just works and is super easy for me. (if you dont delete the events.c after each squareline export it will bark and say that the functions are defined multiple times.) If you create new events that call functions, just be sure to scrape them from the generated events.c and paste them into your main.cpp or manually define them…before deleting the events.c file from the platformio project.

This is exactly what I do now.
In fact - its very convenient.

1 Like

Why can’t you simple do something like this in ui_events.c:

extern int my_var_from_main_cpp;

void ui_sls_generated_event(lv_event_t * e)
{
   do_something(my_var_from_main_cpp);
}

Note that the content of ui_events.c won’t be overwritten, but only completed with new evnts if needed. So you are free to add any custom code.