LCD Driver, some teensy code, SDCard code, MBR/FAT32
This commit is contained in:
45
ext/sd/fat32/DirIterator.h
Normal file
45
ext/sd/fat32/DirIterator.h
Normal file
@@ -0,0 +1,45 @@
|
||||
class DirIterator {
|
||||
|
||||
FS& fs;
|
||||
ClusterNr nextCluster;
|
||||
int curEntryInCluster;
|
||||
uint8_t buf[512];
|
||||
|
||||
public:
|
||||
|
||||
DirIterator(FS& fs, ClusterNr clusterNr) : fs(fs), nextCluster(clusterNr), curEntryInCluster(255) {
|
||||
|
||||
}
|
||||
|
||||
bool hasNext() {
|
||||
|
||||
while(true) {
|
||||
|
||||
++curEntryInCluster;
|
||||
|
||||
// reached end of cluster? load the next one
|
||||
if (curEntryInCluster > fs.tmp.dirEntriesPerSector) {
|
||||
fs.dev.read(fs.clusterToAbsPos(nextCluster), 512, buf);
|
||||
nextCluster = fs.getNextCluster(nextCluster);
|
||||
curEntryInCluster = 0;
|
||||
}
|
||||
|
||||
DirEntry* desc = reinterpret_cast<DirEntry*>(buf + (sizeof(DirEntry) * curEntryInCluster));
|
||||
|
||||
if (desc->isLongFileName()) {continue;}
|
||||
if (desc->isUnused()) {continue;}
|
||||
if (desc->isEndOfDirectory()) {return false;}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DirEntry next() {
|
||||
DirEntry* de = reinterpret_cast<DirEntry*>(buf + (sizeof(DirEntry) * curEntryInCluster));
|
||||
return *de;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user