I’m already a little experienced with LVGL and I’m suffering from a problem.
My screen is freezing.
After 20 minutes or 10 minutes (There is no rule, the screen stops updating.)
I’m going to share the code I’m using. Can anyone shed some light on whether I’m using a good practice?
void f_DisplayTempA(void *parameters){
float tempReceivedA, tempReceivedB, tempReceivedC, tempReceivedD;
int tempReceived_Int;
float tempReceivedAntA, tempReceivedAntB, tempReceivedAntC, tempReceivedAntD;
tempReceivedAntA = -200;tempReceivedAntB = -200;tempReceivedAntC = -200;tempReceivedAntD = -200;
char tempC_char[10];
datetime_t received_time;
char dateReceived_char[64];
char timeReceived_char[64];
while(1){
if (xQueueReceive(qSensor_Display_A, &tempReceivedA, pdMS_TO_TICKS(200))){
if (tempReceivedA !=tempReceivedAntA){
tempReceived_Int = (int)tempReceivedA;
sprintf(tempC_char, "%.2fºC", tempReceivedA);
tempReceivedAntA=tempReceivedA;
lock();
lv_meter_set_indicator_end_value(ui->Main_mt_Canal_A, ui->Main_mt_Canal_A_scale_0_arc_0, tempReceived_Int-1);
lv_meter_set_indicator_start_value(ui->Main_mt_Canal_A, ui->Main_mt_Canal_A_scale_0_arc_1, tempReceived_Int);
lv_meter_set_indicator_end_value(ui->Main_mt_Canal_A, ui->Main_mt_Canal_A_scale_0_arc_1, tempReceived_Int+1);
lv_meter_set_indicator_start_value(ui->Main_mt_Canal_A, ui->Main_mt_Canal_A_scale_0_arc_2, tempReceived_Int+2);
lv_label_set_text(ui->Main_lbl_Temp_A, tempC_char);
unlock();
}
}
if (xQueueReceive(qSensor_Display_B, &tempReceivedB, pdMS_TO_TICKS(200))){
if (tempReceivedB !=tempReceivedAntB){
tempReceived_Int = (int)tempReceivedB;
sprintf(tempC_char, "%.2fºC", tempReceivedB);
tempReceivedAntB=tempReceivedB;
lock();
lv_meter_set_indicator_end_value(ui->Main_mt_Canal_B, ui->Main_mt_Canal_B_scale_0_arc_0, tempReceived_Int-1);
lv_meter_set_indicator_start_value(ui->Main_mt_Canal_B, ui->Main_mt_Canal_B_scale_0_arc_1, tempReceived_Int);
lv_meter_set_indicator_end_value(ui->Main_mt_Canal_B, ui->Main_mt_Canal_B_scale_0_arc_1, tempReceived_Int+1);
lv_meter_set_indicator_start_value(ui->Main_mt_Canal_B, ui->Main_mt_Canal_B_scale_0_arc_2, tempReceived_Int+2);
lv_label_set_text(ui->Main_lbl_Temp_B, tempC_char);
unlock();
}
}
if (xQueueReceive(qSensor_Display_C, &tempReceivedC, pdMS_TO_TICKS(200))){
if (tempReceivedC !=tempReceivedAntC){
tempReceived_Int = (int)tempReceivedC;
sprintf(tempC_char, "%.2fºC", tempReceivedC);
tempReceivedAntC=tempReceivedC;
lock();
lv_meter_set_indicator_end_value(ui->Main_mt_Canal_C, ui->Main_mt_Canal_C_scale_0_arc_0, tempReceived_Int-1);
lv_meter_set_indicator_start_value(ui->Main_mt_Canal_C, ui->Main_mt_Canal_C_scale_0_arc_1, tempReceived_Int);
lv_meter_set_indicator_end_value(ui->Main_mt_Canal_C, ui->Main_mt_Canal_C_scale_0_arc_1, tempReceived_Int+1);
lv_meter_set_indicator_start_value(ui->Main_mt_Canal_C, ui->Main_mt_Canal_C_scale_0_arc_2, tempReceived_Int+2);
lv_label_set_text(ui->Main_lbl_Temp_C, tempC_char);
unlock();
}
}
if (xQueueReceive(qSensor_Display_D, &tempReceivedD, pdMS_TO_TICKS(200))){
if (tempReceivedD !=tempReceivedAntD){
tempReceived_Int = (int)tempReceivedD;
//sprintf(tempC_char, "%.2fºC", tempReceived);
sprintf(tempC_char, "%d%%", (int)tempReceivedD);
tempReceivedAntD=tempReceivedD;
lock();
lv_meter_set_indicator_end_value(ui->Main_mt_Canal_D, ui->Main_mt_Canal_D_scale_0_arc_0, tempReceived_Int);
lv_label_set_text(ui->Main_lbl_Hum, tempC_char);
unlock();
}
}
if (xQueueReceive(qDataHora, &received_time, pdMS_TO_TICKS(200))) {
snprintf(dateReceived_char, sizeof(timeReceived_char),"%02d/%02d/%d",received_time.day, received_time.month, received_time.year);
snprintf(timeReceived_char, sizeof(timeReceived_char),"%02d:%02d:%02d", received_time.hour, received_time.minute, received_time.second);
lock();
lv_label_set_text(ui->Main_lbl_Data, dateReceived_char);
lv_label_set_text(ui->Main_lbl_Hora, timeReceived_char);
unlock();
}
vTaskDelay(400 / portTICK_PERIOD_MS);
}
}
and the code:
void f_updateScreen(void *arg){
ESP_LOGI(TAG, "Starting LVGL task");
while (1) {
lock();
lv_timer_handler();
unlock();
vTaskDelay(pdMS_TO_TICKS(10));
}
}
//void lock(){if (xSemaphoreDisplay!=NULL){xSemaphoreTake(xSemaphoreDisplay, pdMS_TO_TICKS(200));}}
void lock(){if (xSemaphoreDisplay!=NULL){xSemaphoreTake(xSemaphoreDisplay, portMAX_DELAY);}}
void unlock(){if (xSemaphoreDisplay!=NULL){xSemaphoreGive(xSemaphoreDisplay);}}
In the case in question, I cannot call lv_timer_handler() within the f_DisplayTempA() loop because sometimes other visual elements are called such as email sending, error, successful sending, etc…
My problem is that the screen is freezing. After a few minutes of use, the screen freezes…although the freeRTOs tasks continue to work.
Where am I going wrong??
Please help me?