Hi, I can help you complete your forum post with the additional information about adding an event to a button in Squareline Studio. Here’s your completed post with the additional information:
One approach that works well without modifying the generated Squareline code is to use a global parameter structure:
// Global parameter structure for screen configuration
typedef struct {
int gpio1;
int gpio2;
// Add more parameters as needed
} screen_params_t;
// Global instance to store current parameters
screen_params_t current_screen_params;
Then, in your button event handlers, set these parameters before loading the screen:
void button1_handler(lv_event_t * e) {
if(lv_event_get_code(e) == LV_EVENT_CLICKED) {
// Set parameters for first GPIO pair
current_screen_params.gpio1 = 5;
current_screen_params.gpio2 = 6;
// Load the screen
lv_disp_load_scr(ui_Screen1);
}
}
void button2_handler(lv_event_t * e) {
if(lv_event_get_code(e) == LV_EVENT_CLICKED) {
// Set parameters for second GPIO pair
current_screen_params.gpio1 = 12;
current_screen_params.gpio2 = 13;
// Load the screen
lv_disp_load_scr(ui_Screen1);
}
}
In your screen’s event callbacks, use the stored parameters:
void ui_event_OnOffSwitch(lv_event_t * e) {
if(lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
bool state = lv_obj_has_state(ui_OnOffSwitch, LV_STATE_CHECKED);
// Use stored parameters instead of hardcoded values
gpio_set_level(current_screen_params.gpio1, state);
gpio_set_level(current_screen_params.gpio2, state);
}
}
You can also update screen labels when the screen loads to reflect which GPIOs are being controlled:
void ui_event_Screen1(lv_event_t * e) {
if(lv_event_get_code(e) == LV_EVENT_SCREEN_LOADED) {
char label_text[32];
sprintf(label_text, "GPIO %d & %d Control",
current_screen_params.gpio1,
current_screen_params.gpio2);
lv_label_set_text(ui_TitleLabel, label_text);
}
}
This approach keeps your Squareline-generated code intact and gives you the flexibility you need.
To set this up in Squareline Studio, you need to add an event to your button by:
- Select the button in Squareline Studio
- Go to the Events tab in the properties panel
- Add a new event with the trigger type “Clicked”
- Choose “Call function” as the action type
- Enter your function name (e.g., “button1_handler”) in the function name field
Hope this helps!