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