How to create a time event to change screens

I want to make a screen change using a timer, and have the screen change occur at the end of a predetermined time without any direct user interaction.

And another screen change when, for example, I receive a variable with a specific value, but without requiring direct interaction.

And what is your trouble? You try some code ?

Yes, I designed an interface, and at one point, I make a call through a button to connect to a WiFi network and simultaneously move to a “waiting” screen while it connects to the WiFi. However, I am unable to implement the transition from the “waiting” screen to another one that confirms the connection once the connection is established. I tried to implement a timer, but I can’t get it to work.

I want to do this between the “conectandowifiscreen” and, depending on whether the connection is made (I use a bool variable to know this), change the screen to “okwifiScreen” if it connects, or to “errorwifiScreen” if there is a connection error. I have implemented the part that changes the screen based on the bool, but it requires clicking to execute, and what I want is for it to execute after a certain amount of time.

This is my ui.ino:

#include "WiFi.h"
#include <lvgl.h>
#include <TFT_eSPI.h>
#include <ui.h>
#include "time.h"
/*Don't forget to set Sketchbook location in File/Preferencesto the path of your UI project (the parent foder of this INO file)*/

/*Change to your screen resolution*/
static const uint16_t screenWidth  = 480;
static const uint16_t screenHeight = 320;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * screenHeight / 10 ];

/*TFT instance*/
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); 

#if LV_USE_LOG != 0
/*Serial debugging*/
void my_print(const char * buf)
{
    Serial.printf(buf);
    Serial.flush();
}
#endif

/*TAMANHO MAXIMO DE LAS CADENAS SSID Y PASSWORD*/
#define MAX_SSID_LENGTH 32
#define MAX_PASSWORD_LENGTH 64
/*VARIABLES SSID Y PASSWORD*/
char ssid[MAX_SSID_LENGTH] = "";
char password[MAX_PASSWORD_LENGTH] = "";
/*VARIABLE CONEXION*/
bool isWifiConnected = false;
/*VARIABLES TIMER*/
uint32_t screen_start_time = 0;
uint32_t screen_duration = 5000; // 5000 ms = 5 segundos
bool timer = false;

/*DISPLAY*/
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
{
    uint32_t w = ( area->x2 - area->x1 + 1 );
    uint32_t h = ( area->y2 - area->y1 + 1 );

    tft.startWrite();
    tft.setAddrWindow( area->x1, area->y1, w, h );
    tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
    tft.endWrite();

    lv_disp_flush_ready( disp );
}

/*TOUCHPAD*/
void my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
{
    uint16_t touchX = 0, touchY = 0;
    bool touched = tft.getTouch( &touchX, &touchY, 500 );

    if( !touched )
    {
        data->state = LV_INDEV_STATE_REL;
    }
    else
    {
        data->state = LV_INDEV_STATE_PR;

        /*Set the coordinates*/
        data->point.x = touchX;
        data->point.y = touchY;

        /*Serial.print( "Data x " );
        Serial.println( touchX );

        Serial.print( "Data y " );
        Serial.println( touchY );
        */
    }
}

/*FUNCION AREA DE TEXTO SSID*/
static void check_text_ssid(lv_event_t * e) {
  
    /*Objeto del area de texto*/
    lv_obj_t * ta = lv_event_get_target(e);
    
    /*Obtenemos el texto*/
    const char * text = lv_textarea_get_text(ta);

    /*Copiamos el texto a la variable global, asegurando no sobrepasar el tamanho del buffer*/
    if(text != NULL) {
        strncpy(ssid, text, MAX_SSID_LENGTH - 1);
        //Asegura el terminador nulo
        ssid[MAX_SSID_LENGTH - 1] = '\0';  
    }
    
    /*Comprobamos que el texto no este vacio*/
    if(ssid == NULL || strlen(ssid) == 0) 
    {
        /*Vacio.*/
        printf("Campo SSID vacio.\n");
    } 
    else 
    {
        /*Print del texto*/
        printf("SSID: %s\n", ssid);
    }
}

/*FUNCION AREA DE TEXTO PASSWORD*/
static void check_text_password(lv_event_t * e) {
  
    /*Objeto del area de texto*/
    lv_obj_t * tp = lv_event_get_target(e);
    
    /*Obtenemos el texto*/
    const char * text = lv_textarea_get_text(tp);

    /*Copiamos el texto a la variable global, asegurando no sobrepasar el tamanho del buffer*/
    if(text != NULL) {
        strncpy(password, text, MAX_PASSWORD_LENGTH - 1);
        //Asegura el terminador nulo
        password[MAX_PASSWORD_LENGTH - 1] = '\0';  
    }
    
    /*Comprobamos que el texto no este vacio*/
    if(password == NULL || strlen(password) == 0) 
    {
        /*Vacio.*/
        printf("Campo password vacio.\n");
    } 
    else 
    {
        /*Print del texto*/
        printf("Password: %s\n",password);
    }
}

/*FUNCION CONEXION RED WIFI*/
static void connectWiFi(lv_event_t * e) 
{
  LV_UNUSED(e);
  
  /*Prints de informacion*/
  Serial.print("Nuestra ssid: ");
  Serial.println(ssid);
  Serial.print("Nuestra password: ");
  Serial.println(password);
  Serial.print("Intentando conectar a: ");
  /*Nos conectamos a la red*/
  WiFi.begin(ssid, password);
  delay(5000);
  /*Si no realiza la conexion mensaje de error y variable global a false*/
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("No se pudo conectar a la red WiFi.");
    isWifiConnected = false;
    } 
    /*Si realiza la conexion cambiamos la variable global a true*/
    else 
    {
        Serial.println("Conectado exitosamente a la red WiFi.");
        isWifiConnected = true;
        Serial.print("DirecciĂłn IP: ");
        Serial.println(WiFi.localIP());
    }
}

/*SETUP*/
void setup()
{
    /*Prepare for possible serial debug*/
    Serial.begin( 115200 ); 
    
    lv_init();

#if LV_USE_LOG != 0
    /*Register print function for debugging*/
    lv_log_register_print_cb( my_print ); 
#endif
    /*TFT init*/
    tft.begin();  
    /*Landscape orientation, flipped*/        
    tft.setRotation( 3 ); 
    /*CALIBRACION*/
    uint16_t calData[5] = { 274, 3590, 258, 3488, 1 };
    tft.setTouch(calData);

    lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * screenHeight / 10 );

    /*Initialize the display*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init( &disp_drv );
    /*Change the following line to your display resolution*/
    disp_drv.hor_res = screenWidth;
    disp_drv.ver_res = screenHeight;
    disp_drv.flush_cb = my_disp_flush;
    disp_drv.draw_buf = &draw_buf;
    lv_disp_drv_register( &disp_drv );

    /*Initialize the (dummy) input device driver*/
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init( &indev_drv );
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = my_touchpad_read;
    lv_indev_drv_register( &indev_drv );

    ui_init();

    /*EVENTOS*/
    lv_obj_add_event_cb(ui_ssidArea, check_text_ssid, LV_EVENT_VALUE_CHANGED, NULL);
    lv_obj_add_event_cb(ui_passwordArea, check_text_password, LV_EVENT_VALUE_CHANGED, NULL);
    lv_obj_add_event_cb(ui_okmanualpasswordButton, connectWiFi, LV_EVENT_CLICKED, NULL);  
}

/*LOOP*/
void loop()
{
    /*Let the GUI do its work */
    lv_timer_handler();
    
    if (lv_tick_get() - screen_start_time > screen_duration) {
      timer = true;
    }
    
    delay(5);
}

and this is my ui.c:

// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.3.4
// LVGL version: 8.3.6
// Project name: Prueba_SquareLine

#include "ui.h"
#include "ui_helpers.h"

extern bool isWifiConnected;
extern uint32_t  screen_start_time;
extern bool timer;
///////////////////// VARIABLES ////////////////////

static void change_screen(lv_timer_t * timer);
// SCREEN: ui_titleScreen
void ui_titleScreen_screen_init(void);
void ui_event_titleScreen(lv_event_t * e);
lv_obj_t * ui_titleScreen;
lv_obj_t * ui_titlePanel;
lv_obj_t * ui_titleLabel;


// SCREEN: ui_mainScreen
void ui_mainScreen_screen_init(void);
lv_obj_t * ui_mainScreen;
void ui_event_analisisButton(lv_event_t * e);
lv_obj_t * ui_analisisButton;
lv_obj_t * ui_analisisLabel;
void ui_event_wifiButton(lv_event_t * e);
lv_obj_t * ui_wifiButton;
lv_obj_t * ui_wifiLabel;


// SCREEN: ui_analisisScreen1
void ui_analisisScreen1_screen_init(void);
void ui_event_analisisScreen1(lv_event_t * e);
lv_obj_t * ui_analisisScreen1;
lv_obj_t * ui_analisisxplainPanel;
lv_obj_t * ui_analisisxplainText;


// SCREEN: ui_analisisScreen2
void ui_analisisScreen2_screen_init(void);
void ui_event_analisisScreen2(lv_event_t * e);
lv_obj_t * ui_analisisScreen2;
lv_obj_t * ui_advertencianalisisContainer;
lv_obj_t * ui_advertencianalisisLabel;


// SCREEN: ui_analisisScreen3
void ui_analisisScreen3_screen_init(void);
void ui_event_analisisScreen3(lv_event_t * e);
lv_obj_t * ui_analisisScreen3;
void ui_event_iniciaranalisisButton(lv_event_t * e);
lv_obj_t * ui_iniciaranalisisButton;
lv_obj_t * ui_iniciaranalisisLabel;
void ui_event_backButton1(lv_event_t * e);
lv_obj_t * ui_backButton1;
lv_obj_t * ui_backLabel1;


// SCREEN: ui_analizandoScreen1
void ui_analizandoScreen1_screen_init(void);
void ui_event_analizandoScreen1(lv_event_t * e);
lv_obj_t * ui_analizandoScreen1;
lv_obj_t * ui_Spinner1;
lv_obj_t * ui_analizandoLabel1;


// SCREEN: ui_analizandoScreen2
void ui_analizandoScreen2_screen_init(void);
void ui_event_analizandoScreen2(lv_event_t * e);
lv_obj_t * ui_analizandoScreen2;
lv_obj_t * ui_Spinner2;
lv_obj_t * ui_analizandoLabel2;


// SCREEN: ui_analizandoScreen3
void ui_analizandoScreen3_screen_init(void);
void ui_event_analizandoScreen3(lv_event_t * e);
lv_obj_t * ui_analizandoScreen3;
lv_obj_t * ui_Spinner3;
lv_obj_t * ui_analizandoLabel3;


// SCREEN: ui_analizandoScreen4
void ui_analizandoScreen4_screen_init(void);
void ui_event_analizandoScreen4(lv_event_t * e);
lv_obj_t * ui_analizandoScreen4;
lv_obj_t * ui_Spinner4;
lv_obj_t * ui_analizandoLabel4;


// SCREEN: ui_analizandoScreen5
void ui_analizandoScreen5_screen_init(void);
void ui_event_analizandoScreen5(lv_event_t * e);
lv_obj_t * ui_analizandoScreen5;
lv_obj_t * ui_Spinner5;
lv_obj_t * ui_analizandoLabel5;


// SCREEN: ui_resultadosScreen1
void ui_resultadosScreen1_screen_init(void);
lv_obj_t * ui_resultadosScreen1;
void ui_event_resultadosButton1(lv_event_t * e);
lv_obj_t * ui_resultadosButton1;
lv_obj_t * ui_resultadosbutton1Label;


// SCREEN: ui_resultadosScreen2
void ui_resultadosScreen2_screen_init(void);
lv_obj_t * ui_resultadosScreen2;
void ui_event_resultadosButton2(lv_event_t * e);
lv_obj_t * ui_resultadosButton2;
lv_obj_t * ui_resultadosbutton2Label;
void ui_event_resultadosButton3(lv_event_t * e);
lv_obj_t * ui_resultadosButton3;
lv_obj_t * ui_resultadosbutton3Label;


// SCREEN: ui_finanalisisbackScreen
void ui_finanalisisbackScreen_screen_init(void);
lv_obj_t * ui_finanalisisbackScreen;
void ui_event_finanalisisbackButton(lv_event_t * e);
lv_obj_t * ui_finanalisisbackButton;
lv_obj_t * ui_finanalisisbackLabel;
void ui_event_finanalisismainButton(lv_event_t * e);
lv_obj_t * ui_finanalisismainButton;
lv_obj_t * ui_finanalisismainLabel;


// SCREEN: ui_wifiScreen1
void ui_wifiScreen1_screen_init(void);
void ui_event_wifiScreen1(lv_event_t * e);
lv_obj_t * ui_wifiScreen1;
lv_obj_t * ui_wifixplainPanel;
lv_obj_t * ui_wifixplainLabel;


// SCREEN: ui_tipowifiScreen
void ui_tipowifiScreen_screen_init(void);
lv_obj_t * ui_tipowifiScreen;
void ui_event_wifiseleccionButton(lv_event_t * e);
lv_obj_t * ui_wifiseleccionButton;
lv_obj_t * ui_wifiseleccionLabel;
void ui_event_wifimanualButton(lv_event_t * e);
lv_obj_t * ui_wifimanualButton;
lv_obj_t * ui_wifimanualLabel;


// SCREEN: ui_manualwifissidScreen
void ui_manualwifissidScreen_screen_init(void);
lv_obj_t * ui_manualwifissidScreen;
void ui_event_manualwifiKeyboard(lv_event_t * e);
lv_obj_t * ui_manualwifiKeyboard;
void ui_event_ssidArea(lv_event_t * e);
lv_obj_t * ui_ssidArea;
void ui_event_okmanualssidButton(lv_event_t * e);
lv_obj_t * ui_okmanualssidButton;
lv_obj_t * ui_okmanualssidLabel;


// SCREEN: ui_manualwifipasswordScreen
void ui_manualwifipasswordScreen_screen_init(void);
lv_obj_t * ui_manualwifipasswordScreen;
void ui_event_manualwifiKeyboard1(lv_event_t * e);
lv_obj_t * ui_manualwifiKeyboard1;
void ui_event_passwordArea(lv_event_t * e);
lv_obj_t * ui_passwordArea;
void ui_event_okmanualpasswordButton(lv_event_t * e);
lv_obj_t * ui_okmanualpasswordButton;
lv_obj_t * ui_okmanualpasswordLabel;


// SCREEN: ui_seleccionwifiScreen
void ui_seleccionwifiScreen_screen_init(void);
void ui_event_seleccionwifiScreen(lv_event_t * e);
lv_obj_t * ui_seleccionwifiScreen;


// SCREEN: ui_seleccionpasswordScreen
void ui_seleccionpasswordScreen_screen_init(void);
void ui_event_seleccionpasswordScreen(lv_event_t * e);
lv_obj_t * ui_seleccionpasswordScreen;
lv_obj_t * ui_seleccionwifiKeyboard;
void ui_event_passwordseleccionArea(lv_event_t * e);
lv_obj_t * ui_passwordseleccionArea;


// SCREEN: ui_conectandowifiScreen
void ui_conectandowifiScreen_screen_init(void);
void ui_event_conectandowifiScreen(lv_event_t * e);
lv_obj_t * ui_conectandowifiScreen;
lv_obj_t * ui_conectandowifiSpinner;
lv_obj_t * ui_conectandowifiLabel;


// SCREEN: ui_okwiffiScreen
void ui_okwiffiScreen_screen_init(void);
lv_obj_t * ui_okwiffiScreen;
lv_obj_t * ui_okwifiPanel;
lv_obj_t * ui_okwifiLabel;
void ui_event_okwiffibackButton(lv_event_t * e);
lv_obj_t * ui_okwiffibackButton;
lv_obj_t * ui_okwifibackLabel;


// SCREEN: ui_errorwiffiScreen
void ui_errorwiffiScreen_screen_init(void);
lv_obj_t * ui_errorwiffiScreen;
lv_obj_t * ui_errorwifiPanel;
lv_obj_t * ui_errorwifiLabel;
void ui_event_errorwiffibackButton(lv_event_t * e);
lv_obj_t * ui_errorwiffibackButton;
lv_obj_t * ui_errorwifibackLabel;
lv_obj_t * ui____initial_actions0;

///////////////////// TEST LVGL SETTINGS ////////////////////
#if LV_COLOR_DEPTH != 16
    #error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings"
#endif
#if LV_COLOR_16_SWAP !=0
    #error "LV_COLOR_16_SWAP should be 0 to match SquareLine Studio's settings"
#endif

///////////////////// ANIMATIONS ////////////////////

///////////////////// FUNCTIONS ////////////////////
void ui_event_titleScreen(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_mainScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_mainScreen_screen_init);
    }
}
void ui_event_analisisButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analisisScreen1, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analisisScreen1_screen_init);
    }
}
void ui_event_wifiButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_wifiScreen1, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_wifiScreen1_screen_init);
    }
}
void ui_event_analisisScreen1(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analisisScreen2, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analisisScreen2_screen_init);
    }
}
void ui_event_analisisScreen2(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analisisScreen3, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analisisScreen3_screen_init);
    }
}
void ui_event_analisisScreen3(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analizandoScreen1, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analizandoScreen1_screen_init);
    }
}
void ui_event_iniciaranalisisButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_mainScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_mainScreen_screen_init);
    }
}
void ui_event_backButton1(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        inicioanalisis(e);
    }
}
void ui_event_analizandoScreen1(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analizandoScreen2, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analizandoScreen2_screen_init);
    }
    if(event_code == LV_EVENT_CLICKED) {
        analizando1(e);
    }
}
void ui_event_analizandoScreen2(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analizandoScreen3, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analizandoScreen3_screen_init);
    }
    if(event_code == LV_EVENT_CLICKED) {
        analizando2(e);
    }
}
void ui_event_analizandoScreen3(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analizandoScreen4, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analizandoScreen4_screen_init);
    }
    if(event_code == LV_EVENT_CLICKED) {
        analizando3(e);
    }
}
void ui_event_analizandoScreen4(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_analizandoScreen5, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_analizandoScreen5_screen_init);
    }
    if(event_code == LV_EVENT_CLICKED) {
        analizando4(e);
    }
}
void ui_event_analizandoScreen5(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_resultadosScreen1, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_resultadosScreen1_screen_init);
    }
    if(event_code == LV_EVENT_CLICKED) {
        analizando5(e);
    }
}
void ui_event_resultadosButton1(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_resultadosScreen2, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_resultadosScreen2_screen_init);
    }
}
void ui_event_resultadosButton2(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_resultadosScreen1, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_resultadosScreen1_screen_init);
    }
}
void ui_event_resultadosButton3(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_finanalisisbackScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_finanalisisbackScreen_screen_init);
    }
}
void ui_event_finanalisisbackButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_resultadosScreen2, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_resultadosScreen2_screen_init);
    }
}
void ui_event_finanalisismainButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_mainScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_mainScreen_screen_init);
    }
}
void ui_event_wifiScreen1(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_manualwifissidScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_manualwifissidScreen_screen_init);
    }
}
void ui_event_wifiseleccionButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_seleccionwifiScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_seleccionwifiScreen_screen_init);
    }
}
void ui_event_wifimanualButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_manualwifissidScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_manualwifissidScreen_screen_init);
    }
}
void ui_event_manualwifiKeyboard(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_keyboard_set_target(ui_manualwifiKeyboard,  ui_ssidArea);
    }
}
void ui_event_ssidArea(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        ssidpruebaEvent(e);
    }
}
void ui_event_okmanualssidButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_manualwifipasswordScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0,
                          &ui_manualwifipasswordScreen_screen_init);
    }
}
void ui_event_manualwifiKeyboard1(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_keyboard_set_target(ui_manualwifiKeyboard1,  ui_passwordArea);
    }
}
void ui_event_passwordArea(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        passwordpruebaEvent(e);
    }
}
void ui_event_okmanualpasswordButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        conexmanualFunction(e);
        _ui_screen_change(&ui_conectandowifiScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_conectandowifiScreen_screen_init);
    }
}
void ui_event_seleccionwifiScreen(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_seleccionpasswordScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_seleccionpasswordScreen_screen_init);
    }
}
void ui_event_seleccionpasswordScreen(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        screen_start_time = lv_tick_get();
        _ui_screen_change(&ui_conectandowifiScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_conectandowifiScreen_screen_init);
    }
}
void ui_event_passwordseleccionArea(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        passwordselecccion(e);
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ui_event_conectandowifiScreen(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(timer == true) {
        if (isWifiConnected) {
            _ui_screen_change(&ui_okwiffiScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_okwiffiScreen_screen_init);
            } 
            else {
                _ui_screen_change(&ui_errorwiffiScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_errorwiffiScreen_screen_init);
                }
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ui_event_okwiffibackButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_mainScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_mainScreen_screen_init);
    }
}
void ui_event_errorwiffibackButton(lv_event_t * e)
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t * target = lv_event_get_target(e);
    if(event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_manualwifissidScreen, LV_SCR_LOAD_ANIM_NONE, 500, 0, &ui_manualwifissidScreen_screen_init);
    }
}

///////////////////// SCREENS ////////////////////

void ui_init(void)
{
    lv_disp_t * dispp = lv_disp_get_default();
    lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
                                               false, LV_FONT_DEFAULT);
    lv_disp_set_theme(dispp, theme);
    ui_titleScreen_screen_init();
    ui_mainScreen_screen_init();
    ui_analisisScreen1_screen_init();
    ui_analisisScreen2_screen_init();
    ui_analisisScreen3_screen_init();
    ui_analizandoScreen1_screen_init();
    ui_analizandoScreen2_screen_init();
    ui_analizandoScreen3_screen_init();
    ui_analizandoScreen4_screen_init();
    ui_analizandoScreen5_screen_init();
    ui_resultadosScreen1_screen_init();
    ui_resultadosScreen2_screen_init();
    ui_finanalisisbackScreen_screen_init();
    ui_wifiScreen1_screen_init();
    ui_tipowifiScreen_screen_init();
    ui_manualwifissidScreen_screen_init();
    ui_manualwifipasswordScreen_screen_init();
    ui_seleccionwifiScreen_screen_init();
    ui_seleccionpasswordScreen_screen_init();
    ui_conectandowifiScreen_screen_init();
    ui_okwiffiScreen_screen_init();
    ui_errorwiffiScreen_screen_init();
    ui____initial_actions0 = lv_obj_create(NULL);
    lv_disp_load_scr(ui_titleScreen);
}

Hmm, start with basics. Squareline generated files (ui.c) isnt designed for edit with your code, except ui_events.c (or cpp)
When you learn use Events in designer, then you see option call func, and this is primary for coding. Designer create empty func named as you enter in designer and asociate event callback. Then you place code in ui_events.c file.

And for timed events you have two method 1. in loop create timer variable and manage event 2. run lv_timer_create for once or repeat callbacks

And too in loop you can check event based outside lvgl as wifi.

int looper5;
void loop()
{
    /*Let the GUI do its work */
    lv_timer_handler();
    
    delay(5);
    looper5++;

if((looper5%100) == 0) do somethink every half sec

if (WiFi.status() != laststatus) do what you need on change or first connect...
}
1 Like

I saw in a video that from the ui_events.c file you can’t trigger events in Arduino, so I started to do it this other way, but I’ll try what you’re suggesting and see if I can solve it.

You can call external functions if you give their names in the CALL_FUNCTION action and tick ‘Don’t export function’ checkbox below the name. If that’s what you want. But the function should be non-blocking, i.e only start the waiting for WiFi connection or set a timer/counter, and you need to (increment/decrement and) check/poll the value periodically in the main loop as Marian_M shows in a short example. When the counter counts up or a variable/returnvalue asserts or fits your desired value, you can call the screen-change function from the GUI main loop if you want. ( If you need precise timing, not just counters in the loop(), it will still require setting up LVGL timers.)

1 Like