DYSV17Fmp3
Library for the DY-SV17F mp3 player
Loading...
Searching...
No Matches
DYSV17Fmp3.h
Go to the documentation of this file.
1/**
2 * @file DYSV17Fmp3.h
3 * @brief DY-SV17F MP3 Player Control Class
4 *
5 * This class provides an interface to control the DY-SV17F MP3 player module.
6 * It supports playing tracks by number or by filename/path, setting volume,
7 * and monitoring busy status.
8 */
9
10#ifndef DYSV17FMP3_H
11#define DYSV17FMP3_H
12
13#include <Arduino.h>
14
15/**
16 * @class DYSV17Fmp3
17 * @brief Controls a DY-SV17F MP3 player module
18 *
19 * The DYSV17Fmp3 class manages communication with the DY-SV17F MP3 player module.
20 * It handles sending commands, calculating checksums, and processing responses.
21 * The class is designed to work with any Stream object (HardwareSerial, SoftwareSerial, etc.)
22 */
24public:
25 /**
26 * @brief Construct a new DYSV17Fmp3 object
27 *
28 * @param stream Reference to the Stream object for communication with the MP3 module
29 * @param busyPin Arduino pin number connected to the MP3 module's busy output
30 */
31 DYSV17Fmp3(Stream& stream, uint8_t busyPin);
32
33 /**
34 * @brief Initialize the MP3 player module
35 *
36 * Sets up the busy pin as input and sends initial configuration commands
37 * including volume setting. Should be called once during setup.
38 */
39 void begin();
40
41 /**
42 * @brief monitors the busy line to produce debug output
43 *
44 */
45 void update();
46
47 /**
48 * @brief sends the software reset command
49 *
50 */
51 void reset();
52
53 /**
54 * @brief Stops the current playback
55 *
56 */
57 void stop();
58
59 /**
60 * @brief Set the volume of the MP3 player
61 *
62 * @param volume Volume level (0-30 typical range for DY-SV17F)
63 */
64 void setVolume(uint8_t volume);
65
66 /**
67 * @brief Play a track by its number/index
68 *
69 * @param songNumber Track number to play (0-63 typical range)
70 * @return true if command was sent successfully
71 * @return false if command failed
72 */
73 bool playNumber(uint8_t songNumber);
74
75 /**
76 * @brief Play a track by its filename or path
77 *
78 * @param path Filename or path to the track (max 16 characters)
79 * @return true if command was sent successfully
80 * @return false if path was invalid
81 */
82 bool playString(const char* path);
83
84 /**
85 * @brief Play a track by its filename or path and waits for busy
86 *
87 * @param path Filename or path to the track (max 16 characters)
88 * @return true if command was sent successfully and module is busy
89 * @return false if command failed or path was invalid
90 */
91 bool playStringWait(const char* path);
92
93 /**
94 * @brief Get the current busy state of the MP3 player
95 *
96 * @return true if MP3 player is busy (playing or processing)
97 * @return false if MP3 player is idle
98 */
99 bool isBusy();
100
101 /**
102 * @brief Wait for busy state to change or timeout
103 *
104 * Blocks until the busy pin state changes or timeout occurs.
105 * Useful for waiting for command completion.
106 *
107 * @param timeoutMs Maximum time to wait in milliseconds
108 * @return true if state changed, false if timeout occurred
109 */
110 bool waitForBusyChange(uint32_t timeoutMs = 250);
111
112private:
113 Stream& _stream; ///< Reference to the communication stream
114 uint8_t _busyPin; ///< Pin number for busy status input+
115
116 bool lastBusy = false; // previously read busy state
117 uint32_t busyTimer = 0; // time of last busy line change or command sent
118
119 /**
120 * @brief Calculate checksum for a command buffer
121 *
122 * @param buf Pointer to the command buffer
123 * @param len Length of the buffer (excluding checksum byte)
124 * @return uint8_t Calculated checksum value
125 */
126 uint8_t calculateChecksum(uint8_t* buf, uint8_t len);
127
128 /**
129 * @brief Send a command to the MP3 player
130 *
131 * Automatically calculates and appends the checksum byte.
132 * Waits for busy state change after sending.
133 *
134 * @param txbuf Pointer to the command buffer (including space for checksum)
135 * @param txlen Length of the command buffer including checksum byte location
136 */
137 void sendCommand(uint8_t* txbuf, uint8_t txlen);
138
139 /**
140 * @brief Send a command to the MP3 player
141 *
142 * Automatically calculates and appends the checksum byte.
143 * Waits for appropriate busy state before and after sending.
144 *
145 * @param txbuf Pointer to the command buffer (including space for checksum)
146 * @param txlen Length of the command buffer including checksum byte location
147 * @return true if command was sent and module became busy
148 * @return false if command failed
149 */
150 bool sendCommandWait(uint8_t* txbuf, uint8_t txlen);
151};
152
153#endif // DYSV17FMP3_H
bool playStringWait(const char *path)
Play a track by its filename or path and waits for busy.
Definition DYSV17Fmp3.cpp:93
DYSV17Fmp3(Stream &stream, uint8_t busyPin)
Construct a new DYSV17Fmp3 object.
Definition DYSV17Fmp3.cpp:14
bool playString(const char *path)
Play a track by its filename or path.
Definition DYSV17Fmp3.cpp:78
bool playNumber(uint8_t songNumber)
Play a track by its number/index.
Definition DYSV17Fmp3.cpp:69
void begin()
Initialize the MP3 player module.
Definition DYSV17Fmp3.cpp:18
void setVolume(uint8_t volume)
Set the volume of the MP3 player.
Definition DYSV17Fmp3.cpp:63
bool waitForBusyChange(uint32_t timeoutMs=250)
Wait for busy state to change or timeout.
Definition DYSV17Fmp3.cpp:111
void reset()
sends the software reset command
Definition DYSV17Fmp3.cpp:45
void stop()
Stops the current playback.
Definition DYSV17Fmp3.cpp:54
bool isBusy()
Get the current busy state of the MP3 player.
Definition DYSV17Fmp3.cpp:107
void update()
monitors the busy line to produce debug output
Definition DYSV17Fmp3.cpp:23