Fri, 05 Jul 2019 16:14:58 +0200
Version 0.3.5
0 | 1 | /** |
2 | * @file task_sound.c | |
4 | 3 | * @brief BrewBoard Sound driver. Uses a simple piezo buzzer. |
0 | 4 | */ |
5 | ||
6 | #include "config.h" | |
7 | ||
8 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
9 | #define PIEZO_BUZZER CONFIG_BUZZER_GPIO ///< GPIO pin with the piezo buzzer. |
0 | 10 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
11 | EventGroupHandle_t xEventGroupSound; ///< Event handle. |
0 | 12 | |
13 | ||
14 | static const char *TAG = "task_sound"; | |
15 | ||
16 | const int SOUND_STARTUP = BIT0; ///< When set, play startup sound. | |
17 | const int SOUND_PROMPT = BIT1; ///< When set, play prompt sound. | |
18 | const int SOUND_TEMPREACHED = BIT2; ///< When set, play temperature reached sound. | |
19 | const int SOUND_TIMEOUT = BIT3; ///< When set, play time out sound. | |
20 | const int SOUND_ADDHOP = BIT4; ///< When set, play add hop sound. | |
21 | const int SOUND_END = BIT5; ///< When set, play finished sound. | |
22 | const int SOUND_WARN = BIT6; ///< When set, play warning sound. | |
23 | ||
24 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
25 | /* 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
|
26 | 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
|
27 | 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
|
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 | static const uint16_t _sound_Prompt[] = { 2, 50, 125 }; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
32 | 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
|
33 | 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
|
34 | 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
|
35 | static const uint16_t _sound_End[] = { 2, 1000, 75 }; |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
36 | static const uint16_t _sound_Warn[] = { 6, 100, 75, 100, 75, 100, 50 }; |
0 | 37 | |
38 | ||
39 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
40 | /** |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
41 | * @brief Play sounds on the piezo buzzer. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
42 | * @param sound The sound array. |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
43 | */ |
0 | 44 | void BuzzerPlay(const uint16_t *sound) |
45 | { | |
42 | 46 | char msg[16]; |
47 | ||
0 | 48 | for (int i = 1; i <= sound[0]; i += 2) { |
42 | 49 | if (sound != _sound_Startup) { |
50 | snprintf(msg, 15, "{\"beep\":\"1\"}"); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
43
diff
changeset
|
51 | ws_server_send_text_clients((char *)"/ws", msg, strlen(msg)); |
42 | 52 | } |
43
2079940c3989
Fixed missing whirlpool 88+ degrees. Some code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
53 | gpio_set_level(PIEZO_BUZZER, 1); |
0 | 54 | vTaskDelay(sound[i] / portTICK_PERIOD_MS); |
55 | gpio_set_level(PIEZO_BUZZER, 0); | |
56 | vTaskDelay(sound[i+1] / portTICK_PERIOD_MS); | |
57 | } | |
58 | ||
59 | gpio_set_level(PIEZO_BUZZER, 0); // Just make sure the sound is off. | |
60 | } | |
61 | ||
62 | ||
63 | ||
64 | void SoundPlay(int id) | |
65 | { | |
66 | switch (id) { | |
67 | case SOUND_StartUp: xEventGroupSetBits(xEventGroupSound, SOUND_STARTUP); | |
68 | break; | |
69 | ||
70 | case SOUND_Prompt: xEventGroupSetBits(xEventGroupSound, SOUND_PROMPT); | |
71 | break; | |
72 | ||
73 | case SOUND_TempReached: xEventGroupSetBits(xEventGroupSound, SOUND_TEMPREACHED); | |
74 | break; | |
75 | ||
76 | case SOUND_TimeOut: xEventGroupSetBits(xEventGroupSound, SOUND_TIMEOUT); | |
77 | break; | |
78 | ||
79 | case SOUND_AddHop: xEventGroupSetBits(xEventGroupSound, SOUND_ADDHOP); | |
80 | break; | |
81 | ||
82 | case SOUND_End: xEventGroupSetBits(xEventGroupSound, SOUND_END); | |
83 | break; | |
84 | ||
85 | case SOUND_Warn: xEventGroupSetBits(xEventGroupSound, SOUND_WARN); | |
86 | break; | |
87 | } | |
88 | } | |
89 | ||
90 | ||
91 | ||
92 | void task_sound(void *pvParameter) | |
93 | { | |
94 | EventBits_t uxBits; | |
95 | ||
96 | ESP_LOGI(TAG, "Starting sound"); | |
97 | ||
98 | gpio_pad_select_gpio(PIEZO_BUZZER); | |
99 | gpio_set_direction(PIEZO_BUZZER, GPIO_MODE_OUTPUT); | |
100 | ||
101 | xEventGroupSound = xEventGroupCreate(); | |
102 | ||
103 | while (1) { | |
104 | uxBits = xEventGroupWaitBits(xEventGroupSound, | |
105 | SOUND_STARTUP | SOUND_PROMPT | SOUND_TEMPREACHED | SOUND_TIMEOUT | SOUND_ADDHOP | SOUND_END | SOUND_WARN, | |
106 | pdFALSE, pdFALSE, portMAX_DELAY ); | |
107 | ||
108 | if (uxBits & SOUND_STARTUP) { | |
109 | BuzzerPlay(_sound_Startup); | |
110 | xEventGroupClearBits(xEventGroupSound, SOUND_STARTUP); | |
111 | } | |
112 | if (uxBits & SOUND_PROMPT) { | |
113 | BuzzerPlay(_sound_Prompt); | |
114 | xEventGroupClearBits(xEventGroupSound, SOUND_PROMPT); | |
115 | } | |
116 | if (uxBits & SOUND_TEMPREACHED) { | |
117 | BuzzerPlay(_sound_TempReached); | |
118 | xEventGroupClearBits(xEventGroupSound, SOUND_TEMPREACHED); | |
119 | } | |
120 | if (uxBits & SOUND_TIMEOUT) { | |
121 | BuzzerPlay(_sound_TimeOut); | |
122 | xEventGroupClearBits(xEventGroupSound, SOUND_TIMEOUT); | |
123 | } | |
124 | if (uxBits & SOUND_ADDHOP) { | |
125 | BuzzerPlay(_sound_AddHop); | |
126 | xEventGroupClearBits(xEventGroupSound, SOUND_ADDHOP); | |
127 | } | |
128 | if (uxBits & SOUND_END) { | |
129 | BuzzerPlay(_sound_End); | |
130 | xEventGroupClearBits(xEventGroupSound, SOUND_END); | |
131 | } | |
132 | if (uxBits & SOUND_WARN) { | |
133 | BuzzerPlay(_sound_Warn); | |
134 | xEventGroupClearBits(xEventGroupSound, SOUND_WARN); | |
135 | } | |
136 | ||
137 | vTaskDelay(10 / portTICK_PERIOD_MS); | |
138 | } | |
139 | } | |
140 | ||
141 |