main/task_sound.c

changeset 0
b74b0e4902c3
child 1
ad2c8b13eb88
equal deleted inserted replaced
-1:000000000000 0:b74b0e4902c3
1 /**
2 * @file task_sound.c
3 * @brief BrewBoard Sound driver. Plays WAVE audio, Microsoft PCM, 8 bit, mono 16000 Hz
4 * files from the /spiffs/sound/ directory.
5 */
6
7 #include "config.h"
8
9
10 #define PIEZO_BUZZER CONFIG_BUZZER_GPIO
11
12 EventGroupHandle_t xEventGroupSound;
13
14
15 static const char *TAG = "task_sound";
16
17 const int SOUND_STARTUP = BIT0; ///< When set, play startup sound.
18 const int SOUND_PROMPT = BIT1; ///< When set, play prompt sound.
19 const int SOUND_TEMPREACHED = BIT2; ///< When set, play temperature reached sound.
20 const int SOUND_TIMEOUT = BIT3; ///< When set, play time out sound.
21 const int SOUND_ADDHOP = BIT4; ///< When set, play add hop sound.
22 const int SOUND_END = BIT5; ///< When set, play finished sound.
23 const int SOUND_WARN = BIT6; ///< When set, play warning sound.
24
25
26 const uint16_t _sound_Startup[] = { 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 200,
27 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
28 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
29 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
30 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 };
31 const uint16_t _sound_Prompt[] = { 2, 50, 125 };
32 const uint16_t _sound_TempReached[] = { 6, 250, 75, 250, 75, 250, 75};
33 const uint16_t _sound_TimeOut[] = {10, 25, 975, 25, 975, 25, 975, 25, 975, 500, 500 }; // 5 seconds
34 const uint16_t _sound_AddHop[] = {18, 50, 50, 50, 50, 50, 225, 150, 50, 150, 50, 150, 225, 50, 50, 50 , 50 , 50, 50 };
35 const uint16_t _sound_End[] = { 2, 1000, 75 };
36 const uint16_t _sound_Warn[] = { 6, 100, 75, 100, 75, 100, 50 };
37
38
39
40 void BuzzerPlay(const uint16_t *sound)
41 {
42 for (int i = 1; i <= sound[0]; i += 2) {
43 gpio_set_level(PIEZO_BUZZER, 1);
44 vTaskDelay(sound[i] / portTICK_PERIOD_MS);
45 gpio_set_level(PIEZO_BUZZER, 0);
46 vTaskDelay(sound[i+1] / portTICK_PERIOD_MS);
47 }
48
49 gpio_set_level(PIEZO_BUZZER, 0); // Just make sure the sound is off.
50 }
51
52
53
54 void SoundPlay(int id)
55 {
56 switch (id) {
57 case SOUND_StartUp: xEventGroupSetBits(xEventGroupSound, SOUND_STARTUP);
58 break;
59
60 case SOUND_Prompt: xEventGroupSetBits(xEventGroupSound, SOUND_PROMPT);
61 break;
62
63 case SOUND_TempReached: xEventGroupSetBits(xEventGroupSound, SOUND_TEMPREACHED);
64 break;
65
66 case SOUND_TimeOut: xEventGroupSetBits(xEventGroupSound, SOUND_TIMEOUT);
67 break;
68
69 case SOUND_AddHop: xEventGroupSetBits(xEventGroupSound, SOUND_ADDHOP);
70 break;
71
72 case SOUND_End: xEventGroupSetBits(xEventGroupSound, SOUND_END);
73 break;
74
75 case SOUND_Warn: xEventGroupSetBits(xEventGroupSound, SOUND_WARN);
76 break;
77 }
78 }
79
80
81
82 void task_sound(void *pvParameter)
83 {
84 EventBits_t uxBits;
85
86 ESP_LOGI(TAG, "Starting sound");
87
88 gpio_pad_select_gpio(PIEZO_BUZZER);
89 gpio_set_direction(PIEZO_BUZZER, GPIO_MODE_OUTPUT);
90
91 xEventGroupSound = xEventGroupCreate();
92
93 while (1) {
94 uxBits = xEventGroupWaitBits(xEventGroupSound,
95 SOUND_STARTUP | SOUND_PROMPT | SOUND_TEMPREACHED | SOUND_TIMEOUT | SOUND_ADDHOP | SOUND_END | SOUND_WARN,
96 pdFALSE, pdFALSE, portMAX_DELAY );
97
98 if (uxBits & SOUND_STARTUP) {
99 BuzzerPlay(_sound_Startup);
100 xEventGroupClearBits(xEventGroupSound, SOUND_STARTUP);
101 }
102 if (uxBits & SOUND_PROMPT) {
103 VncSoundBell();
104 BuzzerPlay(_sound_Prompt);
105 xEventGroupClearBits(xEventGroupSound, SOUND_PROMPT);
106 }
107 if (uxBits & SOUND_TEMPREACHED) {
108 VncSoundBell();
109 BuzzerPlay(_sound_TempReached);
110 VncSoundBell();
111 xEventGroupClearBits(xEventGroupSound, SOUND_TEMPREACHED);
112 }
113 if (uxBits & SOUND_TIMEOUT) {
114 BuzzerPlay(_sound_TimeOut);
115 xEventGroupClearBits(xEventGroupSound, SOUND_TIMEOUT);
116 }
117 if (uxBits & SOUND_ADDHOP) {
118 VncSoundBell();
119 VncSoundBell();
120 BuzzerPlay(_sound_AddHop);
121 VncSoundBell();
122 VncSoundBell();
123 xEventGroupClearBits(xEventGroupSound, SOUND_ADDHOP);
124 }
125 if (uxBits & SOUND_END) {
126 BuzzerPlay(_sound_End);
127 xEventGroupClearBits(xEventGroupSound, SOUND_END);
128 }
129 if (uxBits & SOUND_WARN) {
130 VncSoundBell();
131 BuzzerPlay(_sound_Warn);
132 xEventGroupClearBits(xEventGroupSound, SOUND_WARN);
133 }
134
135 vTaskDelay(10 / portTICK_PERIOD_MS);
136 }
137 }
138
139

mercurial