Probably should start another thread at this point, but this question is the same as the OP. Which I assume needs to be corrected to "read filename from SD card, initialize to a new array"
Here is some code demonstrating a async function (called every loop when active) in attempt to be created.
The challenge is accessing the returned (string/array?) as an array to deal with the letters of the filename independently. This way I can serve them to my haptic display to a user that types "ls" ala unix cli style.
void ls(boolean activate){ // list contents of working directory
static boolean active = false;
static File contents = workingDir.openNextFile();
static byte index = 0;
if(activate){ // given a 'true' is passed to ls it gets called every loop
active = !active;
if(!active){
index = 0;
contents.close();
contents.rewindDirectory();
}
}
if(active){ // when active 'ls' gets called every loop
if(extHapticMessage(MONITOR_MODE)){ // returns true on complete letter
if(contents){ // given a file
char name[15] = contents.name(); // <- problem: I dont know the size!
if(name[index]){ //
extHapticMessage(name[index]); // vibrates an series of pagers
keyOut(name[index]); // prints letter w/ keyboard emulation
index++; // iterate index for when pagers finish
} else { // when filename is printed
index = 0; // reset index
if(contents.isDirectory()){keyOut('/');} // trail a slash given dir
contents.close(); // gracefully close the file
keyOut(CARIAGE_RETURN); // prepare to print next filename
contents = workingDir.openNextFile(); // open next file
}
}
}
}
}
I apologize about my commenting style, I always make the assumption there is a syntax highlighter
This does not compile because the compiler wants to the the array (name[]) initialized to a brace-enclosed initializer. Which I can understand, it wants to know the size of what it is getting.
Is there an better way to directly access what (file).name() returns? Maybe in a way I can pick off the individual letters at a time? (file).name() Seems to pass to Serial.println() a char array without much fuss.