mirror of
https://github.com/esphome/esphome.git
synced 2025-09-25 06:32:22 +01:00
Implement the finish() method and action. implement the is_stopped condition (#7255)
This commit is contained in:
@@ -180,7 +180,11 @@ void I2SAudioSpeaker::player_task(void *params) {
|
||||
}
|
||||
}
|
||||
|
||||
void I2SAudioSpeaker::stop() {
|
||||
void I2SAudioSpeaker::stop() { this->stop_(false); }
|
||||
|
||||
void I2SAudioSpeaker::finish() { this->stop_(true); }
|
||||
|
||||
void I2SAudioSpeaker::stop_(bool wait_on_empty) {
|
||||
if (this->is_failed())
|
||||
return;
|
||||
if (this->state_ == speaker::STATE_STOPPED)
|
||||
@@ -192,7 +196,11 @@ void I2SAudioSpeaker::stop() {
|
||||
this->state_ = speaker::STATE_STOPPING;
|
||||
DataEvent data;
|
||||
data.stop = true;
|
||||
xQueueSendToFront(this->buffer_queue_, &data, portMAX_DELAY);
|
||||
if (wait_on_empty) {
|
||||
xQueueSend(this->buffer_queue_, &data, portMAX_DELAY);
|
||||
} else {
|
||||
xQueueSendToFront(this->buffer_queue_, &data, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void I2SAudioSpeaker::watch_() {
|
||||
|
@@ -53,6 +53,7 @@ class I2SAudioSpeaker : public Component, public speaker::Speaker, public I2SAud
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
void finish() override;
|
||||
|
||||
size_t play(const uint8_t *data, size_t length) override;
|
||||
|
||||
@@ -60,6 +61,7 @@ class I2SAudioSpeaker : public Component, public speaker::Speaker, public I2SAud
|
||||
|
||||
protected:
|
||||
void start_();
|
||||
void stop_(bool wait_on_empty);
|
||||
void watch_();
|
||||
|
||||
static void player_task(void *params);
|
||||
|
Reference in New Issue
Block a user