KG5NII
Member
I need a little help. My application is a T4.1 JPEG image slideshow application. I have implemented IR remote capability to not only change to next or previous album but also next photo and previous photo within an album. I define an album as a directory off the root of the SD Card:
and so on.
Inside each album (directory) are jpeg files. Some albums have thousands of files.
and so on.
The issue:
Now opening the album and retrieving the next photo in the album:
This is well and fine when walking forward in the album (directory). What I really need is something like an openPrevFile() method that will allow me to walk backwards in the directory from the current file backwards.
Looking at the openNextFile() code from the Teensy SD library:
I think I get part of it. Something is incrementing p, I'm guessing it is the line _file->dirName(p, name); as denoted by the "//<<<<------------". The deal is, there has to be a really good reason why an openPrevFile() method doesn't exist. What am I missing here?
Can someone please offer some advice? I don't care if I have to patch the SD library, though this is a PITA, I've already had to do that by adding a directory file count method which could only offer good performance by adding the method to the library. I hate doing this, but it is what it is. Oh I've got this working by using calloc and creating a huge array of all the filenames as we openNextFile() through the directory. I hate this. it's ugly, it over complicates the code and I'm ashamed to even say I went this route. Some of the albums may contain over 5K jpeg files. There has to be a better more efficient way. How are others handling this?
Thanks for reading.
Ron, KG5NII
Code:
001/
002/
003/
...
Inside each album (directory) are jpeg files. Some albums have thousands of files.
Code:
001/
1.jpg
2.jpg
3.jpg
4.jpg
...
n.jpg
and so on.
The issue:
Now opening the album and retrieving the next photo in the album:
Code:
File dir = SD.open("001");
while(true) {
File photo = dir.openNextFile();
if(!photo) break;
...
}
This is well and fine when walking forward in the album (directory). What I really need is something like an openPrevFile() method that will allow me to walk backwards in the directory from the current file backwards.
Looking at the openNextFile() code from the Teensy SD library:
Code:
// allows you to recurse into a directory
File File::openNextFile(uint8_t mode) {
dir_t p;
Serial.print("\t\treading dir...");
while (_file->readDir(&p) > 0) {
// done if past last used entry
if (p.name[0] == DIR_NAME_FREE) {
Serial.println("end");
return File();
}
// skip deleted entry and entries for . and ..
if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') {
Serial.println("dots");
continue;
}
// only list subdirectories and files
if (!DIR_IS_FILE_OR_SUBDIR(&p)) {
Serial.println("notafile");
continue;
}
// print file name with possible blank fill
SdFile f;
char name[13];
_file->dirName(p, name); //<<<<------------
Serial.print("try to open file ");
Serial.println(name);
if (f.open(_file, name, mode)) {
Serial.println("OK!");
return File(f, name);
} else {
Serial.println("ugh");
return File();
}
}
Serial.println("nothing");
return File();
}
I think I get part of it. Something is incrementing p, I'm guessing it is the line _file->dirName(p, name); as denoted by the "//<<<<------------". The deal is, there has to be a really good reason why an openPrevFile() method doesn't exist. What am I missing here?
Can someone please offer some advice? I don't care if I have to patch the SD library, though this is a PITA, I've already had to do that by adding a directory file count method which could only offer good performance by adding the method to the library. I hate doing this, but it is what it is. Oh I've got this working by using calloc and creating a huge array of all the filenames as we openNextFile() through the directory. I hate this. it's ugly, it over complicates the code and I'm ashamed to even say I went this route. Some of the albums may contain over 5K jpeg files. There has to be a better more efficient way. How are others handling this?
Thanks for reading.
Ron, KG5NII