@@ -24,14 +24,14 @@ void DFRobotDFPlayerMini::uint16ToArray(uint16_t value, uint8_t *array){
24
24
25
25
uint16_t DFRobotDFPlayerMini::calculateCheckSum (uint8_t *buffer){
26
26
uint16_t sum = 0 ;
27
- for (int i=Stack::Version ; i<Stack::CheckSum ; i++) {
27
+ for (int i=Stack_Version ; i<Stack_CheckSum ; i++) {
28
28
sum += buffer[i];
29
29
}
30
30
return -sum;
31
31
}
32
32
33
33
void DFRobotDFPlayerMini::sendStack (){
34
- if (_sending[Stack::ACK ]) {
34
+ if (_sending[Stack_ACK ]) {
35
35
while (_isSending) {
36
36
available ();
37
37
}
@@ -51,17 +51,17 @@ void DFRobotDFPlayerMini::sendStack(){
51
51
#endif
52
52
_serial->write (_sending, DFPLAYER_SEND_LENGTH);
53
53
_timeOutTimer = millis ();
54
- _isSending = _sending[Stack::ACK ];
54
+ _isSending = _sending[Stack_ACK ];
55
55
}
56
56
57
57
void DFRobotDFPlayerMini::sendStack (uint8_t command){
58
58
sendStack (command, 0 );
59
59
}
60
60
61
61
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 );
65
65
sendStack ();
66
66
}
67
67
@@ -72,17 +72,17 @@ void DFRobotDFPlayerMini::sendStack(uint8_t command, uint8_t argumentHigh, uint8
72
72
}
73
73
74
74
void DFRobotDFPlayerMini::enableACK (){
75
- _sending[Stack::ACK ] = 0x01 ;
75
+ _sending[Stack_ACK ] = 0x01 ;
76
76
}
77
77
78
78
void DFRobotDFPlayerMini::disableACK (){
79
- _sending[Stack::ACK ] = 0x00 ;
79
+ _sending[Stack_ACK ] = 0x00 ;
80
80
}
81
81
82
82
bool DFRobotDFPlayerMini::waitAvailable (){
83
83
_isSending = true ;
84
84
while (!available ());
85
- return _handleType != HandleType:: TimeOut;
85
+ return _handleType != TimeOut;
86
86
}
87
87
88
88
bool DFRobotDFPlayerMini::begin (Stream &stream, bool isACK){
@@ -102,7 +102,7 @@ bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){
102
102
return (readType () == DFPlayerCardOnline) || !isACK;
103
103
}
104
104
105
- HandleType DFRobotDFPlayerMini::readType (){
105
+ uint8_t DFRobotDFPlayerMini::readType (){
106
106
_isAvailable = false ;
107
107
return _handleType;
108
108
}
@@ -112,15 +112,15 @@ uint16_t DFRobotDFPlayerMini::read(){
112
112
return _handleParameter;
113
113
}
114
114
115
- bool DFRobotDFPlayerMini::handleMessage (HandleType type, uint16_t parameter){
115
+ bool DFRobotDFPlayerMini::handleMessage (uint8_t type, uint16_t parameter){
116
116
_receivedIndex = 0 ;
117
117
_handleType = type;
118
118
_handleParameter = parameter;
119
119
_isAvailable = true ;
120
120
return _isAvailable;
121
121
}
122
122
123
- bool DFRobotDFPlayerMini::handleError (HandleType type, uint16_t parameter){
123
+ bool DFRobotDFPlayerMini::handleError (uint8_t type, uint16_t parameter){
124
124
handleMessage (type, parameter);
125
125
_isSending = false ;
126
126
}
@@ -131,30 +131,30 @@ uint8_t DFRobotDFPlayerMini::readCommand(){
131
131
}
132
132
133
133
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 );
136
136
137
137
switch (_handleCommand) {
138
138
case 0x3D :
139
- handleMessage (HandleType:: DFPlayerPlayFinished, _handleParameter);
139
+ handleMessage (DFPlayerPlayFinished, _handleParameter);
140
140
break ;
141
141
case 0x3F :
142
142
if (_handleParameter & 0x02 ) {
143
- handleMessage (HandleType:: DFPlayerCardOnline, _handleParameter);
143
+ handleMessage (DFPlayerCardOnline, _handleParameter);
144
144
}
145
145
break ;
146
146
case 0x3A :
147
147
if (_handleParameter & 0x02 ) {
148
- handleMessage (HandleType:: DFPlayerCardInserted, _handleParameter);
148
+ handleMessage (DFPlayerCardInserted, _handleParameter);
149
149
}
150
150
break ;
151
151
case 0x3B :
152
152
if (_handleParameter & 0x02 ) {
153
- handleMessage (HandleType:: DFPlayerCardRemoved, _handleParameter);
153
+ handleMessage (DFPlayerCardRemoved, _handleParameter);
154
154
}
155
155
break ;
156
156
case 0x40 :
157
- handleMessage (HandleType:: DFPlayerError, _handleParameter);
157
+ handleMessage (DFPlayerError, _handleParameter);
158
158
break ;
159
159
case 0x41 :
160
160
_isSending = false ;
@@ -190,19 +190,19 @@ uint16_t DFRobotDFPlayerMini::arrayToUint16(uint8_t *array){
190
190
}
191
191
192
192
bool DFRobotDFPlayerMini::validateStack (){
193
- return calculateCheckSum (_received) == arrayToUint16 (_received+Stack::CheckSum );
193
+ return calculateCheckSum (_received) == arrayToUint16 (_received+Stack_CheckSum );
194
194
}
195
195
196
196
bool DFRobotDFPlayerMini::available (){
197
197
while (_serial->available ()) {
198
198
if (_receivedIndex == 0 ) {
199
- _received[Stack::Header ] = _serial->read ();
199
+ _received[Stack_Header ] = _serial->read ();
200
200
#ifdef _DEBUG
201
201
Serial.print (F (" received:" ));
202
202
Serial.print (_received[_receivedIndex],HEX);
203
203
Serial.print (F (" " ));
204
204
#endif
205
- if (_received[Stack::Header ] == 0x7E ) {
205
+ if (_received[Stack_Header ] == 0x7E ) {
206
206
_isAvailable = false ;
207
207
_receivedIndex ++;
208
208
}
@@ -214,17 +214,17 @@ bool DFRobotDFPlayerMini::available(){
214
214
Serial.print (F (" " ));
215
215
#endif
216
216
switch (_receivedIndex) {
217
- case Stack::Version :
217
+ case Stack_Version :
218
218
if (_received[_receivedIndex] != 0xFF ) {
219
219
return handleError (WrongStack);
220
220
}
221
221
break ;
222
- case Stack::Length :
222
+ case Stack_Length :
223
223
if (_received[_receivedIndex] != 0x06 ) {
224
224
return handleError (WrongStack);
225
225
}
226
226
break ;
227
- case Stack::End :
227
+ case Stack_End :
228
228
#ifdef _DEBUG
229
229
Serial.println ();
230
230
#endif
@@ -235,7 +235,7 @@ bool DFRobotDFPlayerMini::available(){
235
235
if (validateStack ()) {
236
236
_receivedIndex = 0 ;
237
237
parseStack ();
238
- if (_isAvailable && !_sending[Stack::ACK ]) {
238
+ if (_isAvailable && !_sending[Stack_ACK ]) {
239
239
_isSending = false ;
240
240
}
241
241
return _isAvailable;
0 commit comments