コード例 #1
0
ファイル: SDCard.cpp プロジェクト: CyrilLD/sjfw
SdErrorCode directoryReset() {
  reset();
  SdErrorCode rsp = initCard();
  if (rsp != SD_SUCCESS && rsp != SD_ERR_CARD_LOCKED) {
    return rsp;
  }
  fat_reset_dir(dd);
  return SD_SUCCESS;
}
コード例 #2
0
ファイル: SDCard.cpp プロジェクト: CyrilLD/sjfw
bool findFileInDir(const char* name, struct fat_dir_entry_struct* dir_entry)
{
  while(fat_read_dir(dd, dir_entry))
  {
    if(strcmp(dir_entry->long_name, name) == 0)
    {
      fat_reset_dir(dd);
      return true;
    }
  }
  return false;
}
コード例 #3
0
ファイル: main.c プロジェクト: NexusIF/ProjectsBackup
uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry)
{
    while(fat_read_dir(dd, dir_entry))
    {
        if(strcmp(dir_entry->long_name, name) == 0)
        {
            fat_reset_dir(dd);
            return 1;
        }
    }

    return 0;
}
コード例 #4
0
ファイル: FatFs.cpp プロジェクト: BackupGGCode/arms22
bool FatFsClass::find_file_in_dir(const char *file_name,
								  struct fat_dir_entry_struct *dir_entry)
{
	while(1){
		if(!fat_read_dir(_dd, dir_entry))
			break;
		if(strcmp(file_name, dir_entry->long_name) == 0){
			fat_reset_dir(_dd);
			return true;
		}
	}
	return false;
}
コード例 #5
0
uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry)
{
	fat_reset_dir(dd);	//Make sure to start from the beginning of the directory!
    while(fat_read_dir(dd, dir_entry))
    {
        if(strcmp(dir_entry->long_name, name) == 0)
        {
            //fat_reset_dir(dd);
            return 1;
        }
    }

    return 0;
}
コード例 #6
0
ファイル: ecmd.c プロジェクト: AnDann/ethersex
int16_t
parse_cmd_sd_dir(char *cmd, char *output, uint16_t len)
{
  if (vfs_sd_rootnode == 0)
    return ECMD_FINAL(snprintf_P(output, len,
                                 PSTR("SD/MMC backend not available.")));

  if (cmd[0] != ECMD_STATE_MAGIC)
  {
    fat_reset_dir(vfs_sd_rootnode);
    cmd[0] = ECMD_STATE_MAGIC;
  }

  struct fat_dir_entry_struct dir_entry;
  if (!fat_read_dir(vfs_sd_rootnode, &dir_entry))
    return ECMD_FINAL_OK;

  return ECMD_AGAIN(snprintf_P(output, len, PSTR("%32s%c %ld"),
                               dir_entry.long_name,
                               dir_entry.attributes & FAT_ATTRIB_DIR ? '/' : ' ',
                               dir_entry.file_size));
}
コード例 #7
0
void loop()
{
  int bytes_read=0; //Keeps track of how many bytes are read when accessing a file on the SD card.
  
  //Init Timer 1
  //Used for 45uS Interrupt
  TCCR1A = 0;		//Set Timer to normal mode
  TCCR1B = 0x0A;	//Set Timer clock to 2 MHz. Clear timer on compare
  TIMSK1 = 0x02;	//Enable Timer 1 Compare A Interrupt;
  OCR1AH = 0X00;	//Count to 90 before triggering an interrupt. Counting to 90 with a 2MHz clock makes
  OCR1AL = 0x5A;    //the interrupt trigger at 22.222kHz
  
  init_filesystem();	//Initialize the FAT16 file system on the SD card.

  if(get_wav_filename(dd, file_name));	//Find the first WAV file on the SD card (must be in the root directory)
  else while(1);	//If a WAV file isn't found then the sketch is stopped here.
  
  //Open the file	
  file_handle=open_file_in_dir(fs, dd, file_name);
  //Read the header information. Alternate purpose is to get to the DATA offset of the file.
  read_wav_header(file_handle, header);
  //Set the initial play buffer, and grab the initial data from the SD card.
  play_buffer=0;
  bytes_read = fat_read_file(file_handle, buffer1, BUFFERSIZE);
  bytes_read = fat_read_file(file_handle, buffer2, BUFFERSIZE);
  //Enable interrupts to start the wav playback.
  sei();
  while(1){
    if(need_new_data==1)	//need_new_data flag is set by ISR to indicate a buffer is empty and should be refilled
    {
      need_new_data=0;	//Clear the flag.
      if(play_buffer==0)	//play_buffer indicates which buffer is now empty
      {
        //Get the next BUFFERSIZE bytes from the file.
        bytes_read = fat_read_file(file_handle, buffer1, BUFFERSIZE);
      }
      else
      {
        //Get the next BUFFERSIZE bytes from the file.
        bytes_read = fat_read_file(file_handle, buffer2, BUFFERSIZE);
      }
      new_buffer_ready=1;	//new_buffer_ready flag tells the ISR that the buffer has been filled.
			
      //If file_read returns 0 or -1 file is over. Find the next file!
      if(bytes_read<=0)
      {
        cli();	//Disable interrupts to stop playback.
        fat_close_file(file_handle);	//Close the current file
        //Find the next WAV file in the SD card
        fat_reset_dir(dd);	//Make sure we start searching from the beginning of the directory
        find_file_in_dir(fs, dd, file_name, &dir_entry);	//Navigate to the current file in the directory
        if(get_wav_filename(dd, file_name));
        else while(1);	//If we don't find another wav file, stop everything!
				
        //If we get here we've found another wav file. Open it!
        file_handle=open_file_in_dir(fs, dd, file_name);
        //Get the file header and load the initial song data.
        read_wav_header(file_handle, header);
        play_buffer=0;
        bytes_read = fat_read_file(file_handle, buffer1, BUFFERSIZE);
        bytes_read = fat_read_file(file_handle, buffer2, BUFFERSIZE);
        sei();	//Start playing the song
      }
    }
  }
  
}
コード例 #8
0
ファイル: RepRapSDCard.cpp プロジェクト: Brockhold/G3Firmware
uint8_t RepRapSDCard::sd_scan_reset() {
  fat_reset_dir(dd);
  return 0;
}