Beispiel #1
0
void PrintNextImage(volatile void *uselessParameter)
{
    _receivingImage = 0;

    if (previousFileIsValid)
    {
        uint16_t stringLength = strlen(fno.fname) + 1;
        MemCopy(fno.fname, previousFileName, 0, 0, stringLength);
    }

    FRESULT res;
    res = pf_readdir(&dir, &fno);

    if (res == FR_NO_FILE)
    {
        char *rootDir = " ";
        pf_opendir(&dir, rootDir);

        res = pf_readdir(&dir, &fno);
        if (res == FR_NO_FILE)
        {
            return;
        }
    }

    if (!CheckBMPImage(fno.fname))
    {
        previousFileIsValid = true;
        PrintImage(fno.fname);
    }
}
int main (void)
{
	FRESULT res;
	char *dir;
	BYTE org_osc = OSCCAL;


	MCUSR = 0;
	WDTCR = _BV(WDE) | 0b110;	/* Enable WDT reset in timeout of 1s */

	PORTB = 0b101001;		/* Initialize port: - - H L H L L P */
	DDRB  = 0b111110;

	sei();

	for (;;) {
		if (pf_mount(&Fs) == FR_OK) {	/* Initialize FS */
			wdt_reset();
			sendDiag(MOUNT_OK);
			Buff[0] = 0;
			if (!pf_open("osccal")) pf_read(Buff, 1, &rb);	/* Adjust frequency */
			OSCCAL = org_osc + Buff[0];

			res = pf_opendir(&Dir, dir = "wav");	/* Open sound file directory */
			if (res == FR_NO_PATH){
				res = pf_opendir(&Dir, dir = "");	/* Open root directory */
				sendDiag(OPEN_ROOT_DIR);
			}
			else{
				sendDiag(OPEN_WAV_DIR);
			}

			while (res == FR_OK) {				/* Repeat in the dir */
				res = pf_readdir(&Dir, 0);			/* Rewind dir */
				while (res == FR_OK) {				/* Play all wav files in the dir */
					wdt_reset();
					res = pf_readdir(&Dir, &Fno);		/* Get a dir entry */
					if (res || !Fno.fname[0]){
						if(res) sendDiag(DIR_ERROR);
						else sendDiag(END_OF_DIR);
						break;
					}	/* Break on error or end of dir */
					if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, ".WAV")){
						sendFilename(Fno.fname);
						wdt_reset();
						sendDiag(PLAY_SONG);
						res = play(dir, Fno.fname);		/* Play file */
					}
					sendDiag(FINISH);
				}
			}
		}
		else{
			sendDiag(MOUNT_FAIL);
		}
		delay500();
	}
}
Beispiel #3
0
FRESULT PFFS::readdir (
	DIRECT *dj,			/* Pointer to the open directory object */
	FILINFO *fno		/* Pointer to file information to return */
)
{
	return pf_readdir(dj, fno);
}
Beispiel #4
0
FRESULT scan_files (char* path)
{
    FRESULT res;
    FILINFO fno;
    DIR dir;
    char bufpath[12];
    res = pf_opendir(&dir, path);
    if (res == FR_OK) {
        for (;;) {
            res = pf_readdir(&dir, &fno);
           if (res != FR_OK || fno.fname[0] == 0) break;
            if (fno.fattrib & AM_DIR) {
                psprintf(bufpath, "/%s", fno.fname);
                res = scan_files(bufpath);
                if (res != FR_OK) break;
            } else {
                #ifdef SERIAL_PRINT
				serial_printf("%s/", path);
                serial_printf("%s\r\n", fno.fname);
				#endif
                #ifdef CDC_PRINT
                CDCprintf("%s/", path);
                CDCprintf("%s\r\n", fno.fname);
				#endif
            }
        }
    }

    return res;
}
Beispiel #5
0
/* Return:
   0 : Error
   1 : File
   2 : Dir
*/
int FS_ReadDir(char *path)
{
    FILINFO fi;
    if (pf_readdir(&dir, &fi) != FR_OK || ! fi.fname[0])
        return 0;
    dbgprintf("Read: %s %d\n", fi.fname, fi.fattrib);
    strncpy(path, fi.fname, 13);
    return fi.fattrib & AM_DIR ? 2 : 1;
}
Beispiel #6
0
void task2(void)
{
	unsigned char filename[20];
	
	while (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) /* go through all the files in the current folder */
				/* Filter out directories and hidden files */
				
	{		
		if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, "WAV")) /* filter out all the folders, hidden files and the files that are not "WAV" */
		{	
			/* display the filename on the LCD */
			LCD_print(Fno.fname);
			
			/* play the WAV file (the play(filename) function needs the full name of the file e.g. music/file.wav) */
			play(strcat("music/",Fno.fname));
			
			
		}
	}
}
Beispiel #7
0
static uint8_t mas_pff_get_nth_file(const char *path, uint16_t n, char *buf, uint8_t *is_dir)
{
  FRESULT fr;
  uint16_t c = 0;
	
  if ( mas_last_readdir_n >=  n )
  {
    fr = pf_opendir(&mas_pff_dir, path);
    if ( fr != FR_OK )
      return 0;
  }
  else
  {
     c = mas_last_readdir_n;
     c++;
  }
  while( c < 0x0ffff)
  {
    fr = pf_readdir(&mas_pff_dir, &mas_pff_fi);
    if ( fr != FR_OK )
      return 0;
    if ( mas_pff_fi.fname[0] == '\0' )
      return 0;
    if ( c == n )
    {
      strcpy(buf, mas_pff_fi.fname);
      if ( (mas_pff_fi.fattrib & AM_DIR) != 0 )
      {
        *is_dir = 1;
      }
      else
      {
        *is_dir = 0;        
      }
      mas_last_readdir_n = n;
      return 1;
    }
    c++;
  }
  return 0;
}
Beispiel #8
0
/** List a given directory.

  \param path The path to list. Toplevel path is "/".

  A slash is added to directory names, to make it easier for users to
  recognize them.
*/
void sd_list(const char* path) {
  FILINFO fno;
  DIR dir;

  result = pf_opendir(&dir, path);
  if (result == FR_OK) {
    for (;;) {
      result = pf_readdir(&dir, &fno);
      if (result != FR_OK || fno.fname[0] == 0)
        break;
      serial_writestr((uint8_t *)fno.fname);
      if (fno.fattrib & AM_DIR)
        serial_writechar('/');
      serial_writechar('\n');
      delay_ms(2); // Time for sending the characters.
    }
  }
  else {
    sersendf_P(PSTR("E: failed to open dir. (%su)\n"), result);
  }
}
Beispiel #9
0
static uint16_t mas_pff_get_cnt(const char *path)
{
  FRESULT fr;
  uint16_t c = 0;
	
  fr = pf_opendir(&mas_pff_dir, path);
  if ( fr != FR_OK )
    return 0;
  
  while( c < 0x0ffff)
  {
    fr = pf_readdir(&mas_pff_dir, &mas_pff_fi);
    if ( fr != FR_OK )
      break;
    if ( mas_pff_fi.fname[0] == '\0' )
      break;
    c++;
  }
  
  mas_last_readdir_n = 0x0ffff;
  return c;
}
Beispiel #10
0
uint16_t testSDCard(void) {

	FATFS fatfs;			/* File system object */
	DIR dir;				/* Directory object */
	FILINFO fno;			/* File information object */
	WORD bw, br, i;
	BYTE buff[64];


	print("Mount a volume.");
	RET();

	FRESULT rc = pf_mount(&fatfs);
	if (rc) die(rc);

	print("Open a test file (message.txt).");
	RET();

	rc = pf_open("MESSAGE.TXT");
	if (rc) die(rc);

	print("Type the file content.");
    RET();

	for (;;) {
		rc = pf_read(buff, sizeof(buff), &br);	/* Read a chunk of file */
		if (rc || !br) break;			/* Error or end of file */
		for (i = 0; i < br; i++)		/* Type the data */
			putchar(buff[i]);
	}
	if (rc) die(rc);

#if _USE_WRITE
	sprintf(string,"\nOpen a file to write (write.txt).\n");
	print(string);

	rc = pf_open("WRITE.TXT");
	if (rc) die(rc);

	sprintf(string,"\nWrite a text data. (Hello world!)\n");
	print(string);

	for (;;) {
		rc = pf_write("Hello world!\r\n", 14, &bw);
		if (rc || !bw) break;
	}
	if (rc) die(rc);

	sprintf(string,"\nTerminate the file write process.\n");
	print(string);

	rc = pf_write(0, 0, &bw);
	if (rc) die(rc);
#endif

#if _USE_DIR
	print("Open root directory.");
	RET();

	rc = pf_opendir(&dir, "");
	if (rc) die(rc);

	print("Directory listing...");
	RET();

	for (;;) {
		rc = pf_readdir(&dir, &fno);	/* Read a directory item */
		if (rc || !fno.fname[0]) break;	/* Error or end of dir */
		if (fno.fattrib & AM_DIR)
		{
			print("   <dir>  ");
			print(fno.fname);
		    RET();
		}
		else
		{
			printInt((uint8_t*)&fno.fsize, sizeof(fno.fsize));
			print(fno.fname);
			RET();
		}
	}
	if (rc) die(rc);
#endif

	print("\nTest completed.\n");
	while(1)
	{
		delay_ten_us(50000);
		delay_ten_us(50000);
		P1OUT ^= (1 << RED_LED);

	}

   return 0xaa55;
}
Beispiel #11
0
FRESULT PFFS::readdir (
	void				/* Working copies of directory object & file */
)
{
	return pf_readdir(&dir_obj, NULL);
}
Beispiel #12
0
FRESULT PFFS::readdir (
	FILINFO *fno		/* Pointer to file information to return */
)
{
	return pf_readdir(&dir_obj, fno);
}
Beispiel #13
0
int main (void)
{
	FRESULT res;
	char *dir;
	BYTE org_osc = OSCCAL;
	BYTE ndir = 0;
	BYTE nskip = 0;
	BYTE nplay = 0;

//	MCUSR = 0;
	WDTCR = _BV(WDE) | 0b110;	/* Enable WDT reset in timeout of 1s */

	PORTB = 0b101001;		/* Initialize port: - - H L H L L P */
	DDRB  = 0b111110;
	sei();
/*-----------------------------------------------------------------------*/
/* POWER ON and RESET                                                    */
	ndir = eeprom_read_byte((uint8_t*)DIR_EEADR);

 if(bit_is_set(MCUSR, PORF)) { // Power on - resume playback!
    MCUSR = 0; // clear MCUSR
 } 

 if(bit_is_set(MCUSR, WDRF)) { // WatchDog reset - on error!
    MCUSR = 0; // clear MCUSR
	if (ndir !=0) {
    ndir = 0; // resetdirectory 
    nskip = 0; // resetdirectory
	eeprom_write_byte ((uint8_t*)SKIP_EEADR, (uint8_t*) nskip); 
	eeprom_write_byte ((uint8_t*)DIR_EEADR, (uint8_t*) ndir);
//	for (;;) {
//			PORTB ^= _BV(PB1);
//        delay_ms(200);
//       wdt_reset();
//	}
	}
 } 

 if(bit_is_set(MCUSR, EXTRF)) { // Reset button.

    MCUSR = 0; // clear MCUSR
    ndir++; // advance mode

//	for (;;) {wdt_reset();}

			wdt_reset();

    if(ndir > MAX_DIR) {
      ndir = 0; // resetdirectory
    }

    nskip = 0; // resetdirectory
	eeprom_write_byte ((uint8_t*)SKIP_EEADR, (uint8_t*) nskip); 
	eeprom_write_byte ((uint8_t*)DIR_EEADR, (uint8_t*) ndir); 


 }

/*-----------------------------------------------------------------------*/
/*     How many songs need to skip                                   */ 
 

            str[0] =48+ndir/10;
            str[1] = 48+ndir%10;
            str[2] = 0;

		PLAYMOD=0;

		if (pf_mount(&Fs) == FR_OK) {	/* Initialize FS */
			res = pf_opendir(&Dir, dir = str);	/* Open sound file directory */
			res = play(dir, "i");		/* Play intro file */
			res = play(dir, "n");		/* Play name file */
 /* PLAY mode 0 normal, 1 repeat loop, 2 only one file */
		if (play(dir, "r") == FR_OK) {
		PLAYMOD=1; //repeat loop
		}
		if (play(dir, "o") == FR_OK) {
		PLAYMOD=2; //only one file
		}

}
	nskip = eeprom_read_byte((uint8_t*)SKIP_EEADR);

// FR_OK = 0

	for (;;) {
		if (pf_mount(&Fs) == FR_OK) {	/* Initialize FS */
			wdt_reset();
//			Buff[0] = 0;
//			if (!pf_open("osccal")) pf_read(Buff, 1, &rb);	/* Adjust frequency */
//			OSCCAL = org_osc + Buff[0];


			res = pf_opendir(&Dir, dir = str);	/* Open sound file directory */
			if (res == FR_NO_PATH)
				res = pf_opendir(&Dir, dir = "");	/* Open root directory */

			while (res == FR_OK) {				/* Repeat in the dir */
				res = pf_readdir(&Dir, 0);			/* Rewind dir */
				nplay=0;
				while (res == FR_OK) {				/* Play all wav files in the dir */
					wdt_reset();
					res = pf_readdir(&Dir, &Fno);		/* Get a dir entry */
					if (res || !Fno.fname[0]) break;	/* Break on error or end of dir */
					if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, ".WAV"))



if (nplay >= nskip) {
		do {
					res = play(dir, Fno.fname);		/* Play file */
        wdt_reset(); 
		} 
		while (((PINB & 1)  == 1) &&  (PLAYMOD == 1));
		delay500();			/* Delay 500ms in low power sleep mode */


					if (res == FR_OK) {	
					    eeprom_write_byte ((uint8_t*)SKIP_EEADR, (uint8_t*) nplay+1);
						nskip=0;
						
/* PLAY mode 0 normal, 1 repeat loop, 2 only one file */

//		PORTB ^= _BV(PB1);
		if (PLAYMOD == 2) {
		do {
        delay_ms(30);
        wdt_reset(); } 
while ((PINB & 1)  == 1);

		do {
        delay_ms(50);
        wdt_reset(); } 
while ((PINB & 1)  == 0);
        delay_ms(500);	
		}

}
						
	


						
						}
						nplay++; // playing song nr
				}

			}
		}

	}
}
Beispiel #14
0
/* Main                                                                  */
int main (void)
{
	// setare pin 5 (difuzor) si pin 6 (CS_SD) al portului A ca pin de iesire
	DDRD |= (1<<PD5) | (1<<PD6);
	
	// setam toti pinii portului C ca pini de iesire
	DDRC = 0xFF;
	
	DDRB &= ~(1<<PB0);
	DDRB &= ~(1<<PB1);
	
	PORTB |= (1<<PB1) | (1<<PB0);
	PORTD &= ~((1<<PD5) | (1<<PD6));
	PORTD &= ~((1<<PD5) | (1<<PD6));
	

	LCD_init();
		
	sei();

	for (;;)
	{
		_delay_ms(1000);							/* Delay 1000ms for things to settle down */
		
		if (pf_mount(&Fs)) 
		{	
			continue;	/* Initialize FS */
		}
		
		if (pf_opendir(&Dir, "wav")) break;		/* Open /wav folder */
		
		int state = STAHPED;
		char* filename, first_wav, last_wav_played;
		
		
		
		if (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) /* go to next file*/
			{		
				if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, "WAV")) /* filter out all the folders, hidden files and the files that are not "WAV" */
				{	
					/* display the filename on the LCD */
					LCD_print(Fno.fname);
					strcpy(first_wav, Fno.fname);
				}
			}		

		while(1) 
		{
			/* check if button on PA3 (start/stahp) is pressed */
			if (!(PINA & (1 << PA3)))
			{
				if (state == STAHPED)
				{
					state = STARTED;
					LCD_print(Fno.fname);
					play(strcat("wav", Fno.fname)); // play song
				}
				else 
				{
					state = STAHPED;
					LCD_print(Fno.fname);
					FifoCt = 0; // stop melody
				}
			}
			/* check if button on PA2 (next) is pressed */
			if (!(PINA & (1 << PA2)))
			{
				sprintf(last_wav_played, "%s", Fno.fname);
				
				if (state == STARTED)
				{
					if (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) /* go to next file*/
					{		
						if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, "WAV")) /* filter out all the folders, hidden files and the files that are not "WAV" */
						{	
							/* display the filename on the LCD */
							LCD_print(Fno.fname);
							
							/* play the WAV file */
							play(strcat("wav", Fno.fname));
						}
					}			
				}
				else 
				{
					if (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) /* go to next file*/
					{		
						if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, "WAV")) /* filter out all the folders, hidden files and the files that are not "WAV" */
						{	
							/* display the filename on the LCD */
							LCD_print(Fno.fname);
						}
					}			
				}
			}
			
			/* check if button on PA1 (previous) is pressed */
			if (!(PINA & (1 << PA1)))
			{
				if (state == STARTED)
				{
					if (strcmp(last_wav_played, first_wav) != 0 )
					{
						/* display the filename on the LCD */
						LCD_print(last_wav_played);
						
						/* play the WAV file */
						play(strcat("wav", last_wav_played));
					}
					else 
						/* display the filename on the LCD */
						LCD_print(first_wav);
				}
				else
					if (strcmp(last_wav_played, first_wav) != 0 )
					/* display the filename on the LCD */
						LCD_print(last_wav_played);
			}
		}
	}
	
	return 1;
}
Beispiel #15
0
uint8_t genMenu()
{
  uint8_t *p;
  uint16_t filecount = 0;

  // shut off TI cart bug
  disableBus();
  
  // open SD card
  rc = pf_mount(&sd_fs);
  if (rc)
    flash_error(1);

  rc = pf_opendir(&sd_dp, "");
  if (rc)
    flash_error(2);

  // add menu and browser code
  writeMenuCode();
  
  while (images_written < MAX_ENTRIES) {
    // get next item in directory
    rc = pf_readdir(&sd_dp, &sd_fno);
    if (rc)
      flash_error(3);
    if (sd_fno.fname[0] == 0)  // end of dir
      break;
    ++filecount;
    if (sd_fno.fattrib & AM_DIR)
      continue;  // skip directories

    // check if file ends in ".BIN"
    p = (uint8_t *)sd_fno.fname;
    while (*++p);
    if (p - (uint8_t *)sd_fno.fname < 5 ||
	*--p != 'N' || *--p != 'I' || *--p != 'B' || *--p != '.')
      continue;
    --p;  // p at last char of filename w/o extension

    // check image size
    if (sd_fno.fsize > 32768)
      continue;

#ifdef MULTI_FILE
    // check for multi-file image
    // - if file ends in C -> check how many banks
    // - if file ends in D, E, F -> check if C exists, then ignore
    uint8_t c;
    if (sd_fno.fsize == 8192 && *p == 'C') {
      for (c = 'D'; c <= 'F'; ++c) {
        *p = c;
        rc = pf_open(sd_fno.fname);
        if (rc)
          break;
      }
      *p = 'C';
    } else if (sd_fno.fsize == 8192 && (*p == 'D' || *p == 'E' || *p == 'F')) {
      c = *p;
      *p = 'C';
      rc = pf_open(sd_fno.fname);
      if (!rc)
        continue;  // current file covered by C file
      *p = c;  // actually not a multi-file image
    }
#endif

    // create entry
    if (addEntries(sd_fno.fname))
      ++files_written;
  }

  // if only one image found, load file directly
  if (files_written == 1)
    return 1;

  // close menu and browser items
  closeEntries();

  // bring cartridge online
  enableBus();

  return 0;
}