7 static const char *
const TAG =
"dfplayer";
10 if (folder < 100 && file < 256) {
12 this->
send_cmd_(0x0F, (uint8_t) folder, (uint8_t) file);
13 }
else if (folder <= 15 && file <= 3000) {
15 this->
send_cmd_(0x14, (((uint16_t) folder) << 12) | file);
17 ESP_LOGE(TAG,
"Cannot play folder %d file %d.", folder, file);
22 uint8_t buffer[10]{0x7e, 0xff, 0x06,
cmd, 0x01, (uint8_t) (argument >> 8), (uint8_t) argument, 0x00, 0x00, 0xef};
24 for (uint8_t i = 1; i < 7; i++)
25 checksum += buffer[i];
27 buffer[7] = checksum >> 8;
28 buffer[8] = (uint8_t) checksum;
32 ESP_LOGD(TAG,
"Send Command %#02x arg %#04x", cmd, argument);
52 ESP_LOGW(TAG,
"Expected Version 0xFF, got %#02x", byte);
59 ESP_LOGW(TAG,
"Expected Buffer length 0x06, got %#02x", byte);
66 ESP_LOGW(TAG,
"Expected end byte 0xEF, got %#02x", byte);
74 ESP_LOGV(TAG,
"Received message cmd: %#02x arg %#04x", cmd, argument);
79 ESP_LOGI(TAG,
"USB loaded");
80 }
else if (argument == 2) {
81 ESP_LOGI(TAG,
"TF Card loaded");
86 ESP_LOGI(TAG,
"USB unloaded");
87 }
else if (argument == 2) {
88 ESP_LOGI(TAG,
"TF Card unloaded");
93 ESP_LOGI(TAG,
"USB available");
94 }
else if (argument == 2) {
95 ESP_LOGI(TAG,
"TF Card available");
96 }
else if (argument == 3) {
97 ESP_LOGI(TAG,
"USB, TF Card available");
101 ESP_LOGV(TAG,
"Nack");
105 ESP_LOGV(TAG,
"File not found");
110 ESP_LOGV(TAG,
"Ack ok");
121 ESP_LOGD(TAG,
"Command %#02x arg %#04x", cmd, argument);
132 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 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.
bool ack_reset_is_playing_
char read_buffer_[DFPLAYER_READ_BUFFER_LENGTH]