static void PlayerCtrlTask(void *pvParameters){ //portTickType ulLastTime; //char itemCount = 0; unsigned char soundCtrl = 0; //Start Player Ctrl usStopPlayerCtrl = 0; //List files in root ListFiles(); sFilePath=getCurrentFile(); //DisplayMenu(0x03); // // Loop forever. // vTaskSuspendScheduler(); ShowStartup(); xTaskResumeScheduler(); xTaskDelay(5000); while(1){ //get event from button if( xQueueReceive(xPlayerCtrlQueue, (unsigned char*)&usEventCode,100)==pdPASS) { //Events from USB if(usEventCode == STOP_PLAYER) { PlayState=PAUSE_STATE; usStopPlayerCtrl = 1;//*Stop Player Ctrl soundCtrl = STOP;//*Stop Sound Player giveSoundCtrlEvent((unsigned char*)&soundCtrl,portMAX_DELAY); } else if (usEventCode == START_PLAYER) { usStopPlayerCtrl = 0;//*Start Player Ctrl Root = MENU; ChooseItem = NOWPLAY; DisplayMenu(0x03); } //USB not pluged in if(usStopPlayerCtrl == 0) { //Play sound Button when button pressed if(usEventCode < 10 && SoundButton) { soundCtrl = PLAY_BTN_SND; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); } //Events from Sound Player if(usEventCode==PLAY_DONE) { /**Play Mode: Normal*/ //TODO Play next song if(PlayMode == 0){//normal sFilePath = nextFile(); if(ucFileIndex!=0) { soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100);; } }else if(PlayMode == 1)//Single { ; }else if(PlayMode ==2)//repeate { soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100);; }else if(PlayMode==3)//loop { sFilePath = nextFile(); soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100);; } // if(ChooseItem == NOWPLAY) { NowPlay(STATE_UPDATE); NowPlay(SELECTED_UPDATE); } } //Events form user buttons if(Root == ITEM) { if(ChooseItem == NOWPLAY){ if(usEventCode == L_CENTER) { Root = MENU;//*back ROOT DisplayMenu(0x03); }else if(usEventCode == S_CENTER) { soundCtrl=PAUSE_PLAY; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); NowPlay(STATE_UPDATE); }else if(usEventCode == S_RIGHT) { soundCtrl = VLM_UP; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); NowPlay(VOLUME_UPDATE); } else if(usEventCode == S_LEFT) { soundCtrl = VLM_DOWN; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); NowPlay(VOLUME_UPDATE); } else if(usEventCode == S_UP) { //Play next song sFilePath = preFile(); NowPlay(SELECTED_UPDATE); soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); } else if(usEventCode == S_DOWN) { //Play previous song sFilePath = nextFile(); NowPlay(SELECTED_UPDATE); soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); } } else if(ChooseItem == BROWSE) { if(usEventCode == L_CENTER) { //back ROOT/parent's Dir vTaskSuspendScheduler(); if(BackParentDir()) { Root = MENU; DisplayMenu(0x03); } else Browse(BROWSE_UPDATE); xTaskResumeScheduler(); } else if(usEventCode == S_CENTER) { //open dir if it's dir, else file and play; vTaskSuspendScheduler(); ListFiles(); xTaskResumeScheduler(); ChooseItem = NOWPLAY; NowPlay(0x1f); } else if(usEventCode == S_UP){ PreItem(); Browse(BROWSE_UPDATE); }else if(usEventCode == S_DOWN){ NextItem(); Browse(BROWSE_UPDATE); }else if(usEventCode == L_DOWN || usEventCode == L_UP){ vTaskSuspendScheduler(); OpenChooseDir(); xTaskResumeScheduler(); Browse(BROWSE_UPDATE); } }else if(ChooseItem == SETTINGS){ if(usEventCode == L_CENTER){ Root = MENU;//*back MENU DisplayMenu(0x03); }else if(usEventCode == S_CENTER) { if(Selected == PLAY_MODE) { PlayMode++; if(PlayMode >3) PlayMode =0; }else if(Selected == BUTTON_SOUND) { SoundButton++; if(SoundButton>1) SoundButton =0; } Settings(SETTING_MODE); } else if(usEventCode == S_UP) { Selected++; if(Selected > 1) Selected=0; Settings(SETTING_MODE); }else if(usEventCode == S_DOWN) { Selected--; if(Selected > 1) Selected=1; Settings(SETTING_MODE); } }else if(ChooseItem == INFO){ if(usEventCode == L_CENTER){ Root = MENU;//*back MENU DisplayMenu(0x03); } } } else if(Root == MENU){ if(usEventCode == S_CENTER){ Root = ITEM;//enter choose item; if(ChooseItem==NOWPLAY) { NowPlay(0x1f); } else if(ChooseItem==BROWSE) { vTaskSuspendScheduler(); ListDirItems(); xTaskResumeScheduler(); Browse(0x3); } else if(ChooseItem==SETTINGS) { Settings(0x03); } else if(ChooseItem==INFO) { Info(0x03); } }else if(usEventCode == S_UP){ ChooseItem--;//previous item if(ChooseItem > INFO) ChooseItem = INFO; DisplayMenu(MENU_SELECT_UPDATE); }else if(usEventCode == S_DOWN){ ChooseItem++;//next item if(ChooseItem > INFO) ChooseItem = NOWPLAY; DisplayMenu(MENU_SELECT_UPDATE); } } }else{ //USB mass storage USBTransfer(); } } if(Root == ITEM) { if(ChooseItem == NOWPLAY){ //Update time playing if(clock) { NowPlay(TIME_UPDATE); clock=0; } } } } }
//***************************************************************************** // // This task manages the scurring about of a spider. // //***************************************************************************** static void SpiderTask(void *pvParameters) { unsigned long ulDir, ulImage, ulTemp; long lX, lY, lSpider; // // Get the spider number from the parameter. // lSpider = (long)pvParameters; // // Add the current tick count to the random entropy pool. // RandomAddEntropy(xTaskGetTickCount()); // // Reseed the random number generator. // RandomSeed(); // // Indicate that this spider is alive. // HWREGBITW(&g_ulSpiderAlive, lSpider) = 1; // // Indicate that this spider is not dead yet. // HWREGBITW(&g_ulSpiderDead, lSpider) = 0; // // Get a local copy of the spider's starting position. // lX = g_plSpiderX[lSpider]; lY = g_plSpiderY[lSpider]; // // Choose a random starting direction for the spider. // ulDir = RandomNumber() >> 29; // // Start by displaying the first of the two spider animation images. // ulImage = 0; // // Loop forever. // while(1) { // // See if this spider has been killed. // if(HWREGBITW(&g_ulSpiderDead, lSpider) == 1) { // // Wait for 2 seconds. // xTaskDelay((1000 / portTICK_RATE_MS) * 2); // // Clear the spider from the display. // DisplayImage(lX - (SPIDER_WIDTH / 2), lY - (SPIDER_HEIGHT / 2), g_pucSpiderBlankImage); // // Indicate that this spider is not alive. // HWREGBITW(&g_ulSpiderAlive, lSpider) = 0; // // Delete the current task. This should never return. // xTaskDelete(NULL); // // In case it does return, loop forever. // while(1) { } } // // Enter a critical section while the next move for the spider is // determined. Having more than one spider trying to move at a time // (via preemption) would make the collision detection check fail. // taskENTER_CRITICAL(); // // Move the spider. // lX += g_plSpiderStepX[ulDir]; lY += g_plSpiderStepY[ulDir]; // // See if the spider has cross the boundary of its area, if it has // collided with another spider, or if random chance says that the // spider should turn despite not having collided with anything. // if((lX < SPIDER_MIN_X) || (lX > SPIDER_MAX_X) || (lY < SPIDER_MIN_Y) || (lY > SPIDER_MAX_Y) || (SpiderCollide(lSpider, lX, lY) != -1) || (RandomNumber() < 0x08000000)) { // // Undo the previous movement of the spider. // lX -= g_plSpiderStepX[ulDir]; lY -= g_plSpiderStepY[ulDir]; // // Get a random number to determine the turn to be made. // ulTemp = RandomNumber(); // // Determine how to turn the spider based on the random number. // Half the time the spider turns to the left and half the time it // turns to the right. Of each half, it turns a quarter of a turn // 12.5% of the time and an eighth of a turn 87.5% of the time. // if(ulTemp < 0x10000000) { ulDir = (ulDir + 2) & 7; } else if(ulTemp < 0x80000000) { ulDir = (ulDir + 1) & 7; } else if(ulTemp < 0xf0000000) { ulDir = (ulDir - 1) & 7; } else { ulDir = (ulDir - 2) & 7; } } // // Update the position of the spider. // g_plSpiderX[lSpider] = lX; g_plSpiderY[lSpider] = lY; // // Exit the critical section now that the spider has been moved. // taskEXIT_CRITICAL(); // // Have the display task draw the spider at the new position. Since // there is a one pixel empty border around all the images, and the // position of the spider is incremented by only one pixel, this also // erases any traces of the spider in its previous position. // DisplayImage(lX - (SPIDER_WIDTH / 2), lY - (SPIDER_HEIGHT / 2), g_ppucSpiderImage[(ulDir * 2) + ulImage]); // // Toggle the spider animation index. // ulImage ^= 1; // // Delay this task for an amount of time based on the direction the // spider is moving. // xTaskDelay(g_pulSpiderDelay[ulDir & 1]); // // Add the new tick count to the random entropy pool. // RandomAddEntropy(xTaskGetTickCount()); // // Reseed the random number generator. // RandomSeed(); } }