mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
[rtttl] fix STOPPED state (#7323)
This commit is contained in:
parent
436c6282da
commit
aaae8f4a87
1 changed files with 5 additions and 3 deletions
|
@ -32,7 +32,7 @@ void Rtttl::play(std::string rtttl) {
|
||||||
if (this->state_ != State::STATE_STOPPED && this->state_ != State::STATE_STOPPING) {
|
if (this->state_ != State::STATE_STOPPED && this->state_ != State::STATE_STOPPING) {
|
||||||
int pos = this->rtttl_.find(':');
|
int pos = this->rtttl_.find(':');
|
||||||
auto name = this->rtttl_.substr(0, pos);
|
auto name = this->rtttl_.substr(0, pos);
|
||||||
ESP_LOGW(TAG, "RTTL Component is already playing: %s", name.c_str());
|
ESP_LOGW(TAG, "RTTTL Component is already playing: %s", name.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@ void Rtttl::stop() {
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
if (this->output_ != nullptr) {
|
if (this->output_ != nullptr) {
|
||||||
this->output_->set_level(0.0);
|
this->output_->set_level(0.0);
|
||||||
|
this->set_state_(STATE_STOPPED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
|
@ -129,10 +130,10 @@ void Rtttl::stop() {
|
||||||
if (this->speaker_->is_running()) {
|
if (this->speaker_->is_running()) {
|
||||||
this->speaker_->stop();
|
this->speaker_->stop();
|
||||||
}
|
}
|
||||||
|
this->set_state_(STATE_STOPPING);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->note_duration_ = 0;
|
this->note_duration_ = 0;
|
||||||
this->set_state_(STATE_STOPPING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rtttl::loop() {
|
void Rtttl::loop() {
|
||||||
|
@ -342,6 +343,7 @@ void Rtttl::finish_() {
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
if (this->output_ != nullptr) {
|
if (this->output_ != nullptr) {
|
||||||
this->output_->set_level(0.0);
|
this->output_->set_level(0.0);
|
||||||
|
this->set_state_(State::STATE_STOPPED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
|
@ -354,9 +356,9 @@ void Rtttl::finish_() {
|
||||||
this->speaker_->play((uint8_t *) (&sample), 8);
|
this->speaker_->play((uint8_t *) (&sample), 8);
|
||||||
|
|
||||||
this->speaker_->finish();
|
this->speaker_->finish();
|
||||||
|
this->set_state_(State::STATE_STOPPING);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->set_state_(State::STATE_STOPPING);
|
|
||||||
this->note_duration_ = 0;
|
this->note_duration_ = 0;
|
||||||
this->on_finished_playback_callback_.call();
|
this->on_finished_playback_callback_.call();
|
||||||
ESP_LOGD(TAG, "Playback finished");
|
ESP_LOGD(TAG, "Playback finished");
|
||||||
|
|
Loading…
Reference in a new issue