Reading Colleague’s Post,
Yes, every function that refers to LVGL, both TimerHandle and others such as SetText, must share the same Mutex lock.
I have already implemented your suggestions, such as separating tasks.
It looked like this:
void v_AtualizaDisplay(void *parameters){
while(1){
if (xSemaphoreTake(xMutex, portMAX_DELAY)) {
lv_timer_handler();
xSemaphoreGive(xMutex);
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
void v_DisplayTemp(void *parameters){
float tempReceived;
float tempReceivedAnt;
char tempC_char[20];
while(1){
if (xQueueReceive(TempC_Queue, &tempReceived, portMAX_DELAY)){
if (tempReceived !=tempReceivedAnt){
sprintf(tempC_char, "%.2fºC", tempReceived);
tempReceivedAnt=tempReceived;
lv_meter_set_indicator_value(MyGauge[0], indic1[0], tempReceived);
lv_label_set_text(ui_lblTemp, tempC_char);
}
}
vTaskDelay(30 / portTICK_PERIOD_MS);
}
}
void v_DisplayHora(void *parameters){
char timeReceived_char[64];
while(1){
xQueueReceive(datahora_formatadaX_Queue, &timeReceived_char, 50);
if (xSemaphoreTake(xMutex, portMAX_DELAY)) {
lv_label_set_text(ui_lblDataHora, timeReceived_char);
xSemaphoreGive(xMutex);
}
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}
void v_DisplayUptime(void *parameters){
String systemUpTime;
while(1){
uptime::calculateUptime();
if (xSemaphoreTake(xMutex, 300)) {
systemUpTime = String("Uptime: ") + String(uptime::getDays())+"d "+String(uptime::getHours())+":"+String(uptime::getMinutes())+":"+String(uptime::getSeconds());
lv_label_set_text(ui_lblUptime, systemUpTime.c_str());
xSemaphoreGive(xMutex);
}
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}