Skip to content

Commit

Permalink
gfx: Properly set graphics thread delay (#6)
Browse files Browse the repository at this point in the history
* Properly set graphics thread delay

* Handle single frame case
  • Loading branch information
nnhien committed Aug 31, 2023
1 parent 8dbcdca commit 2486250
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &timestamp);
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);
Expand Down

0 comments on commit 2486250

Please sign in to comment.