** Function name: progressHandler ** Description: Função para manipular o progresso da atualização ** Dependencia: prog_handler =>> 0 - Flash, 1 - SPIFFS ***************************************************************************************/
| 449 | ** Dependencia: prog_handler =>> 0 - Flash, 1 - SPIFFS |
| 450 | ***************************************************************************************/ |
| 451 | void progressHandler(size_t progress, size_t total) { |
| 452 | vTaskDelay(pdMS_TO_TICKS(2)); |
| 453 | tft->drawPixel(0, 0, 0); |
| 454 | #if defined(E_PAPER_DISPLAY) |
| 455 | static unsigned long lastUpdate = 0; |
| 456 | #endif |
| 457 | static unsigned long lastProgressDraw = 0; |
| 458 | static size_t lastProgressBarWidth = 0; |
| 459 | double fraction = (double)progress / (double)total; |
| 460 | double barWidthFloat = (tftWidth - 40) * fraction; |
| 461 | size_t barWidth = static_cast<size_t>(barWidthFloat); |
| 462 | // Serial.printf("Total: %d, Progress: %d, Progress bar width: %d \n", total, progress, barWidth); |
| 463 | if (progress == 0) { |
| 464 | lastProgressDraw = launcherMillis(); |
| 465 | lastProgressBarWidth = 0; |
| 466 | tft->setTextSize(FM); |
| 467 | tft->setTextColor(ALCOLOR); |
| 468 | tft->fillRoundRect(6, 6, tftWidth - 12, tftHeight - 12, 5, BGCOLOR); |
| 469 | #if TFT_HEIGHT > 200 |
| 470 | tft->drawCentreString("-=Launcher=-", tftWidth / 2, 20, 1); |
| 471 | #else |
| 472 | tft->drawCentreString("-=Launcher=-", tftWidth / 2, 10, 1); |
| 473 | #endif |
| 474 | tft->drawRoundRect(5, 5, tftWidth - 10, tftHeight - 10, 5, FGCOLOR); |
| 475 | if (prog_handler == 1) { |
| 476 | tft->drawRect(18, tftHeight - 28, tftWidth - 36, 17, ALCOLOR); |
| 477 | tft->fillRect(20, tftHeight - 26, tftWidth - 40, 13, BGCOLOR); |
| 478 | } else tft->drawRect(18, tftHeight - 47, tftWidth - 36, 17, FGCOLOR); |
| 479 | |
| 480 | String txt; |
| 481 | switch (prog_handler) { |
| 482 | case 0: txt = "Installing FW"; break; |
| 483 | case 1: txt = "Copying Data"; break; |
| 484 | case 2: txt = "Downloading"; break; |
| 485 | } |
| 486 | displayRedStripe(txt); |
| 487 | } |
| 488 | if (progress > 0 && progress < total) { |
| 489 | unsigned long now = launcherMillis(); |
| 490 | if (barWidth == lastProgressBarWidth || now - lastProgressDraw < 80) { |
| 491 | wakeUpScreen(); |
| 492 | return; |
| 493 | } |
| 494 | lastProgressDraw = now; |
| 495 | lastProgressBarWidth = barWidth; |
| 496 | } |
| 497 | |
| 498 | if (prog_handler == 1) tft->fillRect(20, tftHeight - 26, barWidth, 13, ALCOLOR); |
| 499 | else tft->fillRect(20, tftHeight - 45, barWidth, 13, FGCOLOR); |
| 500 | |
| 501 | #if defined(E_PAPER_DISPLAY) && (defined(GxEPD2_DISPLAY) || defined(USE_M5GFX)) |
| 502 | if (launcherMillis() - lastUpdate > 2000) { |
| 503 | tft->display(); |
| 504 | lastUpdate = launcherMillis(); |
| 505 | } |
| 506 | #else |
| 507 | tft->display(); |
| 508 | #endif |
no test coverage detected