Hey,
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) {
startdataprocessing(e);
}
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 :-/
cheers
Andreas
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)
{
Serial.println(bufL);
}
in header
void show_serial(char *bufL);
in ui_events.c
show_serial("Back1");
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() {
Serial.println(“doingsomething”);
}
in ui_events.c:
dosomething();
leads to:
src/ui/ui_events.c:8:1: warning: data definition has no type or storage class
dosomething();
^~~~~~~~~~~
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.
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.
I am not a programmer actually. Limited at iterative code structures. copy&paste&trial&error
Yes well, I was confused about that double declaration in your example and that (lv_event_t *e) obviously is important
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.
Thanks!