コード例 #1
0
// Enumerate and possibly display the animated GIF filenames in GIFS directory
int enumerateGIFFiles(const char *directoryName, boolean displayFilenames) {

    numberOfFiles = 0;

    // Set the current working directory
    if (! sd.chdir(directoryName, true)) {
        sd.errorHalt("Could not change to gifs directory");
    }
    sd.vwd()->rewind();

    char fn[13];
    while (file.openNext(sd.vwd(), O_READ)) {
        file.getName(fn, 13);
        // If filename not deleted, count it
        if (fn[0] != '_') {
            numberOfFiles++;
            if (displayFilenames) {
                Serial.println(fn);
                delay(20);
            }
        }
        file.close();
    }
    // Set the current working directory
    if (! sd.chdir("/", true)) {
        sd.errorHalt("Could not change to root directory");
    }
    return numberOfFiles;
}
コード例 #2
0
ファイル: mas_sdfat.cpp プロジェクト: AleXDev25/arduino
/*
  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;
}
コード例 #3
0
ファイル: sdfi.cpp プロジェクト: ro0lz/_CANcrusher_ARM
uint16_t SD_NumberOfFiles(void)
{
    uint16_t fileCount = 0;

    buffer[0] = 0x01;
    usb_rawhid_send(buffer, 100);
    while(file.openNext(sdf.vwd(), O_READ))
    {
        fileCount++;

        buffer[0]++;
        usb_rawhid_send(buffer, 100);

    }
    file.close();
    return fileCount;
}
コード例 #4
0
ファイル: sdfi.cpp プロジェクト: ro0lz/_CANcrusher_ARM
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();
    }
}
コード例 #5
0
// Get the full path/filename of the GIF file with specified index
void getGIFFilenameByIndex(const char *directoryName, int index, char *pnBuffer) {

    char filename[13];

    // Make sure index is in range
    if ((index >= 0) && (index < numberOfFiles)) {

        // Set the current working directory
        if (! sd.chdir(directoryName, true)) {
            sd.errorHalt("Could not change to gifs directory");
        }

        // Make sure file is closed before starting
        file.close();

        // Rewind the directory to the beginning
        sd.vwd()->rewind();

        while ((file.openNext(sd.vwd(), O_READ)) && (index >= 0)) {

            file.getName(filename, 13);

            // If filename is not marked as deleted, count it
            if ((filename[0] != '_') && (filename[0] != '~')) {
                index--;
            }
            file.close();
        }
        // Set the current working directory back to root
        if (! sd.chdir("/", true)) {
            sd.errorHalt("Could not change to root directory");
        }
        // Copy the directory name into the pathname buffer
        strcpy(pnBuffer, directoryName);

        // Append the filename to the pathname
        strcat(pnBuffer, filename);
    }
}
コード例 #6
0
ファイル: mas_sdfat.cpp プロジェクト: AleXDev25/arduino
uint16_t mas_sdfat_get_directory_file_cnt(const char *path)
{
  uint8_t cnt;
  cnt = 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)) 
  {
    cnt++;
    mas_sdfat_file.close();
    if ( cnt == 0x0ffff )
      break;
  }
  return cnt;
}
コード例 #7
0
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();
	}
	}
	
}
コード例 #8
0
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  
  // Wait for USB Serial 
  while (!Serial) {
    SysCall::yield();
  }
  delay(1000);

  cout << F("Type any character to start\n");
  // Wait for input line and discard.
  cin.readline();
  cout << endl;
  
  // Initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.begin(SD_CHIP_SELECT, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }
  if (sd.exists("Folder1") 
    || sd.exists("Folder1/file1.txt")
    || sd.exists("Folder1/File2.txt")) {
    error("Please remove existing Folder1, file1.txt, and File2.txt");
  }
  int rootFileCount = 0;
  sd.vwd()->rewind();   
  while (file.openNext(sd.vwd(), O_READ)) {
    if (!file.isHidden()) {
      rootFileCount++;
    }
    file.close();
    if (rootFileCount > 10) {
      error("Too many files in root. Please use an empty SD.");
    }
  }
  if (rootFileCount) {
    cout << F("\nPlease use an empty SD for best results.\n\n");
    delay(1000);    
  }
  // Create a new folder.
  if (!sd.mkdir("Folder1")) {
    error("Create Folder1 failed");
  }
  cout << F("Created Folder1\n");

  // Create a file in Folder1 using a path.
  if (!file.open("Folder1/file1.txt", O_CREAT | O_WRITE)) {
    error("create Folder1/file1.txt failed");
  }
  file.close();
  cout << F("Created Folder1/file1.txt\n");

  // Change volume working directory to Folder1.
  if (!sd.chdir("Folder1")) {
    error("chdir failed for Folder1.\n");
  }
  cout << F("chdir to Folder1\n");

  // Create File2.txt in current directory.
  if (!file.open("File2.txt", O_CREAT | O_WRITE)) {
    error("create File2.txt failed");
  }
  file.close();
  cout << F("Created File2.txt in current directory\n");

  cout << F("\nList of files on the SD.\n");
  sd.ls("/", LS_R);

  // Remove files from current directory.
  if (!sd.remove("file1.txt") || !sd.remove("File2.txt")) {
    error("remove failed");
  }
  cout << F("\nfile1.txt and File2.txt removed.\n");

  // Change current directory to root.
  if (!sd.chdir()) {
    error("chdir to root failed.\n");
  }

  cout << F("\nList of files on the SD.\n");
  sd.ls(LS_R);

  // Remove Folder1.
  if (!sd.rmdir("Folder1")) {
    error("rmdir for Folder1 failed\n");
  }

  cout << F("\nFolder1 removed.\n");
  cout << F("\nList of files on the SD.\n");
  sd.ls(LS_R);
  cout << F("Done!\n");
}