add option to disable timeout

This commit is contained in:
Kevin Ahrendt 2024-11-11 12:58:53 +00:00
parent a667a1e7ee
commit 11459411ee
3 changed files with 10 additions and 7 deletions

View file

@ -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]))

View file

@ -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) {

View file

@ -123,7 +123,7 @@ class I2SAudioSpeaker : public I2SAudioOut, public speaker::Speaker, public Comp
uint8_t *data_buffer_;
std::shared_ptr<RingBuffer> audio_ring_buffer_;
uint32_t timeout_;
optional<uint32_t> timeout_;
uint8_t dout_pin_;
bool task_created_{false};