diff --git a/src/gfx.c b/src/gfx.c index 8a885b4..dd4c859 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -158,23 +158,27 @@ static int draw_webp(uint8_t *buf, size_t len) { int lastTimestamp = 0; int delay = 0; + TickType_t drawStartTick = xTaskGetTickCount(); // Draw each frame, and sleep for the delay for (int j = 0; j < animation.frame_count; j++) { uint8_t *pix; int timestamp; WebPAnimDecoderGetNext(decoder, &pix, ×tamp); - vTaskDelay(pdMS_TO_TICKS(delay)); + if (delay > 0) + xTaskDelayUntil(&drawStartTick, pdMS_TO_TICKS(delay)); + drawStartTick = xTaskGetTickCount(); display_draw(pix, animation.canvas_width, animation.canvas_height, 4, 0, 1, 2); delay = timestamp - lastTimestamp; lastTimestamp = timestamp; } - vTaskDelay(pdMS_TO_TICKS(delay)); + if (delay > 0) + xTaskDelayUntil(&drawStartTick, pdMS_TO_TICKS(delay)); // In case of a single frame, sleep for 1s if (animation.frame_count == 1) { - vTaskDelay(pdMS_TO_TICKS(1000)); + xTaskDelayUntil(&drawStartTick, pdMS_TO_TICKS(1000)); } WebPAnimDecoderDelete(decoder);