Arduino - calling event function declared in ui_events.c from .ino code file

What do you want to achieve?

I created with SLS an event calling a function whose purpose is, at screen load, to change a widget’s color stored in deep-sleep memory. The function is declared in ui_events.c.

void ColorSaveScreen(lv_event_t * e)

Now I want to call that same function from my main .ino code to immediately update the widget’s color on the screen when the code changes it.
However if I call the function from my .ino sketch I get errors such as
“lv_event_t not defined in this scope”
“e not defined in this scope”

What have you tried so far?

I tried defining the function also in my .ino file whith the “extern” modifier

extern void ColorSaveScreen(lv_event_t * e);

It seems to work because the “go to definition” command shows the ui_event.c file correctly, but later in the code when I call the function I get the same error on compile and the “go to definition” command doesn’t work.

Others

  • SquareLine Studio version: latest
  • Operating system: windows 11
  • Target hardware: ESP 32

include uievents.h

So, I have tried both #include “ui_events.h” and #include <ui_events.h>, with different syntaxes.
It still doesn’t work.

This are all the syntaxes I tried with corresponding error messages on compile.
I GET THE SAME ERRORS IF I DON’T INCLUDE ui_events.h !!

RTC_DATA_ATTR extern int arc_color_id[47];
void ColorSaveScreen(lv_event_t * e);

void loop()

ColorSaveScreen(e);

Error: ‘e’ was not declared in this scope

  1. added “extern”:

RTC_DATA_ATTR extern int arc_color_id[47];
extern void ColorSaveScreen(lv_event_t * e);

void loop()

ColorSaveScreen(e);

Error: ‘e’ was not declared in this scope

  1. changed the function argument:

RTC_DATA_ATTR extern int arc_color_id[47];
extern void ColorSaveScreen(lv_event_t * e);

void loop()

ColorSaveScreen(lv_event_t * e);

Error: expected primary-expression before ‘*’ token
I guess that’s because it doesn’t recognize “lv_event_t”…

4)removed arc_color_id declaration:

extern void ColorSaveScreen(lv_event_t * e);

void loop()

ColorSaveScreen(lv_event_t * e);

Error: ‘arc_color_id’ was not declared in this scope - expected primary-expression before ‘*’ token

Finally, this is the content of the ui_events.c file:

// This file was generated by SquareLine Studio

// SquareLine Studio version: SquareLine Studio 1.3.1

// LVGL version: 8.3.6

// Project name: MF_v6_events

#include “ui.h”

RTC_DATA_ATTR int arc_color_id[47];

void ColorSaveScreen(lv_event_t * e)

{

}

calling with this parameter never will work. You are lost btween C a C++

You create ColorSaveScreen func in Squareline or manualy? Better is create dummy event in squareline with call … After this you can use it two ways, one send used dummy event

lv_event_send (obj, <EVENT_CODE> &some_data)

instead data can use NULL, or second way is NULL in parameter

ColorSaveScreen(NULL);

I created ColorSaveScreen func in Squareline, by adding an event to Screen1 and chosing Trigger = SCREEN_LOADED and action = call function ColorSaveScreen.

Then I got an empty function in my ui_events.c file and there I added stuff to the function to make it load saved colors on all screen objects.

So starting from your last tip, I first tried to use the second way by using:

ColorSaveScreen(NULL);

in my .ino file. It compiles without errors but when uploaded it restarts every time the ui gets loaded and stays in this loop without doing anything.

So I’m now trying the first way, by using

lv_event_send (obj, LV_EVENT_SCREEN_LOADED, &NULL)

but I am unsure of what I should write instead of “obj” and whether this syntax is supposed to be equivalent to the function call ColorSaveScreen(NULL).

Simple obj is ui_… object where you create event in Squareline.