Hi Rob, thanks for your help.
Basically, in the SETUP of the eControl.ino program I extract data from a web server and assemble an array with the prices per hour of the day.
I check what time it is and display on the screen the data corresponding to that time in the fields: ec_hora, ec_prec, ec_horb, ec_preb and ec_porc. This does it correctly.
Subsequently, in the LOOP every 5 minutes I check the time again and if it changes I update the price data of that new time on the screen. This is what I can’t get.
// -------------------------------------------- SETUP ----------------------------------------------
void setup() {
Serial.begin(115200);
delay(1000);
lv_init();
#if LV_USE_LOG != 0
lv_log_register_print_cb(my_print);
#endif
eControl();
tft.begin();
tft.setRotation(1);
uint16_t calData[5] = { 185, 3534, 246, 3604, 1 };
tft.setTouch(calData);
lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * screenHeight / 10);
/*Inicializo el TFT*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = 320; /*Indico la resolucion de la pantalla*/
disp_drv.ver_res = 240;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
/*Inicializo el controlador del dispositivo de entrada (ficticio)*/
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();
esp_task_wdt_init(WDT_TIMEOUT, true); //Activamos perro para reiniciar ESP32
esp_task_wdt_add(NULL); //añadir subproceso actual al reloj WDT
}
void loop() {
lv_task_handler();
vTaskDelay(5);
if ((millis() - timing) > 300000) { // Ejecuto cada 5 mtos. eControl. 300.000 ms.
timing = millis();
eControl();
//lv_scr_load(ui_Inicio);
//lv_disp_trig_activity( dispp );
}
if ( (millis() - dormir) > 30000 && !TFT_On == 0) { // Apago el TFT si nadie hace nada en 30 seg. 30000
digitalWrite(mosfet, HIGH);
TFT_On = 0;
}
esp_task_wdt_reset(); //Tranquilizo al perro
buttonState = digitalRead(GPIO_NUM_35);
if( buttonState == LOW ) esp_deep_sleep_start();
}
All the fields that I mention are in global variables, but I think the problem is that since there are no changes in the objects on the screen, lv_task_handler() simply does not perform the refresh. I have tried to put printf() in ui_Start_screen_init(void) and the first time it shows its step in the console, but then it never renders them again.
I do not know if I have explained myself, if you need any clarification do not hesitate to ask me.
Greetings.
#include "ui.h"
#include "ui_helpers.h"
#include <string.h>
///////////////////// VARIABLES ////////////////////
void ui_event_Inicio(lv_event_t * e);
lv_obj_t * ui_Inicio;
lv_obj_t * ui_Inicio_IBInicio;
void ui_event_Inicio_IBInicio(lv_event_t * e);
lv_obj_t * ui_Inicio_IBProxi;
void ui_event_Inicio_IBProxi(lv_event_t * e);
lv_obj_t * ui_Inicio_PanelAhora;
lv_obj_t * ui_Inicio_Label2;
lv_obj_t * ui_Inicio_Label5;
lv_obj_t * ui_Inicio_Label6;
lv_obj_t * ui_Inicio_PrecioAh;
lv_obj_t * ui_Inicio_PanelDespues;
lv_obj_t * ui_Inicio_Label3;
lv_obj_t * ui_Inicio_HoraDe;
lv_obj_t * ui_Inicio_PrecioDe;
lv_obj_t * ui_Inicio_Porcentaje;
const char * ec_ssid;
const char * ec_pass;
const char * ec_hora;
const char * ec_porc;
const char * ec_esta;
const char * ec_prec;
const char * ec_scro;
const char * ec_horb;
const char * ec_preb;
const char * ec_estb;
const char * ec_prox;
int estados[24];
int estadop[24];
int carga;
int cargap;
int TFT_On;
int Wifi_On;
char * swifi_con;
void ui_Inicio_screen_init(void)
{
ui_Inicio = lv_obj_create(NULL);
lv_obj_clear_flag(ui_Inicio, LV_OBJ_FLAG_SCROLLABLE);
ui_Inicio_IBInicio = lv_btn_create(ui_Inicio);
lv_obj_set_width(ui_Inicio_IBInicio, lv_pct(16));
lv_obj_set_height(ui_Inicio_IBInicio, 40);
lv_obj_set_x(ui_Inicio_IBInicio, -126);
lv_obj_set_y(ui_Inicio_IBInicio, -96);
lv_obj_set_align(ui_Inicio_IBInicio, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_Inicio_IBInicio, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag(ui_Inicio_IBInicio, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_bg_img_src(ui_Inicio_IBInicio, &ui_img_adslwifi_png,
LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_color(ui_Inicio_IBInicio, lv_color_hex(0x06FA1F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_Inicio_IBInicio, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_Inicio_IBInicio, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_IBProxi = lv_btn_create(ui_Inicio);
lv_obj_set_height(ui_Inicio_IBProxi, 40);
lv_obj_set_width(ui_Inicio_IBProxi, 50);
lv_obj_set_x(ui_Inicio_IBProxi, 130);
lv_obj_set_y(ui_Inicio_IBProxi, -96);
lv_obj_set_align(ui_Inicio_IBProxi, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_Inicio_IBProxi, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag(ui_Inicio_IBProxi, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_bg_img_src(ui_Inicio_IBProxi, &ui_img_proxi_png,
LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_color(ui_Inicio_IBProxi, lv_color_hex(0x06FA1F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_Inicio_IBProxi, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_Inicio_IBProxi, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_PanelAhora = lv_obj_create(ui_Inicio);
lv_obj_set_height(ui_Inicio_PanelAhora, 113);
lv_obj_set_width(ui_Inicio_PanelAhora, lv_pct(48));
lv_obj_set_x(ui_Inicio_PanelAhora, -79);
lv_obj_set_y(ui_Inicio_PanelAhora, -13);
lv_obj_set_align(ui_Inicio_PanelAhora, LV_ALIGN_CENTER);
lv_obj_clear_flag(ui_Inicio_PanelAhora, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_bg_color(ui_Inicio_PanelAhora, lv_color_hex(0x0EE524), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(ui_Inicio_PanelAhora, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_color(ui_Inicio_PanelAhora, lv_color_hex(0x06FA1F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_Inicio_PanelAhora, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_Label2 = lv_label_create(ui_Inicio_PanelAhora);
lv_obj_set_width(ui_Inicio_Label2, LV_SIZE_CONTENT);
lv_obj_set_height(ui_Inicio_Label2, LV_SIZE_CONTENT);
lv_obj_set_x(ui_Inicio_Label2, -38);
lv_obj_set_y(ui_Inicio_Label2, -37);
lv_obj_set_align(ui_Inicio_Label2, LV_ALIGN_CENTER);
ec_text = textos[0];
lv_label_set_text(ui_Inicio_Label2, ec_text);// "Ahora");
lv_obj_set_style_text_font(ui_Inicio_Label2, &ui_font_Font20, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_Label5 = lv_label_create(ui_Inicio_PanelAhora);
lv_obj_set_width(ui_Inicio_Label5, LV_SIZE_CONTENT);
lv_obj_set_height(ui_Inicio_Label5, LV_SIZE_CONTENT);
lv_obj_set_x(ui_Inicio_Label5, 6);
lv_obj_set_y(ui_Inicio_Label5, 0);
lv_obj_set_align(ui_Inicio_Label5, LV_ALIGN_CENTER);
char dest[6];
strcpy(dest, ":00 h.");
ec_hora = strcat(ec_hora, dest);
lv_label_set_text(ui_Inicio_Label5, ec_hora);
lv_obj_set_style_text_font(ui_Inicio_Label5, &ui_font_Font20, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_PrecioAh = lv_label_create(ui_Inicio_PanelAhora);
lv_obj_set_height(ui_Inicio_PrecioAh, 18);
lv_obj_set_width(ui_Inicio_PrecioAh, lv_pct(98));
lv_obj_set_x(ui_Inicio_PrecioAh, 1);
lv_obj_set_y(ui_Inicio_PrecioAh, 39);
lv_obj_set_align(ui_Inicio_PrecioAh, LV_ALIGN_CENTER);
lv_obj_set_style_text_font(ui_Inicio_PrecioAh, &ui_font_Font16, LV_PART_MAIN | LV_STATE_DEFAULT);
strcpy(dest, " €\/KWh");
ec_prec = strcat(ec_prec, dest);
lv_label_set_text( ui_Inicio_PrecioAh, ec_prec );
ui_Inicio_PanelDespues = lv_obj_create(ui_Inicio);
lv_obj_set_height(ui_Inicio_PanelDespues, 113);
lv_obj_set_width(ui_Inicio_PanelDespues, lv_pct(48));
lv_obj_set_x(ui_Inicio_PanelDespues, 77);
lv_obj_set_y(ui_Inicio_PanelDespues, -13);
lv_obj_set_align(ui_Inicio_PanelDespues, LV_ALIGN_CENTER);
lv_obj_clear_flag(ui_Inicio_PanelDespues, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_bg_opa(ui_Inicio_PanelDespues, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_color(ui_Inicio_PanelDespues, lv_color_hex(0x06FA1F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width(ui_Inicio_PanelDespues, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_Label3 = lv_label_create(ui_Inicio_PanelDespues);
lv_obj_set_width(ui_Inicio_Label3, LV_SIZE_CONTENT);
lv_obj_set_height(ui_Inicio_Label3, LV_SIZE_CONTENT);
lv_obj_set_x(ui_Inicio_Label3, -5);
lv_obj_set_y(ui_Inicio_Label3, -35);
lv_obj_set_align(ui_Inicio_Label3, LV_ALIGN_CENTER);
ec_text = textos[1];
lv_label_set_text(ui_Inicio_Label3, ec_text);//" Mejor hoy");
lv_obj_set_style_text_font(ui_Inicio_Label3, &ui_font_Font20, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_HoraDe = lv_label_create(ui_Inicio_PanelDespues);
lv_obj_set_width(ui_Inicio_HoraDe , LV_SIZE_CONTENT);
lv_obj_set_height(ui_Inicio_HoraDe , LV_SIZE_CONTENT);
lv_obj_set_x(ui_Inicio_HoraDe, 6);
lv_obj_set_y(ui_Inicio_HoraDe, 0);
lv_obj_set_align(ui_Inicio_HoraDe, LV_ALIGN_CENTER);
char desp[6];
strcpy(desp, ":00 h.");
ec_horb = strcat(ec_horb, desp);
lv_label_set_text(ui_Inicio_HoraDe, ec_horb);
lv_obj_set_style_text_font(ui_Inicio_HoraDe, &ui_font_Font20, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_Inicio_PrecioDe = lv_label_create(ui_Inicio_PanelDespues);
lv_obj_set_height(ui_Inicio_PrecioDe, 18);
lv_obj_set_width(ui_Inicio_PrecioDe, lv_pct(100));
lv_obj_set_x(ui_Inicio_PrecioDe, 1);
lv_obj_set_y(ui_Inicio_PrecioDe, 38);
lv_obj_set_align(ui_Inicio_PrecioDe, LV_ALIGN_CENTER);
lv_obj_set_style_text_font(ui_Inicio_PrecioDe, &ui_font_Font16, LV_PART_MAIN | LV_STATE_DEFAULT);
strcpy(desp, " €\/KWh");
ec_preb = strcat(ec_preb, desp);
lv_label_set_text(ui_Inicio_PrecioDe, ec_preb);
ui_Inicio_Porcentaje = lv_label_create(ui_Inicio);
lv_obj_set_width(ui_Inicio_Porcentaje, 150);
lv_obj_set_height(ui_Inicio_Porcentaje, 55);
lv_obj_set_x(ui_Inicio_Porcentaje, 6);
lv_obj_set_y(ui_Inicio_Porcentaje, 85);
lv_obj_set_align(ui_Inicio_Porcentaje, LV_ALIGN_CENTER);
char duno[1];
strcpy(duno, "%");
ec_porc = strcat(ec_porc, duno);
lv_label_set_text(ui_Inicio_Porcentaje, ec_porc);
lv_label_set_recolor(ui_Inicio_Porcentaje, "true");
lv_obj_set_style_text_opa(ui_Inicio_Porcentaje, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_align(ui_Inicio_Porcentaje, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_Inicio_Porcentaje, &ui_font_Big__Font, LV_PART_MAIN | LV_STATE_DEFAULT);
int ret;
strcpy(duno, "0");
if (strncmp(ec_esta, duno, 1) == 0) {
lv_obj_set_style_bg_color(ui_Inicio_PanelAhora, lv_color_hex(0x08C22A), LV_PART_MAIN | LV_STATE_DEFAULT);//0x0BFF01
lv_obj_set_style_text_color(ui_Inicio_Porcentaje, lv_color_hex(0x08C22A), LV_PART_MAIN | LV_STATE_DEFAULT);
}
if (strncmp(ec_estb, duno, 1) == 0) lv_obj_set_style_bg_color(ui_Inicio_PanelDespues, lv_color_hex(0x08C22A), LV_PART_MAIN | LV_STATE_DEFAULT);
strcpy(duno, "1");
if (strncmp(ec_esta, duno, 1) == 0) {
lv_obj_set_style_bg_color(ui_Inicio_PanelAhora, lv_color_hex(0xF7BF05), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(ui_Inicio_Porcentaje, lv_color_hex(0xF7BF05), LV_PART_MAIN | LV_STATE_DEFAULT);
}
if (strncmp(ec_estb, duno, 1) == 0) lv_obj_set_style_bg_color(ui_Inicio_PanelDespues, lv_color_hex(0xF7BF05), LV_PART_MAIN | LV_STATE_DEFAULT);
strcpy(duno, "2");
if (strncmp(ec_esta, duno, 1) == 0) {
lv_obj_set_style_bg_color(ui_Inicio_PanelAhora, lv_color_hex(0xFE0000), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(ui_Inicio_Porcentaje, lv_color_hex(0xFE0000), LV_PART_MAIN | LV_STATE_DEFAULT);
}
if (strncmp(ec_estb, duno, 1) == 0) lv_obj_set_style_bg_color(ui_Inicio_PanelDespues, lv_color_hex(0xFE0000), LV_PART_MAIN | LV_STATE_DEFAULT);
if ( carga == 0 ) {
lv_obj_set_style_bg_color(ui_Inicio_PanelAhora, lv_color_hex(0x6C6868), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(ui_Inicio_Porcentaje, lv_color_hex(0x6C6868), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_color(ui_Inicio_PanelDespues, lv_color_hex(0x6C6868), LV_PART_MAIN | LV_STATE_DEFAULT);
}
lv_obj_add_event_cb(ui_Inicio_PanelAhora, ui_event_Inicio_PanelAhora, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(ui_Inicio_PanelDespues, ui_event_Inicio_PanelDespues, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(ui_Inicio_IBInicio, ui_event_Inicio_IBInicio, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(ui_Inicio_IBProxi, ui_event_Inicio_IBProxi, LV_EVENT_CLICKED, NULL);
}
void ui_init(void) {
w_pais = i_pais;
w_idioma = i_idio;
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),
true, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
ui_Inicio_screen_init();
lv_disp_load_scr( ui_Inicio );
}