|
| 1 | +/* |
| 2 | + * gui_task.c |
| 3 | + * |
| 4 | + * Created on: 2018-02-13 22:57 |
| 5 | + * Author: Jack Chen <redchenjs@live.com> |
| 6 | + */ |
| 7 | + |
| 8 | +#include "gfx.h" |
| 9 | +#include "esp_log.h" |
| 10 | + |
| 11 | +#include "system/event.h" |
| 12 | +#include "tasks/gui_task.h" |
| 13 | + |
| 14 | +#define TAG "gui_task" |
| 15 | + |
| 16 | +static const uint8_t *img_file_ptr[][2] = { |
| 17 | + {ani0_gif_ptr, ani0_gif_end}, // "Bluetooth" |
| 18 | + {ani1_gif_ptr, ani1_gif_end}, // "Standby" |
| 19 | + {ani2_gif_ptr, ani2_gif_end}, // "Pause" |
| 20 | + {ani3_gif_ptr, ani3_gif_end} // "Playing" |
| 21 | + }; |
| 22 | +uint8_t img_file_index = 0; |
| 23 | + |
| 24 | +void gui_show_image(uint8_t filename_index) |
| 25 | +{ |
| 26 | + if (filename_index >= (sizeof(img_file_ptr) / 2)) { |
| 27 | + ESP_LOGE(TAG, "invalid filename index"); |
| 28 | + return; |
| 29 | + } |
| 30 | + img_file_index = filename_index; |
| 31 | + xEventGroupSetBits(task_event_group, GUI_RELOAD_BIT); |
| 32 | +} |
| 33 | + |
| 34 | +void gui_task(void *pvParameter) |
| 35 | +{ |
| 36 | + gfxInit(); |
| 37 | + |
| 38 | + while (1) { |
| 39 | + gdispImage gfx_image; |
| 40 | + if (!(gdispImageOpenMemory(&gfx_image, img_file_ptr[img_file_index][0]) & GDISP_IMAGE_ERR_UNRECOVERABLE)) { |
| 41 | + gdispImageSetBgColor(&gfx_image, White); |
| 42 | + while (1) { |
| 43 | + if (xEventGroupGetBits(task_event_group) & GUI_RELOAD_BIT) { |
| 44 | + xEventGroupClearBits(task_event_group, GUI_RELOAD_BIT); |
| 45 | + break; |
| 46 | + } |
| 47 | + if (gdispImageDraw(&gfx_image, 0, 0, gfx_image.width, gfx_image.height, 0, 0) != GDISP_IMAGE_ERR_OK) { |
| 48 | + break; |
| 49 | + } |
| 50 | + delaytime_t delay = gdispImageNext(&gfx_image); |
| 51 | + if (delay == TIME_INFINITE) { |
| 52 | + break; |
| 53 | + } |
| 54 | + if (delay != TIME_IMMEDIATE) { |
| 55 | + gfxSleepMilliseconds(delay); |
| 56 | + } |
| 57 | + } |
| 58 | + gdispImageClose(&gfx_image); |
| 59 | + } else { |
| 60 | + break; |
| 61 | + } |
| 62 | + } |
| 63 | + ESP_LOGE(TAG, "task failed, rebooting..."); |
| 64 | + esp_restart(); |
| 65 | +} |
0 commit comments