Skip to content

Commit c36911d

Browse files
authored
Merge pull request #5 from jandelgado/make_call_to_init_optional
Made the call to init() in DFRobotDFPlayerMini::begin() optional.
2 parents 0cf620c + 20343d6 commit c36911d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

DFRobotDFPlayerMini.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool DFRobotDFPlayerMini::waitAvailable(){
8888
return _handleType != TimeOut;
8989
}
9090

91-
bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){
91+
bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK, bool doReset){
9292
if (isACK) {
9393
enableACK();
9494
}
@@ -97,11 +97,18 @@ bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){
9797
}
9898

9999
_serial = &stream;
100-
_timeOutDuration += 3000;
101-
reset();
102-
waitAvailable();
103-
_timeOutDuration -= 3000;
104-
delay(200);
100+
101+
if (doReset) {
102+
_timeOutDuration += 3000;
103+
reset();
104+
waitAvailable();
105+
_timeOutDuration -= 3000;
106+
delay(200);
107+
} else {
108+
// assume same state as with reset(): online
109+
_handleType = DFPlayerCardOnline;
110+
}
111+
105112
return (readType() == DFPlayerCardOnline) || !isACK;
106113
}
107114

DFRobotDFPlayerMini.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class DFRobotDFPlayerMini {
105105

106106
uint8_t readCommand();
107107

108-
bool begin(Stream& stream, bool isACK = true);
108+
bool begin(Stream& stream, bool isACK = true, bool doReset = true);
109109

110110
bool waitAvailable();
111111

0 commit comments

Comments
 (0)