how to use "dir(void (*callback)(char *))"?

Status
Not open for further replies.

NikoTeen

Well-known member
In a code example there is a function to print a directory.
The function:
Code:
/* Prints a directory.
 * Callback must point to a function that prints one string. void SdPlayClass::dir(void (*callback)(char *))  */

void SdPlayClass::dir(void (*callback)(char *))
{
  if(!_pBuf) {
    _lastError = SSDA_ERROR_NOT_INIT;
  } else {
      stop(*SimpleSDAudio_Timer);
      SD_L2_Dir(0, 0x00, 0x18, callback);
  }
}
I don't know how to call dir() to print with Serial.
Can somebody tell me how?
 
Looks like it wants a callback function to do the actual printing. Something like this should work I assume (untested)

Code:
void somename(const char* myString)
{
     Serial.println(myString);
}



void setup()
{    
 //...      
}


void loop()
{
    //...
    player.dir(somename)   
    //...
}
 
That's tricky.
Without "const" it works.
Code:
void somename(char* myString)
{
     Serial.println(myString);
}

Thank you
 
Good, the advantage of such a pattern is that it enables the user to print onto whatever she wants. (Serial, LCD, 3d cookie printer ....)
 
Status
Not open for further replies.
Back
Top