// 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;
}
// 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);
    }
}
예제 #3
0
uint32_t SD_GetFileSize(void)
{
    uint32_t retVal = 0;
    //TEST.TXT
    sdf.chdir();	// Change directory to root
    // OPEN the file for reading:
    if (!file.open("TEST.TXT", O_READ)) {
        sdf.errorHalt("opening FILE for read failed");
    }
    else
    {
        retVal = file.fileSize();
        file.close();

    }

    return retVal;
}
예제 #4
0
파일: main.cpp 프로젝트: keax/SdFat
int main()
{

	// initialize the SD card at SPI_FULL_SPEED for best performance.
	// try SPI_HALF_SPEED if bus errors occur.
	if (!sd.begin(SD_ENABLE_PIN, SPI_FULL_SPEED)) sd.initErrorHalt();


	if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
		sd.errorHalt("opening test.txt for write failed");
	}

	myFile.println("testing 1, 2, 3.");

	// close the file:
	myFile.close();

	while (1);

	return 0;
}
boolean MP3Player::Setup_STA013(void)
{ 
  byte buf[2];
  
  if (!myFile.open("sta013.cfg", O_READ)) 
  {
    #if DEBUG
	sd.errorHalt("cfg file error");
	#endif 
	return false;
  }
  
  #if DEBUG
  Serial.println("setting STA013 from cfgfile");  
  #endif 
  
  
  while (myFile.available()) 
  {
    buf[0]=byte (myFile.read());
    buf[1]=byte (myFile.read()); 
    I2C_Write(buf[0], buf[1]);
    // Serial.write(buf[0]);
    // Serial.write(buf[1]);
  }  
  
  while(!myFile.close())
  {
	  #if DEBUG
	  Serial.println("close cfg file..");
	  #endif
  }
  
    
  #if DEBUG
  Serial.println("Setup STA013 Register Done..");     
  #endif 
  
  return true;
}
boolean MP3Player::Play(const char* SongName)
{  
  if(!PLAY)
  {
	k=65;
	if(!myFile.isOpen())
	{
		// open the file for read
		if (!myFile.open(SongName, O_READ)) 
		{
			#if DEBUG
			sd.errorHalt("open audio file failed");
			#endif 
			return false;
		}
	}
	else
		name = SongName;

	Run_STA013();
	delayMicroseconds(500000);
	Play_Pause(1);
  
	//AMPON();  

	#if DEBUG
	Serial.println("playing");
	#endif 
   
	filesize=myFile.fileSize();
	Timer1.initialize(30);// 30 us = can check data request and send a byte to STA013 at 1/30u = 33.33kHz
							// able to play a song up to 33.33 x 8 /1024 = 260 kbps
							// recommend play song at 200kbps or lower (such as 128 kbps)for stable performance
	PLAY=true; 
	Timer1.attachInterrupt(Callback);
  }

  return true;   
}
예제 #7
0
파일: Tune.cpp 프로젝트: Snootlab/Tune
int Tune::play(char* trackName)
{
	if (isPlaying()) return 1;
	
	// Exit if track not found
	if (!track.open(trackName, O_READ))
	{
		sd.errorHalt("Track not found !");
		return 3;
	}
	
	playState = playback;
	
	// Reset decode time & bitrate from previous playback
	writeSCI(SCI_DECODE_TIME, 0);
	delay(100);
	
	skipTag(); // Skip ID3v2 tag if there's one
	
	feed(); // Feed VS1011e
	attachInterrupt(0, feed, RISING); // Let the interrupt handle the rest of the process
	
	return 0;
}
예제 #8
0
파일: main.cpp 프로젝트: algedi/KUIopenAVR
void ScriviSd(void)
{
	int n;
	n = 0;
	if (!sd.init(SPI_HALF_SPEED, 10)) 
	{
		sd.initErrorHalt();
		return;
	}

	if (!myFile.open("test-1.txt", O_WRITE | O_CREAT | O_APPEND)) 
	{
		delay(800);
		digitalWrite(7, LOW);
		delay(200);
		digitalWrite(7, HIGH);
		delay(800);
		sd.errorHalt("opening test.txt for write failed");
		return;
	} 
//	Serial.println(nMin);

//	for(n = 0; n < nCount; n++)
//	{
//	myFile.print("TIME: ");
//	myFile.print(nMin);
//	myFile.print(" min. - VALUE    : ");
//	myFile.print(nValue[n]);
	myFile.println(" mTesla");
//	}
//	Serial.println("ScriviSd5");
//	nCount = 0;
//	nMin++;	

	myFile.close();
}
예제 #9
0
boolean SD_ReadFile(const char *filename)
{
    uint32_t t_arrival = millis();
    boolean retVal = false;
    sdf.chdir();
    if (!file.open(filename, O_READ)) {
        sdf.errorHalt("opening FILE for read failed");
    }
    else
    {
        uint32_t len = file.fileSize();
        uint8_t index = 0;
        for(uint32_t i=0; i< len; i++)
        {
            int intData = file.read();
            char byteData;
            int base = 10u;
            //itoa(intData,&byteData,base);	// Convert to ASCII
            buffer[index] = (uint8_t)intData;//byteData;
            if(index < 63u) {
                index++;
            }
            else {
                usb_rawhid_send(buffer, 100u);
                index = 0;
            }

        }
        file.close();
        uint32_t t_exit = millis() - t_arrival;
        buffer[62] = (uint8_t)((t_exit & 0x000000FF)>>8);
        buffer[63] = (uint8_t)t_exit;
        usb_rawhid_send(buffer,100u);

    }
}