Skip to content

Commit d4a5d0e

Browse files
committed
Tone update
1 parent b784c5e commit d4a5d0e

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

cores/esp32/Tone.cpp

+9-22
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
static TaskHandle_t _tone_task = NULL;
88
static QueueHandle_t _tone_queue = NULL;
9-
static QueueHandle_t _tone_mutex = NULL;
109
static uint8_t _channel = 0;
1110

1211
typedef enum{
@@ -30,30 +29,29 @@ static void tone_task(void*){
3029
switch(tone_msg.tone_cmd){
3130
case TONE_START:
3231
log_d("Task received from queue TONE_START: _pin=%d, frequency=%u Hz, duration=%u ms", tone_msg.pin, tone_msg.frequency, tone_msg.duration);
33-
if(xSemaphoreTake(_tone_mutex, portMAX_DELAY) != pdTRUE ){
34-
log_e("Tone mutex take returned with error");
35-
break;
36-
}
32+
3733
log_d("Setup LED controll on channel %d", _channel);
38-
ledcSetup(_channel, tone_msg.frequency, 11);
34+
// ledcSetup(_channel, tone_msg.frequency, 11);
35+
// ledcAttachPin(tone_msg.pin, _channel);
36+
// ledcWrite(_channel, 1024);
37+
ledcWriteTone(_channel, tone_msg.frequency);
3938
ledcAttachPin(tone_msg.pin, _channel);
40-
ledcWrite(_channel, 1024);
41-
if(xSemaphoreGive(_tone_mutex) != pdTRUE){
42-
log_e("Tone mutex give returned with error");
43-
}
4439

4540
if(tone_msg.duration){
46-
vTaskDelay(pdMS_TO_TICKS(tone_msg.duration));
41+
delay(tone_msg.duration);
4742
ledcDetachPin(tone_msg.pin);
43+
ledcWriteTone(_channel, 0);
4844
}
4945
break;
5046

5147
case TONE_END:
5248
log_d("Task received from queue TONE_END: pin=%d", tone_msg.pin);
5349
ledcDetachPin(tone_msg.pin);
50+
ledcWriteTone(_channel, 0);
5451
break;
5552

5653
case TONE_SET_CHANNEL:
54+
log_d("Task received from queue TONE_SET_CHANNEL: channel=%d", tone_msg.channel);
5755
_channel = tone_msg.channel;
5856
break;
5957

@@ -63,17 +61,6 @@ static void tone_task(void*){
6361
}
6462

6563
static int tone_init(){
66-
if(_tone_mutex == NULL){
67-
log_v("Creating tone mutex");
68-
_tone_mutex = xSemaphoreCreateMutex();
69-
if(_tone_mutex == NULL){
70-
log_e("Could not create tone mutex");
71-
return 0; // ERR
72-
}
73-
log_v("Tone mutex created");
74-
}
75-
76-
7764
if(_tone_queue == NULL){
7865
log_v("Creating tone queue");
7966
_tone_queue = xQueueCreate(128, sizeof(tone_msg_t));

0 commit comments

Comments
 (0)