From 11459411eec3386fc545eb0e4bcc166875f54af3 Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Mon, 11 Nov 2024 12:58:53 +0000 Subject: [PATCH] add option to disable timeout --- esphome/components/i2s_audio/speaker/__init__.py | 12 +++++++----- .../i2s_audio/speaker/i2s_audio_speaker.cpp | 3 ++- .../components/i2s_audio/speaker/i2s_audio_speaker.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/esphome/components/i2s_audio/speaker/__init__.py b/esphome/components/i2s_audio/speaker/__init__.py index dd43d6cb39..c84821c4e3 100644 --- a/esphome/components/i2s_audio/speaker/__init__.py +++ b/esphome/components/i2s_audio/speaker/__init__.py @@ -2,7 +2,7 @@ from esphome import pins import esphome.codegen as cg from esphome.components import esp32, speaker import esphome.config_validation as cv -from esphome.const import CONF_CHANNEL, CONF_ID, CONF_MODE, CONF_TIMEOUT +from esphome.const import CONF_CHANNEL, CONF_DISABLED, CONF_ID, CONF_MODE, CONF_TIMEOUT from .. import ( CONF_I2S_DOUT_PIN, @@ -72,9 +72,10 @@ BASE_SCHEMA = ( ) .extend( { - cv.Optional( - CONF_TIMEOUT, default="500ms" - ): cv.positive_time_period_milliseconds, + cv.Optional(CONF_TIMEOUT, default="500ms"): cv.Any( + cv.positive_time_period_milliseconds, + cv.one_of(CONF_DISABLED, lower=True), + ), } ) .extend(cv.COMPONENT_SCHEMA) @@ -116,4 +117,5 @@ async def to_code(config): else: cg.add(var.set_dout_pin(config[CONF_I2S_DOUT_PIN])) cg.add(var.set_i2s_comm_fmt(config[CONF_I2S_COMM_FMT])) - cg.add(var.set_timeout(config[CONF_TIMEOUT])) + if config[CONF_TIMEOUT] != CONF_DISABLED: + cg.add(var.set_timeout(config[CONF_TIMEOUT])) diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp index 1e5a9b8c9d..24a76902a4 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp @@ -267,7 +267,8 @@ void I2SAudioSpeaker::speaker_task(void *params) { uint32_t last_data_received_time = millis(); bool tx_dma_underflow = false; - while ((millis() - last_data_received_time) <= this_speaker->timeout_) { + while (!this_speaker->timeout_.has_value() || + (millis() - last_data_received_time) <= this_speaker->timeout_.value()) { event_group_bits = xEventGroupGetBits(this_speaker->event_group_); if (event_group_bits & SpeakerEventGroupBits::COMMAND_STOP) { diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h index e296e28264..76c2350585 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h @@ -123,7 +123,7 @@ class I2SAudioSpeaker : public I2SAudioOut, public speaker::Speaker, public Comp uint8_t *data_buffer_; std::shared_ptr audio_ring_buffer_; - uint32_t timeout_; + optional timeout_; uint8_t dout_pin_; bool task_created_{false};