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);
163 ESP_LOGW(TAG,
"Expected end byte 0xEF, got %#02x", byte);
171 ESP_LOGV(TAG,
"Received message cmd: %#02x arg %#04x", cmd, argument);
176 ESP_LOGI(TAG,
"USB loaded");
177 }
else if (argument == 2) {
178 ESP_LOGI(TAG,
"TF Card loaded");
183 ESP_LOGI(TAG,
"USB unloaded");
184 }
else if (argument == 2) {
185 ESP_LOGI(TAG,
"TF Card unloaded");
190 ESP_LOGI(TAG,
"USB available");
191 }
else if (argument == 2) {
192 ESP_LOGI(TAG,
"TF Card available");
193 }
else if (argument == 3) {
194 ESP_LOGI(TAG,
"USB, TF Card available");
198 ESP_LOGV(TAG,
"Nack");
203 ESP_LOGE(TAG,
"Module is busy or uninitialized");
206 ESP_LOGE(TAG,
"Module is in sleep mode");
209 ESP_LOGE(TAG,
"Serial receive error");
212 ESP_LOGE(TAG,
"Checksum incorrect");
215 ESP_LOGE(TAG,
"Specified track is out of current track scope");
219 ESP_LOGE(TAG,
"Specified track is not found");
223 ESP_LOGE(TAG,
"Insertion error (an inserting operation only can be done when a track is being played)");
226 ESP_LOGE(TAG,
"SD card reading failed (SD card pulled out or damaged)");
229 ESP_LOGE(TAG,
"Entered into sleep mode");
235 ESP_LOGV(TAG,
"Ack ok");
242 ESP_LOGV(TAG,
"Playback finished");
247 ESP_LOGV(TAG,
"Received unknown cmd %#02x arg %#04x", cmd, argument);
258 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)