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 uint16_t arg = enable ? 0x00 : 0x01;
107 ESP_LOGD(TAG,
"Setting current track repeat to %s",
108 enable ? LOG_STR_LITERAL(
"enabled") : LOG_STR_LITERAL(
"disabled"));
113 ESP_LOGD(TAG,
"Playing file %d in folder %d", file, folder);
114 if (folder < 100 && file < 256) {
116 this->
send_cmd_(0x0F, (uint8_t) folder, (uint8_t) file);
117 }
else if (folder <= 15 && file <= 3000) {
119 this->
send_cmd_(0x14, (((uint16_t) folder) << 12) | file);
121 ESP_LOGE(TAG,
"Cannot play folder %d file %d.", folder, file);
126 uint8_t
buffer[10]{0x7e, 0xff, 0x06, cmd, 0x01, (uint8_t) (argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef};
133 ESP_LOGV(TAG,
"Send Command %#02x arg %#04x", cmd, argument);
142 size_t to_read = std::min(avail,
sizeof(buf));
147 for (
size_t bi = 0; bi < to_read; bi++) {
148 uint8_t
byte = buf[bi];
160 ESP_LOGW(TAG,
"Expected Version 0xFF, got %#02x",
byte);
167 ESP_LOGW(TAG,
"Expected Buffer length 0x06, got %#02x",
byte);
173#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
174 char byte_sequence[100];
175 byte_sequence[0] =
'\0';
176 for (
size_t i = 0; i < this->
read_pos_ + 1; ++i) {
177 snprintf(byte_sequence + strlen(byte_sequence),
sizeof(byte_sequence) - strlen(byte_sequence),
"%02X ",
180 ESP_LOGVV(TAG,
"Received byte sequence: %s", byte_sequence);
183 ESP_LOGW(TAG,
"Expected end byte 0xEF, got %#02x",
byte);
191 ESP_LOGV(TAG,
"Received message cmd: %#02x arg %#04x", cmd, argument);
196 ESP_LOGI(TAG,
"USB loaded");
197 }
else if (argument == 2) {
198 ESP_LOGI(TAG,
"TF Card loaded");
203 ESP_LOGI(TAG,
"USB unloaded");
204 }
else if (argument == 2) {
205 ESP_LOGI(TAG,
"TF Card unloaded");
210 ESP_LOGI(TAG,
"USB available");
211 }
else if (argument == 2) {
212 ESP_LOGI(TAG,
"TF Card available");
213 }
else if (argument == 3) {
214 ESP_LOGI(TAG,
"USB, TF Card available");
218 ESP_LOGV(TAG,
"Nack");
223 ESP_LOGE(TAG,
"Module is busy or uninitialized");
226 ESP_LOGE(TAG,
"Module is in sleep mode");
229 ESP_LOGE(TAG,
"Serial receive error");
232 ESP_LOGE(TAG,
"Checksum incorrect");
235 ESP_LOGE(TAG,
"Specified track is out of current track scope");
239 ESP_LOGE(TAG,
"Specified track is not found");
244 "Insertion error (an inserting operation only can be done when a track is being played)");
247 ESP_LOGE(TAG,
"SD card reading failed (SD card pulled out or damaged)");
250 ESP_LOGE(TAG,
"Entered into sleep mode");
258 ESP_LOGV(TAG,
"Ack ok");
265 ESP_LOGV(TAG,
"Playback finished (USB drive)");
270 ESP_LOGV(TAG,
"Playback finished (SD card)");
275 ESP_LOGE(TAG,
"Received unknown cmd %#02x arg %#04x", cmd, argument);
void dump_config() override
CallbackManager< void()> on_finished_playback_callback_
void send_cmd_(uint8_t cmd, uint16_t argument=0)
void set_volume(uint8_t volume)
void play_folder(uint16_t folder, uint16_t file)
void play_file_loop(uint16_t file)
void set_device(Device device)
void play_file(uint16_t file)
void set_current_track_repeat(bool enable)
bool ack_reset_is_playing_
void set_eq(EqPreset preset)
char read_buffer_[DFPLAYER_READ_BUFFER_LENGTH]
void play_folder_loop(uint16_t folder)
void play_mp3(uint16_t file)
optional< std::array< uint8_t, N > > read_array()
void write_array(const uint8_t *data, size_t len)
const size_t DFPLAYER_READ_BUFFER_LENGTH
ESPHOME_LOG_TAG(TAG, "dfplayer")
constexpr uint16_t sum16_bytes(const uint8_t *data, size_t len, uint16_t sum=0)
Add up the bytes of data with size len, truncated to 16 bits.