7 static const char *
const TAG =
"dfplayer";
11 ESP_LOGD(TAG,
"Playing next track");
17 ESP_LOGD(TAG,
"Playing previous track");
22 ESP_LOGD(TAG,
"Playing file %d in mp3 folder", file);
28 ESP_LOGD(TAG,
"Playing file %d", file);
34 ESP_LOGD(TAG,
"Playing file %d in loop", file);
40 ESP_LOGD(TAG,
"Playing folder %d in loop", folder);
45 ESP_LOGD(TAG,
"Increasing volume");
50 ESP_LOGD(TAG,
"Decreasing volume");
55 ESP_LOGD(TAG,
"Setting device to %d", device);
60 ESP_LOGD(TAG,
"Setting volume to %d", volume);
65 ESP_LOGD(TAG,
"Setting EQ to %d", preset);
71 ESP_LOGD(TAG,
"Putting DFPlayer to sleep");
77 ESP_LOGD(TAG,
"Resetting DFPlayer");
83 ESP_LOGD(TAG,
"Starting playback");
89 ESP_LOGD(TAG,
"Pausing playback");
95 ESP_LOGD(TAG,
"Stopping playback");
101 ESP_LOGD(TAG,
"Playing random file");
106 ESP_LOGD(TAG,
"Playing file %d in folder %d", file, folder);
107 if (folder < 100 && file < 256) {
109 this->
send_cmd_(0x0F, (uint8_t) folder, (uint8_t) file);
110 }
else if (folder <= 15 && file <= 3000) {
112 this->
send_cmd_(0x14, (((uint16_t) folder) << 12) | file);
114 ESP_LOGE(TAG,
"Cannot play folder %d file %d.", folder, file);
119 uint8_t buffer[10]{0x7e, 0xff, 0x06,
cmd, 0x01, (uint8_t) (argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef};
121 for (uint8_t i = 1; i < 7; i++)
122 checksum += buffer[i];
124 buffer[7] = checksum >> 8;
125 buffer[8] = (uint8_t) checksum;
129 ESP_LOGV(TAG,
"Send Command %#02x arg %#04x", cmd, argument);
149 ESP_LOGW(TAG,
"Expected Version 0xFF, got %#02x", byte);
156 ESP_LOGW(TAG,
"Expected Buffer length 0x06, got %#02x", byte);
162 #ifdef ESPHOME_LOG_HAS_VERY_VERBOSE 163 char byte_sequence[100];
164 byte_sequence[0] =
'\0';
165 for (
size_t i = 0; i < this->
read_pos_ + 1; ++i) {
166 snprintf(byte_sequence + strlen(byte_sequence),
sizeof(byte_sequence) - strlen(byte_sequence),
"%02X ",
169 ESP_LOGVV(TAG,
"Received byte sequence: %s", byte_sequence);
172 ESP_LOGW(TAG,
"Expected end byte 0xEF, got %#02x", byte);
180 ESP_LOGV(TAG,
"Received message cmd: %#02x arg %#04x", cmd, argument);
185 ESP_LOGI(TAG,
"USB loaded");
186 }
else if (argument == 2) {
187 ESP_LOGI(TAG,
"TF Card loaded");
192 ESP_LOGI(TAG,
"USB unloaded");
193 }
else if (argument == 2) {
194 ESP_LOGI(TAG,
"TF Card unloaded");
199 ESP_LOGI(TAG,
"USB available");
200 }
else if (argument == 2) {
201 ESP_LOGI(TAG,
"TF Card available");
202 }
else if (argument == 3) {
203 ESP_LOGI(TAG,
"USB, TF Card available");
207 ESP_LOGV(TAG,
"Nack");
212 ESP_LOGE(TAG,
"Module is busy or uninitialized");
215 ESP_LOGE(TAG,
"Module is in sleep mode");
218 ESP_LOGE(TAG,
"Serial receive error");
221 ESP_LOGE(TAG,
"Checksum incorrect");
224 ESP_LOGE(TAG,
"Specified track is out of current track scope");
228 ESP_LOGE(TAG,
"Specified track is not found");
232 ESP_LOGE(TAG,
"Insertion error (an inserting operation only can be done when a track is being played)");
235 ESP_LOGE(TAG,
"SD card reading failed (SD card pulled out or damaged)");
238 ESP_LOGE(TAG,
"Entered into sleep mode");
244 ESP_LOGV(TAG,
"Ack ok");
251 ESP_LOGV(TAG,
"Playback finished (USB drive)");
255 ESP_LOGV(TAG,
"Playback finished (SD card)");
260 ESP_LOGE(TAG,
"Received unknown cmd %#02x arg %#04x", cmd, argument);
271 ESP_LOGCONFIG(TAG,
"DFPlayer:");
void send_cmd_(uint8_t cmd, uint16_t argument=0)
void dump_config() override
CallbackManager< void()> on_finished_playback_callback_
void write_array(const uint8_t *data, size_t len)
void play_file_loop(uint16_t file)
void set_device(Device device)
void play_file(uint16_t file)
void play_folder_loop(uint16_t folder)
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
bool read_byte(uint8_t *data)
const size_t DFPLAYER_READ_BUFFER_LENGTH
void play_folder(uint16_t folder, uint16_t file)
Implementation of SPI Controller mode.
void set_eq(EqPreset preset)
void set_volume(uint8_t volume)
bool ack_reset_is_playing_
char read_buffer_[DFPLAYER_READ_BUFFER_LENGTH]
void play_mp3(uint16_t file)