Skip to content

Commit fabbb01

Browse files
committed
update to 1.0.1 Fix the compiling error on Arduino.org IDE
1 parent 483c5f5 commit fabbb01

File tree

4 files changed

+57
-67
lines changed

4 files changed

+57
-67
lines changed

DFRobotDFPlayerMini.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ void DFRobotDFPlayerMini::uint16ToArray(uint16_t value, uint8_t *array){
2424

2525
uint16_t DFRobotDFPlayerMini::calculateCheckSum(uint8_t *buffer){
2626
uint16_t sum = 0;
27-
for (int i=Stack::Version; i<Stack::CheckSum; i++) {
27+
for (int i=Stack_Version; i<Stack_CheckSum; i++) {
2828
sum += buffer[i];
2929
}
3030
return -sum;
3131
}
3232

3333
void DFRobotDFPlayerMini::sendStack(){
34-
if (_sending[Stack::ACK]) {
34+
if (_sending[Stack_ACK]) {
3535
while (_isSending) {
3636
available();
3737
}
@@ -51,17 +51,17 @@ void DFRobotDFPlayerMini::sendStack(){
5151
#endif
5252
_serial->write(_sending, DFPLAYER_SEND_LENGTH);
5353
_timeOutTimer = millis();
54-
_isSending = _sending[Stack::ACK];
54+
_isSending = _sending[Stack_ACK];
5555
}
5656

5757
void DFRobotDFPlayerMini::sendStack(uint8_t command){
5858
sendStack(command, 0);
5959
}
6060

6161
void DFRobotDFPlayerMini::sendStack(uint8_t command, uint16_t argument){
62-
_sending[Stack::Command] = command;
63-
uint16ToArray(argument, _sending+Stack::Parameter);
64-
uint16ToArray(calculateCheckSum(_sending), _sending+Stack::CheckSum);
62+
_sending[Stack_Command] = command;
63+
uint16ToArray(argument, _sending+Stack_Parameter);
64+
uint16ToArray(calculateCheckSum(_sending), _sending+Stack_CheckSum);
6565
sendStack();
6666
}
6767

@@ -72,17 +72,17 @@ void DFRobotDFPlayerMini::sendStack(uint8_t command, uint8_t argumentHigh, uint8
7272
}
7373

7474
void DFRobotDFPlayerMini::enableACK(){
75-
_sending[Stack::ACK] = 0x01;
75+
_sending[Stack_ACK] = 0x01;
7676
}
7777

7878
void DFRobotDFPlayerMini::disableACK(){
79-
_sending[Stack::ACK] = 0x00;
79+
_sending[Stack_ACK] = 0x00;
8080
}
8181

8282
bool DFRobotDFPlayerMini::waitAvailable(){
8383
_isSending = true;
8484
while (!available());
85-
return _handleType != HandleType::TimeOut;
85+
return _handleType != TimeOut;
8686
}
8787

8888
bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){
@@ -102,7 +102,7 @@ bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){
102102
return (readType() == DFPlayerCardOnline) || !isACK;
103103
}
104104

105-
HandleType DFRobotDFPlayerMini::readType(){
105+
uint8_t DFRobotDFPlayerMini::readType(){
106106
_isAvailable = false;
107107
return _handleType;
108108
}
@@ -112,15 +112,15 @@ uint16_t DFRobotDFPlayerMini::read(){
112112
return _handleParameter;
113113
}
114114

115-
bool DFRobotDFPlayerMini::handleMessage(HandleType type, uint16_t parameter){
115+
bool DFRobotDFPlayerMini::handleMessage(uint8_t type, uint16_t parameter){
116116
_receivedIndex = 0;
117117
_handleType = type;
118118
_handleParameter = parameter;
119119
_isAvailable = true;
120120
return _isAvailable;
121121
}
122122

123-
bool DFRobotDFPlayerMini::handleError(HandleType type, uint16_t parameter){
123+
bool DFRobotDFPlayerMini::handleError(uint8_t type, uint16_t parameter){
124124
handleMessage(type, parameter);
125125
_isSending = false;
126126
}
@@ -131,30 +131,30 @@ uint8_t DFRobotDFPlayerMini::readCommand(){
131131
}
132132

133133
void DFRobotDFPlayerMini::parseStack(){
134-
_handleCommand = *(_received + Stack::Command);
135-
_handleParameter = arrayToUint16(_received + Stack::Parameter);
134+
_handleCommand = *(_received + Stack_Command);
135+
_handleParameter = arrayToUint16(_received + Stack_Parameter);
136136

137137
switch (_handleCommand) {
138138
case 0x3D:
139-
handleMessage(HandleType::DFPlayerPlayFinished, _handleParameter);
139+
handleMessage(DFPlayerPlayFinished, _handleParameter);
140140
break;
141141
case 0x3F:
142142
if (_handleParameter & 0x02) {
143-
handleMessage(HandleType::DFPlayerCardOnline, _handleParameter);
143+
handleMessage(DFPlayerCardOnline, _handleParameter);
144144
}
145145
break;
146146
case 0x3A:
147147
if (_handleParameter & 0x02) {
148-
handleMessage(HandleType::DFPlayerCardInserted, _handleParameter);
148+
handleMessage(DFPlayerCardInserted, _handleParameter);
149149
}
150150
break;
151151
case 0x3B:
152152
if (_handleParameter & 0x02) {
153-
handleMessage(HandleType::DFPlayerCardRemoved, _handleParameter);
153+
handleMessage(DFPlayerCardRemoved, _handleParameter);
154154
}
155155
break;
156156
case 0x40:
157-
handleMessage(HandleType::DFPlayerError, _handleParameter);
157+
handleMessage(DFPlayerError, _handleParameter);
158158
break;
159159
case 0x41:
160160
_isSending = false;
@@ -190,19 +190,19 @@ uint16_t DFRobotDFPlayerMini::arrayToUint16(uint8_t *array){
190190
}
191191

192192
bool DFRobotDFPlayerMini::validateStack(){
193-
return calculateCheckSum(_received) == arrayToUint16(_received+Stack::CheckSum);
193+
return calculateCheckSum(_received) == arrayToUint16(_received+Stack_CheckSum);
194194
}
195195

196196
bool DFRobotDFPlayerMini::available(){
197197
while (_serial->available()) {
198198
if (_receivedIndex == 0) {
199-
_received[Stack::Header] = _serial->read();
199+
_received[Stack_Header] = _serial->read();
200200
#ifdef _DEBUG
201201
Serial.print(F("received:"));
202202
Serial.print(_received[_receivedIndex],HEX);
203203
Serial.print(F(" "));
204204
#endif
205-
if (_received[Stack::Header] == 0x7E) {
205+
if (_received[Stack_Header] == 0x7E) {
206206
_isAvailable = false;
207207
_receivedIndex ++;
208208
}
@@ -214,17 +214,17 @@ bool DFRobotDFPlayerMini::available(){
214214
Serial.print(F(" "));
215215
#endif
216216
switch (_receivedIndex) {
217-
case Stack::Version:
217+
case Stack_Version:
218218
if (_received[_receivedIndex] != 0xFF) {
219219
return handleError(WrongStack);
220220
}
221221
break;
222-
case Stack::Length:
222+
case Stack_Length:
223223
if (_received[_receivedIndex] != 0x06) {
224224
return handleError(WrongStack);
225225
}
226226
break;
227-
case Stack::End:
227+
case Stack_End:
228228
#ifdef _DEBUG
229229
Serial.println();
230230
#endif
@@ -235,7 +235,7 @@ bool DFRobotDFPlayerMini::available(){
235235
if (validateStack()) {
236236
_receivedIndex = 0;
237237
parseStack();
238-
if (_isAvailable && !_sending[Stack::ACK]) {
238+
if (_isAvailable && !_sending[Stack_ACK]) {
239239
_isSending = false;
240240
}
241241
return _isAvailable;

DFRobotDFPlayerMini.h

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,30 @@
3535

3636
//#define _DEBUG
3737

38-
enum HandleType{
39-
TimeOut,
40-
WrongStack,
41-
DFPlayerCardInserted,
42-
DFPlayerCardRemoved,
43-
DFPlayerCardOnline,
44-
DFPlayerPlayFinished,
45-
DFPlayerError
46-
};
47-
48-
enum DFPlayerErrorType{
49-
Busy = 1,
50-
Sleeping,
51-
SerialWrongStack,
52-
CheckSumNotMatch,
53-
FileIndexOut,
54-
FileMismatch,
55-
Advertise
56-
};
57-
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
5862

5963
class DFRobotDFPlayerMini {
6064
Stream* _serial;
@@ -88,28 +92,16 @@ class DFRobotDFPlayerMini {
8892

8993
uint8_t device = DFPLAYER_DEVICE_SD;
9094

91-
92-
enum Stack{
93-
Header = 0,
94-
Version = 1,
95-
Length = 2,
96-
Command = 3,
97-
ACK = 4,
98-
Parameter = 5,
99-
CheckSum = 7,
100-
End = 9
101-
};
102-
10395
public:
10496

105-
HandleType _handleType;
97+
uint8_t _handleType;
10698
uint8_t _handleCommand;
10799
uint16_t _handleParameter;
108100
bool _isAvailable = false;
109101
bool _isSending = false;
110102

111-
bool handleMessage(HandleType type, uint16_t parameter = 0);
112-
bool handleError(HandleType type, uint16_t parameter = 0);
103+
bool handleMessage(uint8_t type, uint16_t parameter = 0);
104+
bool handleError(uint8_t type, uint16_t parameter = 0);
113105

114106
uint8_t readCommand();
115107

@@ -119,7 +111,7 @@ class DFRobotDFPlayerMini {
119111

120112
bool available();
121113

122-
HandleType readType();
114+
uint8_t readType();
123115

124116
uint16_t read();
125117

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# DFPlayer - A Mini MP3 Player For Arduino
22
DFPlayer - A Mini MP3 Player For Arduino
3-
43
https://www.dfrobot.com/index.php?route=product/product&product_id=1121
54

65
This example shows the all the function of library for DFPlayer.
@@ -16,5 +15,4 @@ Notice and Trouble shooting
1615

1716
1.Connection and Diagram can be found here
1817
https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram
19-
20-
2.This code is tested on Arduino Uno, Leonardo, Mega boards.
18+
2.This code is tested on Arduino Uno, Leonardo, Mega boards.

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=DFRobotDFPlayerMini
2-
version=1.0.0
2+
version=1.0.1
33
author=DFRobot
44
maintainer=Angelo <[email protected]>
55
sentence=Driver for DFPlayer Mini from DFRobot
6-
paragraph=Easy-to-use and reliable library for DFPlayer Mini
6+
paragraph=Easy-to-use and reliable library for DFPlayer Mini
77
category=Sensors
88
url=https://github.com/DFRobot/DFRobotDFPlayerMini
99
architectures=*

0 commit comments

Comments
 (0)