forked from DFRobot/DFRobotDFPlayerMini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DFRobotDFPlayerMini.h
201 lines (129 loc) · 3.89 KB
/
DFRobotDFPlayerMini.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*!
* @file DFRobotDFPlayerMini.h
* @brief DFPlayer - An Arduino Mini MP3 Player From DFRobot
* @n Header file for DFRobot's DFPlayer
*
* @copyright [DFRobot]( http://www.dfrobot.com ), 2016
* @copyright GNU Lesser General Public License
*
* @author [Angelo](Angelo.qiao@dfrobot.com)
* @version V1.0.3
* @date 2016-12-07
*/
#include "Arduino.h"
#ifndef DFRobotDFPlayerMini_cpp
#define DFRobotDFPlayerMini_cpp
#define DFPLAYER_EQ_NORMAL 0
#define DFPLAYER_EQ_POP 1
#define DFPLAYER_EQ_ROCK 2
#define DFPLAYER_EQ_JAZZ 3
#define DFPLAYER_EQ_CLASSIC 4
#define DFPLAYER_EQ_BASS 5
#define DFPLAYER_DEVICE_U_DISK 1
#define DFPLAYER_DEVICE_SD 2
#define DFPLAYER_DEVICE_AUX 3
#define DFPLAYER_DEVICE_SLEEP 4
#define DFPLAYER_DEVICE_FLASH 5
#define DFPLAYER_RECEIVED_LENGTH 10
#define DFPLAYER_SEND_LENGTH 10
//#define _DEBUG
#define TimeOut 0
#define WrongStack 1
#define DFPlayerCardInserted 2
#define DFPlayerCardRemoved 3
#define DFPlayerCardOnline 4
#define DFPlayerPlayFinished 5
#define DFPlayerError 6
#define DFPlayerUSBInserted 7
#define DFPlayerUSBRemoved 8
#define DFPlayerUSBOnline 9
#define DFPlayerCardUSBOnline 10
#define DFPlayerFeedBack 11
#define Busy 1
#define Sleeping 2
#define SerialWrongStack 3
#define CheckSumNotMatch 4
#define FileIndexOut 5
#define FileMismatch 6
#define Advertise 7
#define Stack_Header 0
#define Stack_Version 1
#define Stack_Length 2
#define Stack_Command 3
#define Stack_ACK 4
#define Stack_Parameter 5
#define Stack_CheckSum 7
#define Stack_End 9
class DFRobotDFPlayerMini {
Stream* _serial;
unsigned long _timeOutTimer;
unsigned long _timeOutDuration = 500;
uint8_t _received[DFPLAYER_RECEIVED_LENGTH];
uint8_t _sending[DFPLAYER_SEND_LENGTH] = {0x7E, 0xFF, 06, 00, 01, 00, 00, 00, 00, 0xEF};
uint8_t _receivedIndex=0;
void sendStack();
void sendStack(uint8_t command);
void sendStack(uint8_t command, uint16_t argument);
void sendStack(uint8_t command, uint8_t argumentHigh, uint8_t argumentLow);
void enableACK();
void disableACK();
void uint16ToArray(uint16_t value,uint8_t *array);
uint16_t arrayToUint16(uint8_t *array);
uint16_t calculateCheckSum(uint8_t *buffer);
void parseStack();
bool validateStack();
uint8_t device = DFPLAYER_DEVICE_SD;
public:
uint8_t _handleType;
uint8_t _handleCommand;
uint16_t _handleParameter;
bool _isAvailable = false;
bool _isSending = false;
bool handleMessage(uint8_t type, uint16_t parameter = 0);
bool handleError(uint8_t type, uint16_t parameter = 0);
uint8_t readCommand();
bool begin(Stream& stream, bool isACK = true, bool doReset = true);
bool waitAvailable(unsigned long duration = 0);
bool available();
uint8_t readType();
uint16_t read();
void setTimeOut(unsigned long timeOutDuration);
void next();
void previous();
void play(int fileNumber=1);
void volumeUp();
void volumeDown();
void volume(uint8_t volume);
void EQ(uint8_t eq);
void loop(int fileNumber);
void outputDevice(uint8_t device);
void sleep();
void reset();
void start();
void pause();
void playFolder(uint8_t folderNumber, uint8_t fileNumber);
void outputSetting(bool enable, uint8_t gain);
void enableLoopAll();
void disableLoopAll();
void playMp3Folder(int fileNumber);
void advertise(int fileNumber);
void playLargeFolder(uint8_t folderNumber, uint16_t fileNumber);
void stopAdvertise();
void stop();
void loopFolder(int folderNumber);
void randomAll();
void enableLoop();
void disableLoop();
void enableDAC();
void disableDAC();
int readState();
int readVolume();
int readEQ();
int readFileCounts(uint8_t device);
int readCurrentFileNumber(uint8_t device);
int readFileCountsInFolder(int folderNumber);
int readFileCounts();
int readFolderCounts();
int readCurrentFileNumber();
};
#endif