idigi_callback_status_t iDigiFileSystem::app_process_file_stat(idigi_file_stat_request_t * const request_data, idigi_file_stat_response_t * const response_data) { idigi_file_stat_t *pstat = &response_data->statbuf; idigi_callback_status_t status = idigi_callback_continue; SdFile entry = DigiSD.open(request_data->path); if (!entry.isOpen()) { APP_DEBUG("stat cannot open: %s\n", request_data->path); goto done; } pstat->last_modified = 0; // Last modified date unsupported: pstat->hash_alg = idigi_file_hash_none; // File hash not supported pstat->file_size = (size_t) entry.fileSize(); pstat->flags = 0; if (entry.isDir()) pstat->flags |= IDIGI_FILE_IS_DIR; else pstat->flags |= IDIGI_FILE_IS_REG; entry.close(); done: return status; }
/* Description: Requrest for a specific file at a specified position within the directory The path argument is identical to the path which was provided to last call to "mas_sdfat_move_to_pwd" */ uint8_t mas_sdfat_get_nth_file(const char *path, uint16_t n, char *buf, uint8_t *is_dir) { uint16_t c = 0; if ( mas_sdfat_move_to_pwd(path) == 0 ) return 0; if ( mas_sdfat_file_is_open != 0 ) { mas_sdfat_file.close(); mas_sdfat_file_is_open = 0; } mas_sdfat_sd->vwd()->rewind(); while (mas_sdfat_file.openNext(mas_sdfat_sd->vwd(), O_READ)) { if ( n == c ) { mas_sdfat_file.getFilename(buf); buf[12] = '\0'; *is_dir = mas_sdfat_file.isDir(); mas_sdfat_file.close(); return 1; } c++; mas_sdfat_file.close(); } return 0; }
idigi_callback_status_t iDigiFileSystem::app_process_file_opendir(idigi_file_path_request_t * const request_data, idigi_file_open_response_t * const response_data) { idigi_callback_status_t status = idigi_callback_continue; SdFile *dir = new SdFile; if (dir == NULL) { response_data->error->error_status = idigi_file_out_of_memory; } *dir = DigiSD.open(request_data->path); if (!dir->isOpen() || !dir->isDir()) { response_data->error->error_status = idigi_file_path_not_found; return status; } dir->rewind(); response_data->handle = dir; APP_DEBUG("opendir for %s returned %p\n", request_data->path, (void *) dir); return status; }
/** Change current working directory * * Changes the current working directory to the \a path subdirectory. * * Example: Executing chdir("SUB") in the "/DIR" directory will change the * current working directory from "/DIR" to "/DIR/SUB". * * \param[in] path The name of the subdirectory. * * \return The value one, true, is returned for success and * the value zero, false, is returned for failure. */ bool SdFat::chdir(const char *path) { SdFile dir; if (path[0] == '/' && path[1] == '\0') return chdir(); if (!dir.open(path, O_READ)) goto fail; if (!dir.isDir()) goto fail; cwd_ = dir; return true; fail: return false; }
boolean get_handler(AtMegaWebServer& web_server){ const char* filename = web_server.get_path(); #if DEBUG Serial << F("file_handler path: ") << filename << '\n'; #endif if (!filename) { web_server.sendHttpResult(404); #if DEBUG Serial << F("Could not parse URL"); #endif return true; } if(filename[0] == '/' && filename[1] == 0){ // root dir, file.open() will fail listDirectory(web_server, SdBaseFile::cwd()); return true; } SdFile file; if(file.open(filename, O_READ)){ #if DEBUG Serial << "file isOpen: " << filename << '\n'; #endif if (file.isDir()) { listDirectory(web_server, &file); } else { AtMegaWebServer::MimeType mime_type = AtMegaWebServer::get_mime_type_from_filename(filename); // If you want to send a file with a non-supported MimeType you can: // web_server.sendHttpResult(200, 0, "Content-Type: image/tiff" CRLF); web_server.sendHttpResult(200, mime_type); #if DEBUG Serial << F("Read file "); Serial.println(filename); #endif web_server.send_file(file); } file.close(); }else{ web_server.sendHttpResult(404); } return true; }
void SD_ListFiles(void) { Serial.begin(9600); while (!Serial) {} delay(1000); Serial.println(); while (file.openNext(sdf.vwd(), O_READ)) { file.printFileSize(&Serial); Serial.write(' '); file.printModifyDateTime(&Serial); Serial.write(' '); file.printName(&Serial); if (file.isDir()) { // Indicate a directory. Serial.write('/'); } Serial.println(); file.close(); } }
void MP3Player::PlayTrack(const char* dirName,int track_no,const char* track_name) { if(!PLAY) { finishSearch = false; int count=0; //if(track_no>0) //counter = track_no; if(!isPlayAll) { char temp[20]; isPlayAll = true; sd.chdir();delayMicroseconds(100000); sd.chdir(dirName,true); sd.vwd()->rewind(); sd.vwd()->getName(temp,20); currentDir = temp; counter = 0; } while(true) { if(myFile.openNext(myFile.cwd(), O_READ)) { char FileName[80]; myFile.getName(FileName,80); #if DEBUG //myFile.printName(&Serial); Serial.print(FileName); if (myFile.isDir()) { // Indicate a directory. Serial.write('/'); } Serial.println(); #endif if (!(myFile.isDir()||(String(FileName).indexOf(".mp3")==-1&&String(FileName).indexOf(".MP3")==-1))) { counter++; if(ls_flag) { Serial.print(counter); Serial.print(". "); Serial.print(FileName); Serial.print(" "); Serial.print(myFile.fileSize()); Serial.println(" bytes"); myFile.close(); continue; } //Play(FileName); if(!String(track_name).equals("")) { //counter++; if(String(track_name).equals(FileName)) { Play(FileName); //name = track_name; isPlayAll = false; break; } } else if(track_no==0) { //counter++; Play(FileName); break; } else if(track_no>0) { count++; if(count==track_no) { counter = track_no; Play(FileName); isPlayAll = false; break; } } } } else { isPlayAll = false; finishSearch = true; ls_flag = false; break; } //myFile.getFilename(FileName); myFile.close(); } } }