Skip to content

Commit 20343d6

Browse files
jandelgadoiotlabopenmunich
authored andcommitted
Made the call to init() in DFRobotDFPlayerMini::begin() optional.
Ratio: calling init() after the module is initially powered on is not necessary and leads a) to an additional startup latency and b) (more annoying) to a loud "plop" sound on the speaker output of the DFPlayerMini module. By adding an optional parameter doReset to the begin() method, the user can now decide, if the reset should be peformed. Default is true, which is same behaviour as now (i.e. perform reset()).
1 parent 31d5ec1 commit 20343d6

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)