Skip to content

Commit 802304f

Browse files
committed
add event struct to make code easier to understand
1 parent 7cc48ce commit 802304f

File tree

6 files changed

+170
-0
lines changed

6 files changed

+170
-0
lines changed

main/inc/system/event.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* event.c
3+
*
4+
* Created on: 2018-03-04 20:07
5+
* Author: Jack Chen <redchenjs@live.com>
6+
*/
7+
8+
#ifndef INC_SYSTEM_EVENT_C_
9+
#define INC_SYSTEM_EVENT_C_
10+
11+
#include "freertos/FreeRTOS.h"
12+
#include "freertos/event_groups.h"
13+
14+
enum task_event_group_bits {
15+
MP3_PLAYER_READY_BIT = BIT0,
16+
GUI_RELOAD_BIT = BIT1
17+
};
18+
19+
extern EventGroupHandle_t task_event_group;
20+
21+
extern void event_init(void);
22+
23+
#endif /* INC_SYSTEM_EVENT_C_ */

main/inc/system/task.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* task.h
3+
*
4+
* Created on: 2018-02-16 18:00
5+
* Author: Jack Chen <redchenjs@live.com>
6+
*/
7+
8+
#ifndef INC_SYSTEM_TASK_H_
9+
#define INC_SYSTEM_TASK_H_
10+
11+
extern void task_init(void);
12+
13+
#endif /* INC_SYSTEM_TASK_H_ */

main/inc/tasks/gui_task.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* gui_task.h
3+
*
4+
* Created on: 2018-02-13 22:57
5+
* Author: Jack Chen <redchenjs@live.com>
6+
*/
7+
8+
#ifndef INC_TASKS_GUI_TASK_H_
9+
#define INC_TASKS_GUI_TASK_H_
10+
11+
#include <stdint.h>
12+
13+
// ani0.gif
14+
extern const uint8_t ani0_gif_ptr[] asm("_binary_ani0_gif_start");
15+
extern const uint8_t ani0_gif_end[] asm("_binary_ani0_gif_end");
16+
// ani1.gif
17+
extern const uint8_t ani1_gif_ptr[] asm("_binary_ani1_gif_start");
18+
extern const uint8_t ani1_gif_end[] asm("_binary_ani1_gif_end");
19+
// ani2.gif
20+
extern const uint8_t ani2_gif_ptr[] asm("_binary_ani2_gif_start");
21+
extern const uint8_t ani2_gif_end[] asm("_binary_ani2_gif_end");
22+
// ani3.gif
23+
extern const uint8_t ani3_gif_ptr[] asm("_binary_ani3_gif_start");
24+
extern const uint8_t ani3_gif_end[] asm("_binary_ani3_gif_end");
25+
26+
extern void gui_show_image(uint8_t filename_index);
27+
extern void gui_task(void *pvParameter);
28+
29+
#endif /* INC_TASKS_GUI_TASK_H_ */

main/src/system/event.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* event.c
3+
*
4+
* Created on: 2018-03-04 20:07
5+
* Author: Jack Chen <redchenjs@live.com>
6+
*/
7+
8+
#include "freertos/FreeRTOS.h"
9+
#include "freertos/event_groups.h"
10+
11+
#define TAG "event"
12+
13+
EventGroupHandle_t task_event_group;
14+
15+
void event_init(void)
16+
{
17+
task_event_group = xEventGroupCreate();
18+
}

main/src/system/task.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* task.c
3+
*
4+
* Created on: 2018-02-16 18:00
5+
* Author: Jack Chen <redchenjs@live.com>
6+
*/
7+
8+
#include "freertos/FreeRTOS.h"
9+
#include "freertos/task.h"
10+
11+
#include "tasks/gui_task.h"
12+
#include "tasks/mp3_player.h"
13+
#include "tasks/bt_speaker.h"
14+
#include "tasks/led_indicator.h"
15+
16+
void task_init(void)
17+
{
18+
xTaskCreate(gui_task, "gui_task", 2048, NULL, 5, NULL);
19+
xTaskCreate(mp3_player_task, "mp3_player_task", 8192, NULL, 5, NULL);
20+
xTaskCreate(bt_speaker_task, "bt_speaker_task", 2560, NULL, 5, NULL);
21+
xTaskCreate(led_indicator_task, "led_indicator_task", 1024, NULL, 5, NULL);
22+
}

main/src/tasks/gui_task.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)