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.
Its truly because im an unseasoned programmer!! LOL!!!
Now that you have been so kind as to show me the proper way, im going to give it a go.
although when i do currently export from squareline my habit is to instantly remove the events.c file unless i defined a new function call, then i cut it from the events and paste it into main.c and off I go… Just easier for me… but i will give it a go so its properly done… Thanks for the info and sorry for the long delay! I do appreciate your help!
Note that in the newer version you can choose to not export ui_event.c
. This way you can define the function as you wish.
Give me sample, in the events, how to turn on the led using digitalWrite from main ino program. Because declaration error appears.
I’ve just tried it out and really there is an issue with Arduino if you don’t export the events. We will fix it in the next release which will be out next week.
okay, how export the events? so program will working fine. The events is in C header, and i write digitalWrite for turn on led, but errors appear.
The problem is that if you select not the export the events, an lv_event.h
is still required else ui.c
won’t see the callbacks.
And that what we will fix in the next release.