Sat, 20 Oct 2018 17:09:48 +0200
Updated lots of doxygen comments
0 | 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 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
10 | #define PIEZO_BUZZER CONFIG_BUZZER_GPIO ///< GPIO pin with the piezo buzzer. |
0 | 11 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
12 | EventGroupHandle_t xEventGroupSound; ///< Event handle. |
0 | 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 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
26 | /* Sound arrays. The first value is the length, followed by the on and off times. */ |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
27 | static const uint16_t _sound_Startup[] = { 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 200, |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
28 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
29 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
30 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
31 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
32 | static const uint16_t _sound_Prompt[] = { 2, 50, 125 }; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
33 | static const uint16_t _sound_TempReached[] = { 6, 250, 75, 250, 75, 250, 75}; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
34 | static const uint16_t _sound_TimeOut[] = { 10, 25, 975, 25, 975, 25, 975, 25, 975, 500, 500 }; // 5 seconds |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
35 | static const uint16_t _sound_AddHop[] = { 18, 50, 50, 50, 50, 50, 225, 150, 50, 150, 50, 150, 225, 50, 50, 50 , 50 , 50, 50 }; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
36 | static const uint16_t _sound_End[] = { 2, 1000, 75 }; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
37 | static const uint16_t _sound_Warn[] = { 6, 100, 75, 100, 75, 100, 50 }; |
0 | 38 | |
39 | ||
40 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
41 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
42 | * @brief Play sounds on the piezo buzzer. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
43 | * @param sound The sound array. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
44 | */ |
0 | 45 | void BuzzerPlay(const uint16_t *sound) |
46 | { | |
47 | for (int i = 1; i <= sound[0]; i += 2) { | |
48 | gpio_set_level(PIEZO_BUZZER, 1); | |
49 | vTaskDelay(sound[i] / portTICK_PERIOD_MS); | |
50 | gpio_set_level(PIEZO_BUZZER, 0); | |
51 | vTaskDelay(sound[i+1] / portTICK_PERIOD_MS); | |
52 | } | |
53 | ||
54 | gpio_set_level(PIEZO_BUZZER, 0); // Just make sure the sound is off. | |
55 | } | |
56 | ||
57 | ||
58 | ||
59 | void SoundPlay(int id) | |
60 | { | |
61 | switch (id) { | |
62 | case SOUND_StartUp: xEventGroupSetBits(xEventGroupSound, SOUND_STARTUP); | |
63 | break; | |
64 | ||
65 | case SOUND_Prompt: xEventGroupSetBits(xEventGroupSound, SOUND_PROMPT); | |
66 | break; | |
67 | ||
68 | case SOUND_TempReached: xEventGroupSetBits(xEventGroupSound, SOUND_TEMPREACHED); | |
69 | break; | |
70 | ||
71 | case SOUND_TimeOut: xEventGroupSetBits(xEventGroupSound, SOUND_TIMEOUT); | |
72 | break; | |
73 | ||
74 | case SOUND_AddHop: xEventGroupSetBits(xEventGroupSound, SOUND_ADDHOP); | |
75 | break; | |
76 | ||
77 | case SOUND_End: xEventGroupSetBits(xEventGroupSound, SOUND_END); | |
78 | break; | |
79 | ||
80 | case SOUND_Warn: xEventGroupSetBits(xEventGroupSound, SOUND_WARN); | |
81 | break; | |
82 | } | |
83 | } | |
84 | ||
85 | ||
86 | ||
87 | void task_sound(void *pvParameter) | |
88 | { | |
89 | EventBits_t uxBits; | |
90 | ||
91 | ESP_LOGI(TAG, "Starting sound"); | |
92 | ||
93 | gpio_pad_select_gpio(PIEZO_BUZZER); | |
94 | gpio_set_direction(PIEZO_BUZZER, GPIO_MODE_OUTPUT); | |
95 | ||
96 | xEventGroupSound = xEventGroupCreate(); | |
97 | ||
98 | while (1) { | |
99 | uxBits = xEventGroupWaitBits(xEventGroupSound, | |
100 | SOUND_STARTUP | SOUND_PROMPT | SOUND_TEMPREACHED | SOUND_TIMEOUT | SOUND_ADDHOP | SOUND_END | SOUND_WARN, | |
101 | pdFALSE, pdFALSE, portMAX_DELAY ); | |
102 | ||
103 | if (uxBits & SOUND_STARTUP) { | |
104 | BuzzerPlay(_sound_Startup); | |
105 | xEventGroupClearBits(xEventGroupSound, SOUND_STARTUP); | |
106 | } | |
107 | if (uxBits & SOUND_PROMPT) { | |
108 | VncSoundBell(); | |
109 | BuzzerPlay(_sound_Prompt); | |
110 | xEventGroupClearBits(xEventGroupSound, SOUND_PROMPT); | |
111 | } | |
112 | if (uxBits & SOUND_TEMPREACHED) { | |
113 | VncSoundBell(); | |
114 | BuzzerPlay(_sound_TempReached); | |
115 | VncSoundBell(); | |
116 | xEventGroupClearBits(xEventGroupSound, SOUND_TEMPREACHED); | |
117 | } | |
118 | if (uxBits & SOUND_TIMEOUT) { | |
119 | BuzzerPlay(_sound_TimeOut); | |
120 | xEventGroupClearBits(xEventGroupSound, SOUND_TIMEOUT); | |
121 | } | |
122 | if (uxBits & SOUND_ADDHOP) { | |
123 | VncSoundBell(); | |
124 | VncSoundBell(); | |
125 | BuzzerPlay(_sound_AddHop); | |
126 | VncSoundBell(); | |
127 | VncSoundBell(); | |
128 | xEventGroupClearBits(xEventGroupSound, SOUND_ADDHOP); | |
129 | } | |
130 | if (uxBits & SOUND_END) { | |
131 | BuzzerPlay(_sound_End); | |
132 | xEventGroupClearBits(xEventGroupSound, SOUND_END); | |
133 | } | |
134 | if (uxBits & SOUND_WARN) { | |
135 | VncSoundBell(); | |
136 | BuzzerPlay(_sound_Warn); | |
137 | xEventGroupClearBits(xEventGroupSound, SOUND_WARN); | |
138 | } | |
139 | ||
140 | vTaskDelay(10 / portTICK_PERIOD_MS); | |
141 | } | |
142 | } | |
143 | ||
144 |