Пример #1
0
int
main(void)
{
    unsigned long ulPHYMR0;
    tBoolean bButtonWasPressed = false;
    tMotorState sMotorState=STATE_STOPPED;
    tWaveHeader sWaveHeader;
    unsigned long ulWaveIndex = 1;
    int losL,losH;
    
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    ulPHYMR0 = ROM_EthernetPHYRead(ETH_BASE, PHY_MR0);
    ROM_EthernetPHYWrite(ETH_BASE, PHY_MR0, ulPHYMR0 | PHY_MR0_PWRDN);

	         	 // Display96x16x1Init(true);
	        	//  Display96x16x1StringDraw("MOTOR", 29, 0);
	         	 //  Display96x16x1StringDraw("DEMO", 31, 1);

    LEDsInit();
    LED_On(LED_1);
    PushButtonsInit();
    BumpSensorsInit();
    MotorsInit();
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();
    SoundInit();
    // WaveOpen((unsigned long *) sWaveClips[ulWaveIndex].pucWav, &sWaveHeader);
    //mozliwe ze trzeba przed kazdym odtworzeniem ;/
   // while(WaveOpen((unsigned long *)
     //                            sWaveClips[ulWaveIndex].pucWav,
       //                          &sWaveHeader) != WAVE_OK);//do zablokowania w razie bledu
    for(;;)
    {

       
            tBoolean bButtonIsPressed;
            tBoolean bBumperIsPressed[2];

            bButtonIsPressed = !PushButtonGetDebounced((tButton)1);
            bBumperIsPressed[0] = !BumpSensorGetDebounced((tBumper)0);
            bBumperIsPressed[1] = !BumpSensorGetDebounced((tBumper)1);

            switch(sMotorState)
            {
                case STATE_STOPPED:
                {
                    if(bButtonIsPressed && !bButtonWasPressed)
                    {
                    	sterowanie(0,50,50);
                        sMotorState = STATE_RUNNING;
                    }
                    break;
                }

                 case STATE_RUNNING:
                {
                	 
                    if(bButtonIsPressed && !bButtonWasPressed)
                    {
                        MotorStop((tSide)0);
                        MotorStop((tSide)1);
                        sMotorState = STATE_STOPPED;
                    }

                    else if(bBumperIsPressed[0])
                    {
                         MotorStop((tSide)0);
                         MotorStop((tSide)1);
                //       WavePlayStart(&sWaveHeader); mozliwe ze tu
                	losL =10+ g_ulTickCount % 20;//i dać los zamiast 15,mamy losowe skrecanie(10-30)
                     	losH =40+ g_ulTickCount % 30;//i dać los zamiast 60,mamy losowe skrecanie(40-70)
                         sterowanie(1,losL,losH);
                	 sMotorState = STATE_TYL;
                    }

                    else if(bBumperIsPressed[1]){
                          MotorStop((tSide)0);
                          MotorStop((tSide)1);
                      	  losL =10+ g_ulTickCount % 20;//i dać los zamiast 15,mamy losowe skrecanie(10-30)
                     	  losH =40+ g_ulTickCount % 30;//i dać los zamiast 60,mamy losowe skrecanie(40-70)
                          sterowanie(1,losH,losL);
                //       WavePlayStart(&sWaveHeader); mozliwe ze tu
                          sMotorState = STATE_TYL;
                          }
                    break;
                }

               case STATE_TYL:
                {//cofanie tez moze byc losowe np losH+losL(50-100)+160=(210-260)
                	 while(cofanie<250);
                        MotorStop((tSide)0);
                        MotorStop((tSide)1);
                        sterowanie(0,50,50);
                        sMotorState = STATE_RUNNING;

                    break;
                }
                
               default:
                {
                    MotorStop((tSide)1);
                    MotorStop((tSide)0);
                    sMotorState = STATE_STOPPED;
                  break;
                }
            } 

           bButtonWasPressed = bButtonIsPressed;

         
    } 
}
//*****************************************************************************
//
// The main application.  It configures the board and then enters a loop
// to show messages on the display and blink the LEDs.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulPHYMR0;
    unsigned long ulNextTickLED = 0;
    unsigned long ulNextTickDisplay = 0;
    unsigned long ulDisplayState = 0;

    //
    // Set the clocking to directly from the crystal
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Since the Ethernet is not used, power down the PHY to save battery.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    ulPHYMR0 = ROM_EthernetPHYRead(ETH_BASE, PHY_MR0);
    ROM_EthernetPHYWrite(ETH_BASE, PHY_MR0, ulPHYMR0 | PHY_MR0_PWRDN);

    //
    // Initialize the board display
    //
    Display96x16x1Init(true);

    //
    // Initialize the GPIO used for the LEDs, and then turn one LED on
    // and the other off
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, 0);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_5, GPIO_PIN_5);

    //
    // Set up and enable the SysTick timer to use as a time reference.
    // It will be set up for a 100 ms tick.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 10);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Enter loop to run forever, blinking LEDs and printing messages to
    // the display
    //
    for(;;)
    {
        //
        // If LED blink period has timed out, then toggle LEDs.
        //
        if(g_ulTickCount >= ulNextTickLED)
        {
            //
            // Set next LED toggle timeout for 1 second
            //
            ulNextTickLED += 10;

            //
            // Toggle the state of each LED
            //
            ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4 | GPIO_PIN_5,
                             ~ROM_GPIOPinRead(GPIO_PORTF_BASE,
                                              GPIO_PIN_4 | GPIO_PIN_5));
        }

        //
        // If display interval has elapsed, then update display state
        //
        if(g_ulTickCount >= ulNextTickDisplay)
        {
            //
            // Process the display state.  Each state, the display does
            // something different.
            //
            // Odd time intervals are used, like 5.3 seconds, to keep the
            // display updates out of sync with the LED blinking which is
            // happening on a 1 second interval.  This is just for cosmetic
            // effect, there is no technical reason it needs to be that way.
            //
            switch(ulDisplayState)
            {
                //
                // Initial state, show TEXAS INSTRUMENTS for 5.3 seconds
                //
                case 0:
                {
                    Display96x16x1StringDraw("TEXAS", 29, 0);
                    Display96x16x1StringDraw("INSTRUMENTS", 11, 1);
                    ulNextTickDisplay += 53;
                    ulDisplayState = 1;
                    break;
                }

                //
                // Next, clear display for 1.3 seconds
                //
                case 1:
                {
                    Display96x16x1Clear();
                    ulNextTickDisplay += 13;
                    ulDisplayState = 2;
                    break;
                }

                //
                // Show STELLARIS for 5.3 seconds
                //
                case 2:
                {
                    Display96x16x1StringDraw("STELLARIS", 21, 0);
                    ulNextTickDisplay += 53;
                    ulDisplayState = 3;
                    break;
                }

                //
                // Clear the previous message and then show EVALBOT on
                // the second line for 5.3 seconds
                //
                case 3:
                {
                    Display96x16x1Clear();
                    Display96x16x1StringDraw("EVALBOT", 27, 1);
                    ulNextTickDisplay += 53;
                    ulDisplayState = 4;
                    break;
                }

                //
                // Clear display for 1.3 seconds, then go back to start
                //
                case 4:
                {
                    Display96x16x1Clear();
                    ulNextTickDisplay += 13;
                    ulDisplayState = 0;
                    break;
                }

                //
                // Default state.  Should never get here, but if so just
                // go back to starting state.
                //
                default:
                {
                    ulDisplayState = 0;
                    break;
                }
            } // end switch
        } // end if
    } // end for(;;)
}