mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 19:18:09 +01:00
Moved dfplayer functions from header to cpp file
This allows the logging macros to have the correct line numbers
This commit is contained in:
parent
13de8b71b8
commit
983b161ab5
2 changed files with 100 additions and 81 deletions
|
@ -4,6 +4,89 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace dfplayer {
|
namespace dfplayer {
|
||||||
|
|
||||||
|
static const char *const TAG = "dfplayer";
|
||||||
|
|
||||||
|
void DFPlayer::next() {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Playing next track");
|
||||||
|
this->send_cmd_(0x01);
|
||||||
|
}
|
||||||
|
void DFPlayer::previous() {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Playing previous track");
|
||||||
|
this->send_cmd_(0x02);
|
||||||
|
}
|
||||||
|
void DFPlayer::play_mp3(uint16_t file) {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Playing file %d in mp3 folder", file);
|
||||||
|
this->send_cmd_(0x12, file);
|
||||||
|
}
|
||||||
|
void DFPlayer::play_file(uint16_t file) {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Playing file %d", file);
|
||||||
|
this->send_cmd_(0x03, file);
|
||||||
|
}
|
||||||
|
void DFPlayer::play_file_loop(uint16_t file) {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Playing file %d in loop", file);
|
||||||
|
this->send_cmd_(0x08, file);
|
||||||
|
}
|
||||||
|
void DFPlayer::play_folder_loop(uint16_t folder) {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Playing folder %d in loop", folder);
|
||||||
|
this->send_cmd_(0x17, folder);
|
||||||
|
}
|
||||||
|
void DFPlayer::volume_up() {
|
||||||
|
ESP_LOGD(TAG, "Increasing volume");
|
||||||
|
this->send_cmd_(0x04);
|
||||||
|
}
|
||||||
|
void DFPlayer::volume_down() {
|
||||||
|
ESP_LOGD(TAG, "Decreasing volume");
|
||||||
|
this->send_cmd_(0x05);
|
||||||
|
}
|
||||||
|
void DFPlayer::set_device(Device device) {
|
||||||
|
ESP_LOGD(TAG, "Setting device to %d", device);
|
||||||
|
this->send_cmd_(0x09, device);
|
||||||
|
}
|
||||||
|
void DFPlayer::set_volume(uint8_t volume) {
|
||||||
|
ESP_LOGD(TAG, "Setting volume to %d", volume);
|
||||||
|
this->send_cmd_(0x06, volume);
|
||||||
|
}
|
||||||
|
void DFPlayer::set_eq(EqPreset preset) {
|
||||||
|
ESP_LOGD(TAG, "Setting EQ to %d", preset);
|
||||||
|
this->send_cmd_(0x07, preset);
|
||||||
|
}
|
||||||
|
void DFPlayer::sleep() {
|
||||||
|
this->ack_reset_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Putting DFPlayer to sleep");
|
||||||
|
this->send_cmd_(0x0A);
|
||||||
|
}
|
||||||
|
void DFPlayer::reset() {
|
||||||
|
this->ack_reset_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Resetting DFPlayer");
|
||||||
|
this->send_cmd_(0x0C);
|
||||||
|
}
|
||||||
|
void DFPlayer::start() {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Starting playback");
|
||||||
|
this->send_cmd_(0x0D);
|
||||||
|
}
|
||||||
|
void DFPlayer::pause() {
|
||||||
|
this->ack_reset_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Pausing playback");
|
||||||
|
this->send_cmd_(0x0E);
|
||||||
|
}
|
||||||
|
void DFPlayer::stop() {
|
||||||
|
this->ack_reset_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Stopping playback");
|
||||||
|
this->send_cmd_(0x16);
|
||||||
|
}
|
||||||
|
void DFPlayer::random() {
|
||||||
|
this->ack_set_is_playing_ = true;
|
||||||
|
ESP_LOGD(TAG, "Playing random file");
|
||||||
|
this->send_cmd_(0x18);
|
||||||
|
}
|
||||||
|
|
||||||
void DFPlayer::play_folder(uint16_t folder, uint16_t file) {
|
void DFPlayer::play_folder(uint16_t folder, uint16_t file) {
|
||||||
ESP_LOGD(TAG, "Playing file %d in folder %d", file, folder);
|
ESP_LOGD(TAG, "Playing file %d in folder %d", file, folder);
|
||||||
if (folder < 100 && file < 256) {
|
if (folder < 100 && file < 256) {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
|
|
||||||
const size_t DFPLAYER_READ_BUFFER_LENGTH = 25; // two messages + some extra
|
const size_t DFPLAYER_READ_BUFFER_LENGTH = 25; // two messages + some extra
|
||||||
static const char *const TAG = "dfplayer";
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace dfplayer {
|
namespace dfplayer {
|
||||||
|
@ -30,87 +29,24 @@ class DFPlayer : public uart::UARTDevice, public Component {
|
||||||
public:
|
public:
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
void next() {
|
void next();
|
||||||
this->ack_set_is_playing_ = true;
|
void previous();
|
||||||
ESP_LOGD(TAG, "Playing next track");
|
void play_mp3(uint16_t file);
|
||||||
this->send_cmd_(0x01);
|
void play_file(uint16_t file);
|
||||||
}
|
void play_file_loop(uint16_t file);
|
||||||
void previous() {
|
|
||||||
this->ack_set_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Playing previous track");
|
|
||||||
this->send_cmd_(0x02);
|
|
||||||
}
|
|
||||||
void play_mp3(uint16_t file) {
|
|
||||||
this->ack_set_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Playing file %d in mp3 folder", file);
|
|
||||||
this->send_cmd_(0x12, file);
|
|
||||||
}
|
|
||||||
void play_file(uint16_t file) {
|
|
||||||
this->ack_set_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Playing file %d", file);
|
|
||||||
this->send_cmd_(0x03, file);
|
|
||||||
}
|
|
||||||
void play_file_loop(uint16_t file) {
|
|
||||||
this->ack_set_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Playing file %d in loop", file);
|
|
||||||
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) {
|
void play_folder_loop(uint16_t folder);
|
||||||
this->ack_set_is_playing_ = true;
|
void volume_up();
|
||||||
ESP_LOGD(TAG, "Playing folder %d in loop", folder);
|
void volume_down();
|
||||||
this->send_cmd_(0x17, folder);
|
void set_device(Device device);
|
||||||
}
|
void set_volume(uint8_t volume);
|
||||||
void volume_up() {
|
void set_eq(EqPreset preset);
|
||||||
ESP_LOGD(TAG, "Increasing volume");
|
void sleep();
|
||||||
this->send_cmd_(0x04);
|
void reset();
|
||||||
}
|
void start();
|
||||||
void volume_down() {
|
void pause();
|
||||||
ESP_LOGD(TAG, "Decreasing volume");
|
void stop();
|
||||||
this->send_cmd_(0x05);
|
void random();
|
||||||
}
|
|
||||||
void set_device(Device device) {
|
|
||||||
ESP_LOGD(TAG, "Setting device to %d", device);
|
|
||||||
this->send_cmd_(0x09, device);
|
|
||||||
}
|
|
||||||
void set_volume(uint8_t volume) {
|
|
||||||
ESP_LOGD(TAG, "Setting volume to %d", volume);
|
|
||||||
this->send_cmd_(0x06, volume);
|
|
||||||
}
|
|
||||||
void set_eq(EqPreset preset) {
|
|
||||||
ESP_LOGD(TAG, "Setting EQ to %d", preset);
|
|
||||||
this->send_cmd_(0x07, preset);
|
|
||||||
}
|
|
||||||
void sleep() {
|
|
||||||
this->ack_reset_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Putting DFPlayer to sleep");
|
|
||||||
this->send_cmd_(0x0A);
|
|
||||||
}
|
|
||||||
void reset() {
|
|
||||||
this->ack_reset_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Resetting DFPlayer");
|
|
||||||
this->send_cmd_(0x0C);
|
|
||||||
}
|
|
||||||
void start() {
|
|
||||||
this->ack_set_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Starting playback");
|
|
||||||
this->send_cmd_(0x0D);
|
|
||||||
}
|
|
||||||
void pause() {
|
|
||||||
this->ack_reset_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Pausing playback");
|
|
||||||
this->send_cmd_(0x0E);
|
|
||||||
}
|
|
||||||
void stop() {
|
|
||||||
this->ack_reset_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Stopping playback");
|
|
||||||
this->send_cmd_(0x16);
|
|
||||||
}
|
|
||||||
void random() {
|
|
||||||
this->ack_set_is_playing_ = true;
|
|
||||||
ESP_LOGD(TAG, "Playing random file");
|
|
||||||
this->send_cmd_(0x18);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_playing() { return is_playing_; }
|
bool is_playing() { return is_playing_; }
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
|
Loading…
Reference in a new issue