From 20343d62edb38196d4f1db85977d76e325165729 Mon Sep 17 00:00:00 2001 From: Jan Delgado Date: Tue, 13 Jun 2017 15:45:19 +0200 Subject: [PATCH] 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()). --- DFRobotDFPlayerMini.cpp | 19 +++++++++++++------ DFRobotDFPlayerMini.h | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/DFRobotDFPlayerMini.cpp b/DFRobotDFPlayerMini.cpp index c58da12..8b903ff 100644 --- a/DFRobotDFPlayerMini.cpp +++ b/DFRobotDFPlayerMini.cpp @@ -88,7 +88,7 @@ bool DFRobotDFPlayerMini::waitAvailable(){ return _handleType != TimeOut; } -bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){ +bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK, bool doReset){ if (isACK) { enableACK(); } @@ -97,11 +97,18 @@ bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK){ } _serial = &stream; - _timeOutDuration += 3000; - reset(); - waitAvailable(); - _timeOutDuration -= 3000; - delay(200); + + if (doReset) { + _timeOutDuration += 3000; + reset(); + waitAvailable(); + _timeOutDuration -= 3000; + delay(200); + } else { + // assume same state as with reset(): online + _handleType = DFPlayerCardOnline; + } + return (readType() == DFPlayerCardOnline) || !isACK; } diff --git a/DFRobotDFPlayerMini.h b/DFRobotDFPlayerMini.h index 825e8dd..ec72f19 100644 --- a/DFRobotDFPlayerMini.h +++ b/DFRobotDFPlayerMini.h @@ -105,7 +105,7 @@ class DFRobotDFPlayerMini { uint8_t readCommand(); - bool begin(Stream& stream, bool isACK = true); + bool begin(Stream& stream, bool isACK = true, bool doReset = true); bool waitAvailable();