Function on ready event to manipulate things


I know this probably is more a coding question than related to squareline layout. I am currently trying to find out how to use a function executed at an event.

For my example I got a start screen1 with a couple of dropdown options and a button to proceed to next step screen2 for further progress. Screen2 fires an event when ready that should start further progress.

if(event_code == LV_EVENT_READY) {

This function ends up in ui_events.c however it doesn’t have any access to basic functionality like Serial.print or variables defined in main.cpp.

Sorry this probably is a total noob question but how can I achieve that?
Question that kicks in with that, does Squareline Studio overwrite my changes in /ui, once I changed something there? Feels like it could be painful for later changes in the ui then :-/


Yes ui and other gen files is overwriten on every export, except ui_event .
This can be c or cpp , but access to other files you need handle in h …
I like more c file and for func , that require cpp i create … little example
in main.cpp (ino)

void show_serial(char *bufL)

in header

void show_serial(char *bufL);

in ui_events.c


Ah okay, thanks. That of course eliminates the messing with ui files.
I assume the code returns to loop() then, once the job in show_serial() is done?

show serial is normal func return where is caled.
and Squareline have many events test and learn use it
after export this code in ui_events is created new epty func for your code

Yes I know, the Serial.print was just an example. Not my real intention except for debugging.
Thanks for the help, I am going to play around with it.

I don’t get it.

So in the header inside the ifdef __cplusplus

I got this now:
void dosomething();

in main.cpp:

void dosomething() {

in ui_events.c:

leads to:

src/ui/ui_events.c:8:1: warning: data definition has no type or storage class
src/ui/ui_events.c:8:1: warning: type defaults to 'int' in declaration of 'dosomething' [-Wimplicit-int]
src/ui/ui_events.c:8:1: error: conflicting types for 'dosomething'
In file included from src/ui/ui.h:26,
                 from src/ui/ui_events.c:6:
src/ui/ui_events.h:13:6: note: previous declaration of 'dosomething' was here
 void dosomething();
*** [.pio\build\esp32dev\src\ui\ui_events.c.o] Error 1

While squareline generates in ui_events.c :

void dosomething(lv_event_t * e)


// Your code here


Hmm yes but WHAT code? I can’t access anything from main.cpp within ui_events-c.
I fear the logic is far beyond my understanding. :frowning:

Its simple you cant use same name function

or activate checkbox do not export …

You are programmer or lego player? In Lego you can have many same bricks, but in code two function with same name isnt ideal. :slight_smile:

I am not a programmer actually. Limited at iterative code structures. copy&paste&trial&error :joy:
Yes well, I was confused about that double declaration in your example and that (lv_event_t *e) obviously is important :grimacing:

I set the event to READY, that obviously was my fault. I expected that to be something like “ready” but SCREEN LOADED actually works. Whatever event “READY” means then.