I've read about some trouble with this library
- slow
- wrong feedback e.g. for files in folder
I have a look to this and have some findings
the instruction sendStack line 33
inside the loop waitAvailable is with default timeout, it can be reduced to 20ms because it should only update the _isSending Flag
this is the reason for the slow behaviour
void DFRobotDFPlayerMini::sendStack(){
if (_sending[Stack_ACK]) { //if the ack mode is on wait until the last transmition
while (_isSending) { // the loop update _isSending flage not _isAvailable, therfore short timeout LK
delay(0);
waitAvailable(25); //short timeout to 25ms
}
}
#ifdef _DEBUG
for (int i=0; i<DFPLAYER_SEND_LENGTH; i++) {
Serial.print(_sending[i],HEX);
Serial.print(F(" "));
}
Serial.println();
#endif
_serial->write(_sending, DFPLAYER_SEND_LENGTH);
_timeOutTimer = millis();
_isSending = _sending[Stack_ACK];
debugs7(_isSending);
if (!_sending[Stack_ACK]) { //if the ack mode is off wait 10 ms after one transmition.
delay(10);
}
}
the instruction handleMessage line 131
it sets _isAvailable to true also if there is an error, i think that make no sense
my change
bool DFRobotDFPlayerMini::handleMessage(uint8_t type, uint16_t parameter){
_receivedIndex = 0;
_handleType = type;
_handleParameter = parameter;
if (type==TimeOut|type==WrongStack) {_isAvailable=false;}else{_isAvailable=true;} //Änderung LK statt Zeiler darunter
//_isAvailable = true; // wenn von handleError aufgerufen dann stimmt das nicht weil es gibt keine Nachricht, d.h. type==timout oder wrongstack dann false LK
debugs8(_isAvailable);
return _isAvailable;
}
and at least I create a instruction that wil wait for the Acknoledge
I've add this after each sendStack(0xhex) instruction which will only expect an acknolede if this mode is enabled
e.g.
void DFRobotDFPlayerMini::loop(int fileNumber) {
sendStack(0x08, fileNumber);
waitAck();
}
the waitAck itsel is this code, sure it must also be added to the header file
bool DFRobotDFPlayerMini::waitAck(){
uint8_t errcnt=0;
if(_sending[Stack_ACK]){
while(_handleCommand!=0x41){
waitAvailable(25);
errcnt++;
if (errcnt=20) {return false;}
}
}
return true;
}
i have checked the software with this chip AA20HFJ648 in the dfplayer mini module, but checked also the message with a logic analyzer and it seems it will work