void Play() { playingState = PS_NEXT_SONG; currentFile = 1; #if defined(__AVR_ATmega1280__) // If play/stop button is pressed during boot, enter recording. if (0== PSKey) { delay(20); while(0 == PSKey); delay(20); Record(); } #endif //cyclely play while(1) { //CheckPlay(); CheckKey(); if(1 ==playStop) { if(OpenFile(currentFile)) { //if open failed, then try it again if(OpenFile(currentFile)) { playStop = 0; playingState = PS_NEXT_SONG; currentFile = 1; continue; } } PlayCurrentFile(); if (playingState == PS_PREVIOUS_SONG) currentFile--; if (playingState == PS_NEXT_SONG) currentFile++; if (currentFile==0) currentFile = 1; //if (playingState == PS_END_OF_SONG) playingState = PS_NORMAL; Mp3SoftReset(); } } }
//-------------------------------------------------------------------------- void main(void){ //------------------------------------------------------------------------- if(USBIsAttached()){ return; //Quit to ROM code to handle USB traffic } //------------------------------------------------------------------------- ph = &fsNandPhys.p; //physical disk is nand flash ROM handler map = FsMapTnCreate(ph,0); //logical disk mapper is ROM tiny mapper (read only) currentKeyMap = ZeroKeyMap; PERIP(GPIO1_MODE) = 0x30; //-\seting PERIP(GPIO1_DDR) = 0x0F; //-/port GPIO1 //------------------------------------------------------------------------- if(InitFileSystem()){ while(1); // NO File System } else{ //FAT IS INIT minifatInfo.supportedSuffixes = supportedFiles; //play '.ogg' files player.totalFiles = OpenFile(0xffffU); SetVOL(0x10); player.currentFile = 0; player.nextStep = 1; player.offDelay = 0; player.randomOn = 0; /// Off random PERIP(GPIO1_ODATA) |= 0x01; SetHookFunction((u_int16)PowerOff, MyPowerOff); if(OpenFile(player.currentFile) < 0){ OpenFile(player.currentFile); PlayCurrentFile(); } player.currentFile++; currentKeyMap = MyKeyMap; while (1) {//player loop // "Previous" file selected at the first file if (player.currentFile < 1) { player.currentFile = (player.totalFiles-1); } // "Next" file selected at or after the last file if (player.currentFile >= player.totalFiles){ player.currentFile = 1; } if(OpenFile(player.currentFile) < 0){ OpenFile(player.currentFile); player.nextStep = 1; { u_int16 result = PlayCurrentFile(); if (result == ceFormatNotFound){ player.currentFile++; //Skip erroneous file } if(result == ceFormatNotSupported){ player.currentFile++; //Skip erroneous file } if(result == ceOtherError){ player.currentFile++; //Skip erroneous file } } player.currentFile += player.nextStep; } else{ // Could not OpenFile. player.currentFile++; // Revert to playing the first file } } //end of player loop } //end FAT } //end main