boolean newSD::findIndex(char *fileName,unsigned int &songindex) { unsigned char dname[11]; // name formated for dir entry dir_t* p; // pointer to cached dir entry // error if invalid name unsigned int _rootDirEntryCount = file.rootDirEntryCount(); if (!make83Name(fileName, dname)) return false;//false for (uint16_t index = 0; index < _rootDirEntryCount; index++) { if (!(p = file.dbgCacheDir(index))) return false;//false if (p->name[0] == DIR_NAME_FREE || p->name[0] == DIR_NAME_DELETED) { // done if no entries follow if (p->name[0] == DIR_NAME_FREE) break; } else if (!memcmp(dname, p->name, 11)) { songindex = index; return true; } } }
boolean newSD::traverseRootSong(unsigned int songIndex[], unsigned char &totalNum) { dir_t* p; // pointer to directory entry unsigned int _rootDirEntryCount = file.rootDirEntryCount(); Serial.println("All songs in the root directory:"); for (unsigned int index = 0; index < _rootDirEntryCount; index++) { if (!(p = file.dbgCacheDir(index))) return false; if (p->name[0] == DIR_NAME_FREE) return true; else if(p->name[0] == DIR_NAME_DELETED)continue; else if((p->name[8] == 'M')&&(p->name[9] == 'P')&&(p->name[10] == '3')){ songIndex[totalNum] = index; totalNum ++; ucharArray2String(p->name); } else if((p->name[8] == 'W')&&(p->name[9] == 'A')&&(p->name[10] == 'V')){ songIndex[totalNum] = index; totalNum ++; ucharArray2String(p->name); } else if((p->name[8] == 'W')&&(p->name[9] == 'M')&&(p->name[10] == 'A')){ songIndex[totalNum] = index; totalNum ++; ucharArray2String(p->name); } else if((p->name[8] == 'M')&&(p->name[9] == 'I')&&(p->name[10] == 'D')){ songIndex[totalNum] = index; totalNum ++; ucharArray2String(p->name); } else if((p->name[8] == 'O')&&(p->name[9] == 'G')&&(p->name[10] == 'G')){ songIndex[totalNum] = index; totalNum ++; ucharArray2String(p->name); } if(totalNum == 100)return true; } }