Mon, 22 Oct 2018 21:43:45 +0200
Updated esp-ide. Removed VNC server corre encoding because no clients would use it. Enabled WiFi error logmessages. Write runtime record is now debug logging. Removed recipe.Record number, not usefull and was wrong too. Removed console print of json log data.
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 | { | |
46 | for (int i = 1; i <= sound[0]; i += 2) { | |
47 | gpio_set_level(PIEZO_BUZZER, 1); | |
48 | vTaskDelay(sound[i] / portTICK_PERIOD_MS); | |
49 | gpio_set_level(PIEZO_BUZZER, 0); | |
50 | vTaskDelay(sound[i+1] / portTICK_PERIOD_MS); | |
51 | } | |
52 | ||
53 | gpio_set_level(PIEZO_BUZZER, 0); // Just make sure the sound is off. | |
54 | } | |
55 | ||
56 | ||
57 | ||
58 | void SoundPlay(int id) | |
59 | { | |
60 | switch (id) { | |
61 | case SOUND_StartUp: xEventGroupSetBits(xEventGroupSound, SOUND_STARTUP); | |
62 | break; | |
63 | ||
64 | case SOUND_Prompt: xEventGroupSetBits(xEventGroupSound, SOUND_PROMPT); | |
65 | break; | |
66 | ||
67 | case SOUND_TempReached: xEventGroupSetBits(xEventGroupSound, SOUND_TEMPREACHED); | |
68 | break; | |
69 | ||
70 | case SOUND_TimeOut: xEventGroupSetBits(xEventGroupSound, SOUND_TIMEOUT); | |
71 | break; | |
72 | ||
73 | case SOUND_AddHop: xEventGroupSetBits(xEventGroupSound, SOUND_ADDHOP); | |
74 | break; | |
75 | ||
76 | case SOUND_End: xEventGroupSetBits(xEventGroupSound, SOUND_END); | |
77 | break; | |
78 | ||
79 | case SOUND_Warn: xEventGroupSetBits(xEventGroupSound, SOUND_WARN); | |
80 | break; | |
81 | } | |
82 | } | |
83 | ||
84 | ||
85 | ||
86 | void task_sound(void *pvParameter) | |
87 | { | |
88 | EventBits_t uxBits; | |
89 | ||
90 | ESP_LOGI(TAG, "Starting sound"); | |
91 | ||
92 | gpio_pad_select_gpio(PIEZO_BUZZER); | |
93 | gpio_set_direction(PIEZO_BUZZER, GPIO_MODE_OUTPUT); | |
94 | ||
95 | xEventGroupSound = xEventGroupCreate(); | |
96 | ||
97 | while (1) { | |
98 | uxBits = xEventGroupWaitBits(xEventGroupSound, | |
99 | SOUND_STARTUP | SOUND_PROMPT | SOUND_TEMPREACHED | SOUND_TIMEOUT | SOUND_ADDHOP | SOUND_END | SOUND_WARN, | |
100 | pdFALSE, pdFALSE, portMAX_DELAY ); | |
101 | ||
102 | if (uxBits & SOUND_STARTUP) { | |
103 | BuzzerPlay(_sound_Startup); | |
104 | xEventGroupClearBits(xEventGroupSound, SOUND_STARTUP); | |
105 | } | |
106 | if (uxBits & SOUND_PROMPT) { | |
107 | VncSoundBell(); | |
108 | BuzzerPlay(_sound_Prompt); | |
109 | xEventGroupClearBits(xEventGroupSound, SOUND_PROMPT); | |
110 | } | |
111 | if (uxBits & SOUND_TEMPREACHED) { | |
112 | VncSoundBell(); | |
113 | BuzzerPlay(_sound_TempReached); | |
114 | VncSoundBell(); | |
115 | xEventGroupClearBits(xEventGroupSound, SOUND_TEMPREACHED); | |
116 | } | |
117 | if (uxBits & SOUND_TIMEOUT) { | |
118 | BuzzerPlay(_sound_TimeOut); | |
119 | xEventGroupClearBits(xEventGroupSound, SOUND_TIMEOUT); | |
120 | } | |
121 | if (uxBits & SOUND_ADDHOP) { | |
122 | VncSoundBell(); | |
123 | VncSoundBell(); | |
124 | BuzzerPlay(_sound_AddHop); | |
125 | VncSoundBell(); | |
126 | VncSoundBell(); | |
127 | xEventGroupClearBits(xEventGroupSound, SOUND_ADDHOP); | |
128 | } | |
129 | if (uxBits & SOUND_END) { | |
130 | BuzzerPlay(_sound_End); | |
131 | xEventGroupClearBits(xEventGroupSound, SOUND_END); | |
132 | } | |
133 | if (uxBits & SOUND_WARN) { | |
134 | VncSoundBell(); | |
135 | BuzzerPlay(_sound_Warn); | |
136 | xEventGroupClearBits(xEventGroupSound, SOUND_WARN); | |
137 | } | |
138 | ||
139 | vTaskDelay(10 / portTICK_PERIOD_MS); | |
140 | } | |
141 | } | |
142 | ||
143 |