fix missing checks of is_playing condition (#844)

This commit is contained in:
Guillermo Ruffino 2019-11-11 23:50:06 -03:00 committed by Otto Winter
parent 7f6672bb37
commit 2ef64b55c5
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E
2 changed files with 42 additions and 9 deletions

View file

@ -8,8 +8,10 @@ static const char* TAG = "dfplayer";
void DFPlayer::play_folder(uint16_t folder, uint16_t file) { void DFPlayer::play_folder(uint16_t folder, uint16_t file) {
if (folder < 100 && file < 256) { if (folder < 100 && file < 256) {
this->ack_set_is_playing_ = true;
this->send_cmd_(0x0F, (uint8_t) folder, (uint8_t) file); this->send_cmd_(0x0F, (uint8_t) folder, (uint8_t) file);
} else if (folder <= 10 && file <= 1000) { } else if (folder <= 10 && file <= 1000) {
this->ack_set_is_playing_ = true;
this->send_cmd_(0x14, (((uint16_t) folder) << 12) | file); this->send_cmd_(0x14, (((uint16_t) folder) << 12) | file);
} else { } else {
ESP_LOGE(TAG, "Cannot play folder %d file %d.", folder, file); ESP_LOGE(TAG, "Cannot play folder %d file %d.", folder, file);
@ -93,6 +95,10 @@ void DFPlayer::loop() {
ESP_LOGI(TAG, "USB, TF Card available"); ESP_LOGI(TAG, "USB, TF Card available");
} }
break; break;
case 0x40:
ESP_LOGV(TAG, "Nack");
this->ack_set_is_playing_ = false;
this->ack_reset_is_playing_ = false;
case 0x41: case 0x41:
ESP_LOGV(TAG, "Ack ok"); ESP_LOGV(TAG, "Ack ok");
this->is_playing_ |= this->ack_set_is_playing_; this->is_playing_ |= this->ack_set_is_playing_;

View file

@ -27,29 +27,56 @@ class DFPlayer : public uart::UARTDevice, public Component {
public: public:
void loop() override; void loop() override;
void next() { this->send_cmd_(0x01); } void next() {
void previous() { this->send_cmd_(0x02); } this->ack_set_is_playing_ = true;
this->send_cmd_(0x01);
}
void previous() {
this->ack_set_is_playing_ = true;
this->send_cmd_(0x02);
}
void play_file(uint16_t file) { void play_file(uint16_t file) {
this->ack_set_is_playing_ = true; this->ack_set_is_playing_ = true;
this->send_cmd_(0x03, file); this->send_cmd_(0x03, file);
} }
void play_file_loop(uint16_t file) { this->send_cmd_(0x08, file); } void play_file_loop(uint16_t file) {
this->ack_set_is_playing_ = true;
this->send_cmd_(0x08, file);
}
void play_folder(uint16_t folder, uint16_t file); void play_folder(uint16_t folder, uint16_t file);
void play_folder_loop(uint16_t folder) { this->send_cmd_(0x17, folder); } void play_folder_loop(uint16_t folder) {
this->ack_set_is_playing_ = true;
this->send_cmd_(0x17, folder);
}
void volume_up() { this->send_cmd_(0x04); } void volume_up() { this->send_cmd_(0x04); }
void volume_down() { this->send_cmd_(0x05); } void volume_down() { this->send_cmd_(0x05); }
void set_device(Device device) { this->send_cmd_(0x09, device); } void set_device(Device device) { this->send_cmd_(0x09, device); }
void set_volume(uint8_t volume) { this->send_cmd_(0x06, volume); } void set_volume(uint8_t volume) { this->send_cmd_(0x06, volume); }
void set_eq(EqPreset preset) { this->send_cmd_(0x07, preset); } void set_eq(EqPreset preset) { this->send_cmd_(0x07, preset); }
void sleep() { this->send_cmd_(0x0A); } void sleep() {
void reset() { this->send_cmd_(0x0C); } this->ack_reset_is_playing_ = true;
void start() { this->send_cmd_(0x0D); } this->send_cmd_(0x0A);
}
void reset() {
this->ack_reset_is_playing_ = true;
this->send_cmd_(0x0C);
}
void start() {
this->ack_set_is_playing_ = true;
this->send_cmd_(0x0D);
}
void pause() { void pause() {
this->ack_reset_is_playing_ = true; this->ack_reset_is_playing_ = true;
this->send_cmd_(0x0E); this->send_cmd_(0x0E);
} }
void stop() { this->send_cmd_(0x16); } void stop() {
void random() { this->send_cmd_(0x18); } this->ack_reset_is_playing_ = true;
this->send_cmd_(0x16);
}
void random() {
this->ack_set_is_playing_ = true;
this->send_cmd_(0x18);
}
bool is_playing() { return is_playing_; } bool is_playing() { return is_playing_; }
void dump_config() override; void dump_config() override;