mirror of https://github.com/esphome/esphome.git
removed WAITING_FOR_LOCK state
This commit is contained in:
parent
4bd22e784f
commit
3b5ef399e0
|
@ -22,13 +22,19 @@ void I2SAudioSpeaker::setup() {
|
||||||
this->event_queue_ = xQueueCreate(BUFFER_COUNT, sizeof(TaskEvent));
|
this->event_queue_ = xQueueCreate(BUFFER_COUNT, sizeof(TaskEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2SAudioSpeaker::start() { this->state_ = speaker::STATE_WAITING_FOR_LOCK; }
|
void I2SAudioSpeaker::start() {
|
||||||
|
this->task_created_ = false;
|
||||||
|
this->state_ = speaker::STATE_STARTING;
|
||||||
|
}
|
||||||
void I2SAudioSpeaker::start_() {
|
void I2SAudioSpeaker::start_() {
|
||||||
|
if (this->task_created_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this->parent_->try_lock()) {
|
if (!this->parent_->try_lock()) {
|
||||||
return; // Waiting for another i2s component to return lock
|
return; // Waiting for another i2s component to return lock
|
||||||
}
|
}
|
||||||
this->state_ = speaker::STATE_STARTING;
|
|
||||||
xTaskCreate(I2SAudioSpeaker::player_task, "speaker_task", 8192, (void *) this, 1, &this->player_task_handle_);
|
xTaskCreate(I2SAudioSpeaker::player_task, "speaker_task", 8192, (void *) this, 1, &this->player_task_handle_);
|
||||||
|
this->task_created_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2SAudioSpeaker::player_task(void *params) {
|
void I2SAudioSpeaker::player_task(void *params) {
|
||||||
|
@ -188,6 +194,7 @@ void I2SAudioSpeaker::watch_() {
|
||||||
case TaskEventType::STOPPED:
|
case TaskEventType::STOPPED:
|
||||||
this->state_ = speaker::STATE_STOPPED;
|
this->state_ = speaker::STATE_STOPPED;
|
||||||
vTaskDelete(this->player_task_handle_);
|
vTaskDelete(this->player_task_handle_);
|
||||||
|
this->task_created_ = false;
|
||||||
this->player_task_handle_ = nullptr;
|
this->player_task_handle_ = nullptr;
|
||||||
this->parent_->unlock();
|
this->parent_->unlock();
|
||||||
xQueueReset(this->buffer_queue_);
|
xQueueReset(this->buffer_queue_);
|
||||||
|
@ -203,10 +210,10 @@ void I2SAudioSpeaker::watch_() {
|
||||||
|
|
||||||
void I2SAudioSpeaker::loop() {
|
void I2SAudioSpeaker::loop() {
|
||||||
switch (this->state_) {
|
switch (this->state_) {
|
||||||
case speaker::STATE_WAITING_FOR_LOCK:
|
|
||||||
this->start_();
|
|
||||||
break;
|
|
||||||
case speaker::STATE_STARTING:
|
case speaker::STATE_STARTING:
|
||||||
|
this->start_();
|
||||||
|
this->watch_();
|
||||||
|
break;
|
||||||
case speaker::STATE_RUNNING:
|
case speaker::STATE_RUNNING:
|
||||||
case speaker::STATE_STOPPING:
|
case speaker::STATE_STOPPING:
|
||||||
this->watch_();
|
this->watch_();
|
||||||
|
|
|
@ -71,6 +71,7 @@ class I2SAudioSpeaker : public Component, public speaker::Speaker, public I2SAud
|
||||||
QueueHandle_t event_queue_;
|
QueueHandle_t event_queue_;
|
||||||
|
|
||||||
uint8_t dout_pin_{0};
|
uint8_t dout_pin_{0};
|
||||||
|
bool task_created_{false};
|
||||||
|
|
||||||
#if SOC_I2S_SUPPORTS_DAC
|
#if SOC_I2S_SUPPORTS_DAC
|
||||||
i2s_dac_mode_t internal_dac_mode_{I2S_DAC_CHANNEL_DISABLE};
|
i2s_dac_mode_t internal_dac_mode_{I2S_DAC_CHANNEL_DISABLE};
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace speaker {
|
||||||
|
|
||||||
enum State : uint8_t {
|
enum State : uint8_t {
|
||||||
STATE_STOPPED = 0,
|
STATE_STOPPED = 0,
|
||||||
STATE_WAITING_FOR_LOCK,
|
|
||||||
STATE_STARTING,
|
STATE_STARTING,
|
||||||
STATE_RUNNING,
|
STATE_RUNNING,
|
||||||
STATE_STOPPING,
|
STATE_STOPPING,
|
||||||
|
|
Loading…
Reference in New Issue