コード例 #1
0
ファイル: app.c プロジェクト: ruelsison/simplewave-harmony
void APP_Tasks ( void )
{
    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            break;
        }
        case APP_STATE_EVENT:
        {
            BSP_LEDToggle(BSP_LED_1);
            appData.state = APP_STATE_IDLE;
            break;
        }
        case APP_STATE_IDLE:
        {
            break;
        }
        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }
}
コード例 #2
0
ファイル: app.c プロジェクト: Karenbuitano/Blinky_leds
void APP_Tasks ( void )
{
   /* Take appropriate action, depending on the current state. */
    switch (appData.state)
    {

        /* Application is stuck in a counting loop. */
        case APP_STATE_COUNT:
        {
            /* Keep incrementing the count if it's less than the blink delay */
            if (i < APP_LED_BLINK_DELAY)
            {
                /* Increment count. */
                i++;
            }

            else
            {
                /* If count is reached, switch states */
                appData.state = APP_STATE_BLINK_LED;
            }

            break;
        }

        /* Toggle the LED and switch back to the delay loop. */
        case APP_STATE_BLINK_LED:
        {
            /* Toggle LED */
            BSP_LEDToggle(BSP_LED_3);

            /* Put the application back to the count state */
            appData.state = APP_STATE_COUNT;

            /* Restart count. */
            i = 0;

            break;
        }

        /* Should not come here during normal operation */
        default:
        {
            PLIB_ASSERT(false , "unknown application state");

            break;
        }

    }
}
コード例 #3
0
ファイル: app.c プロジェクト: fokane/LPFgit
/* TODO:  Add any necessary callback functions.
*/
void TimerInterruptCallback(uintptr_t context, uint32_t alarmCount)
{
    static uint32_t index = 0;
   
    Nop();
    Nop();
    Nop();
    Nop();
    BSP_LEDToggle(BSP_LED_3);
  
    
    // update PWM duty cycle with next sample 
    PLIB_OC_PulseWidth16BitSet(OC_ID_1, sineData[index++]);
    
    // check if we are at the end of the input data array
    // if so, reset to beginning of array
    if(index == INPUT_DATA_LENGTH)
    {
        index = 0;
    }
    
}
コード例 #4
0
void BSP_LED_LightShow(BSP_LED_LIGHT_SHOW lightShow)
{
    static uint32_t ledTick = 0;
    static uint8_t count = 0;
    static uint8_t count2 = 0;
    static uint32_t connectionTimeout = 0;

    switch (lightShow)
    {
        case     BSP_LED_EASY_CONFIGURATION:
            if(SYS_TMR_TickCountGet() - ledTick >= 625)
            {
                ledTick = SYS_TMR_TickCountGet();
                BSP_LEDToggle(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
                BSP_LEDOff(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
                BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                BSP_LEDOff(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
            }
            break;

        case     BSP_LED_CONNECTING_TO_AP:
            if(SYS_TMR_TickCountGet() - connectionTimeout >= (1250 * 10))
            {
                connectionTimeout = SYS_TMR_TickCountGet();
                BSP_LED_LightShowSet(BSP_LED_CONNECTION_FAILED);
            }
            if (SYS_TMR_TickCountGet() - ledTick >= 150)
            {
                ledTick = SYS_TMR_TickCountGet();
                BSP_LEDOff(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
                BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
                switch (count)
                {
                    case (0):
                        BSP_LEDOn(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                        BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                        BSP_LEDOff(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                        BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
                        count++;
                        break;
                    case (1):
                        BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                        BSP_LEDOn(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                        BSP_LEDOff(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                        BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
                        count++;
                        break;
                    case (2):
                        BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                        BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                        BSP_LEDOff(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                        BSP_LEDOn(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
                        count++;
                        break;
                    case (3):
                        BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                        BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                        BSP_LEDOn(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                        BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
                        count = 0;
                        break;
                    default:
                        count = 0;
                        break;
                }

            }
            break;
            //Not implemented
        case     BSP_LED_CONNECTION_FAILED:
                BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                BSP_LEDOn(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                BSP_LEDOff(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
                BSP_LEDOn(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
                BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);

            if(SYS_TMR_TickCountGet() - connectionTimeout >= 4750)
            {
                connectionTimeout = SYS_TMR_TickCountGet();
                ledTick = SYS_TMR_TickCountGet();
                BSP_LED_LightShowSet(BSP_LED_CONNECTING_TO_AP);
            }
            break;
        case    BSP_LED_AP_CONNECTED:
                if(SYS_TMR_TickCountGet() - ledTick >= 625)
                {
                    count2++;
                    ledTick = SYS_TMR_TickCountGet();
                    BSP_LEDStateSet(BSP_LED_5_CHANNEL, BSP_LED_5_PORT, BSP_LEDStateGet(BSP_LED_6_CHANNEL, BSP_LED_6_PORT));
                    BSP_LEDToggle(BSP_LED_5_CHANNEL, BSP_LED_6_PORT);
                    BSP_LEDToggle(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
                    BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                    BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                    BSP_LEDOff(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                    BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
                }
            break;

        case    BSP_LED_SERVER_CONNECT_FAILED:
                BSP_LEDOn(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
                BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
                BSP_LEDOff(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
                BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
                BSP_LEDOn(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
                BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
            break;

        case    BSP_LED_ALL_GOOD:
                BSP_LEDOff(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
                BSP_LEDOff(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
                ledTick = SYS_TMR_TickCountGet();
            // Idle state
            break;
            
        case    BSP_LED_TX:
            BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
            if(SYS_TMR_TickCountGet() - ledTick >= 30)
                BSP_LED_LightShowSet(BSP_LED_ALL_GOOD);
            break;
            
        case    BSP_LED_RX:
            BSP_LEDOn(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
            if(SYS_TMR_TickCountGet() - ledTick >= 30)
                BSP_LED_LightShowSet(BSP_LED_ALL_GOOD);
            break; 

        case    BSP_LED_DNS_FAILED:
            BSP_LEDOn(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
            BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
            BSP_LEDOn(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
            BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
            BSP_LEDOn(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
            BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
        break;
        
        case    BSP_LED_TCPIP_STACK_INIT_FAILURE:
            BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
            BSP_LEDOn(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
            BSP_LEDOn(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
            BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
            BSP_LEDOn(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
            BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
        break;
        
        case BSP_LED_NVM_FAILED_MOUNT:
            BSP_LEDOff(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
            BSP_LEDOff(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
            BSP_LEDOn(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
            BSP_LEDOff(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
            BSP_LEDOn(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
            BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
        break;  
        
        case BSP_LED_INTIAL_CONNECT:
            BSP_LEDOn(BSP_LED_1_CHANNEL, BSP_LED_1_PORT);
            BSP_LEDOn(BSP_LED_2_CHANNEL, BSP_LED_2_PORT);
            BSP_LEDOn(BSP_LED_3_CHANNEL, BSP_LED_3_PORT);
            BSP_LEDOn(BSP_LED_4_CHANNEL, BSP_LED_4_PORT);
            BSP_LEDOn(BSP_LED_5_CHANNEL, BSP_LED_5_PORT);
            BSP_LEDOn(BSP_LED_6_CHANNEL, BSP_LED_6_PORT);
            
        default:
            break;
    }
}
コード例 #5
0
ファイル: app.c プロジェクト: neslerc/Homework2
void APP_Tasks (void )
{
    char message[25];
    char inputfrompc[25];
    int i;
    short accels[3]; // accelerations for the 3 axes
    short accelsMAF;
    short accelsFIR;
    int buf1=0;
    int buf2=0;
    int buf3=0;
    int buf4=0;
    int buf5=0;
    //bn*1000 for FIR
    float b1=.0088;
    float b2=.0479;
    float b3=.1640;
    float b4=.2793;
    float b5=.2793;
    float b6=.1640;
    float b7=.0479;
    float b8=.0088;

    int FIRbuf1=0;
    int FIRbuf2=0;
    int FIRbuf3=0;
    int FIRbuf4=0;
    int FIRbuf5=0;
    int FIRbuf6=0;
    int FIRbuf7=0;
    int FIRbuf8=0;


    //sprintf(message,"Hello!");
    //use_display(20,20,message);
    //display_draw();
    /* Check if device is configured.  See if it is configured with correct
     * configuration value  */

    switch(appData.state)
    {
        case APP_STATE_INIT:

            /* Open the device layer */
            appData.usbDevHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE );

            if(appData.usbDevHandle != USB_DEVICE_HANDLE_INVALID)
            {
                /* Register a callback with device layer to get event notification (for end point 0) */
                USB_DEVICE_EventHandlerSet(appData.usbDevHandle, APP_USBDeviceEventHandler, 0);

                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else
            {
                /* The Device Layer is not ready to be opened. We should try
                 * again later. */
            }

            break;

        case APP_STATE_WAIT_FOR_CONFIGURATION:

            if(appData.deviceConfigured == true)
            {
                /* Device is ready to run the main task */
                appData.hidDataReceived = false;
                appData.hidDataTransmitted = true;
                appData.state = APP_STATE_MAIN_TASK;

                /* Place a new read request. */
                USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                        &appData.rxTransferHandle, appData.receiveDataBuffer, 64);
            }
            break;

        case APP_STATE_MAIN_TASK:

            if(!appData.deviceConfigured)
            {
                /* Device is not configured */
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else if( appData.hidDataReceived )
            {
                /* Look at the data the host sent, to see what
                 * kind of application specific command it sent. */

                switch(appData.receiveDataBuffer[0])
                {
                    case 0x80:
                        /* Toggle on board LED1 to LED2. */
                        BSP_LEDToggle( APP_USB_LED_1 );
                        BSP_LEDToggle( APP_USB_LED_2 );
                        
                        for (i=0; i<8; i++){
                            inputfrompc[i] = appData.receiveDataBuffer[i+1];
                        }
                        use_display(20,20,inputfrompc);
                        display_draw();
                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );

                        break;

                    case 0x81:

                        if(appData.hidDataTransmitted)
                        {
                            /* Echo back to the host PC the command we are fulfilling in
                             * the first byte.  In this case, the Get Push-button State
                             * command. */

                            appData.transmitDataBuffer[0] = 0x81;

                            acc_read_register(OUT_X_L_A, (unsigned char *) accels, 6);
                            sprintf(message,"Z: %d",accels[0]);
                            use_display(10,10,message);
                            display_draw();
                            if(_CP0_GET_COUNT()>800000){
                                appData.transmitDataBuffer[1] = 1;
                                appData.transmitDataBuffer[2] = accels[0]>>8;
                                appData.transmitDataBuffer[3] = accels[0]&0xFF;

                                //use MAF buffer values to calculate accelsMAF
                                accelsMAF = ((buf1+buf2+buf3+buf4+buf5+accels[0])/6);

                                //change MAF buffer values
                                buf5=buf4;
                                buf4=buf3;
                                buf3=buf2;
                                buf2=buf1;
                                buf1=accels[0];



                                //change FIR buffer values
                                FIRbuf8=FIRbuf7;
                                FIRbuf7=FIRbuf6;
                                FIRbuf6=FIRbuf5;
                                FIRbuf5=FIRbuf4;
                                FIRbuf4=FIRbuf3;
                                FIRbuf3=FIRbuf2;
                                FIRbuf2=FIRbuf1;
                                FIRbuf1=accels[0];
                                //FIR Filtering calculations
                                accelsFIR = (b1*FIRbuf1)+(b2*FIRbuf2)+(b3*FIRbuf3)+(b4*FIRbuf4)+(b5*FIRbuf5)+(b6*FIRbuf6)+(b7*FIRbuf7)+(b8*FIRbuf8);

                                appData.transmitDataBuffer[4] = accelsMAF>>8;
                                appData.transmitDataBuffer[5] = accelsMAF&0xFF;
                                appData.transmitDataBuffer[6] = accelsFIR>>8;
                                appData.transmitDataBuffer[7] = accelsFIR&0xFF;
                                _CP0_SET_COUNT(0);

                            }
                            else{appData.transmitDataBuffer[1]=0;}


                            

                            appData.hidDataTransmitted = false;

                            /* Prepare the USB module to send the data packet to the host */
                            USB_DEVICE_HID_ReportSend (USB_DEVICE_HID_INDEX_0,
                                    &appData.txTransferHandle, appData.transmitDataBuffer, 64 );

                            appData.hidDataReceived = false;

                            /* Place a new read request. */
                            USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                    &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        }
                        break;

                    default:

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        break;
                }
コード例 #6
0
ファイル: app.c プロジェクト: andrewturchina/me_433
void APP_Tasks (void )
{

    /* Check if device is configured.  See if it is configured with correct
     * configuration value  */

    switch(appData.state)
    {
        case APP_STATE_INIT:

            /* Open the device layer */
            appData.usbDevHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE );

            if(appData.usbDevHandle != USB_DEVICE_HANDLE_INVALID)
            {
                /* Register a callback with device layer to get event notification (for end point 0) */
                USB_DEVICE_EventHandlerSet(appData.usbDevHandle, APP_USBDeviceEventHandler, 0);

                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else
            {
                /* The Device Layer is not ready to be opened. We should try
                 * again later. */
            }

            break;

        case APP_STATE_WAIT_FOR_CONFIGURATION:

            if(appData.deviceConfigured == true)
            {
                /* Device is ready to run the main task */
                appData.hidDataReceived = false;
                appData.hidDataTransmitted = true;
                appData.state = APP_STATE_MAIN_TASK;

                /* Place a new read request. */
                USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                        &appData.rxTransferHandle, appData.receiveDataBuffer, 64);
            }
            break;

        case APP_STATE_MAIN_TASK:

            if(!appData.deviceConfigured)
            {
                /* Device is not configured */
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else if( appData.hidDataReceived )
            {
                /* Look at the data the host sent, to see what
                 * kind of application specific command it sent. */

                switch(appData.receiveDataBuffer[0])
                {
                    case 0x80:

                        /* Toggle on board LED1 to LED2. */
                        BSP_LEDToggle( APP_USB_LED_1 );
                        BSP_LEDToggle( APP_USB_LED_2 );

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );

                        break;

                    case 0x81:

                        if(appData.hidDataTransmitted)
                        {
                            /* Echo back to the host PC the command we are fulfilling in
                             * the first byte.  In this case, the Get Push-button State
                             * command. */

                            appData.transmitDataBuffer[0] = 0x81;

                            if( BSP_SwitchStateGet(APP_USB_SWITCH_1) == BSP_SWITCH_STATE_PRESSED )
                            {
                                appData.transmitDataBuffer[1] = 0x00;
                            }
                            else
                            {
                                appData.transmitDataBuffer[1] = 0x01;
                            }

                            appData.hidDataTransmitted = false;

                            /* Prepare the USB module to send the data packet to the host */
                            USB_DEVICE_HID_ReportSend (USB_DEVICE_HID_INDEX_0,
                                    &appData.txTransferHandle, appData.transmitDataBuffer, 64 );

                            appData.hidDataReceived = false;

                            /* Place a new read request. */
                            USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                    &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        }
                        break;

                    default:

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        break;
                }
            }
        case APP_STATE_ERROR:
            break;
        default:
            break;
    }
}
コード例 #7
0
ファイル: flir.c プロジェクト: MattAtHazmat/flirry
/* Application's Timer Callback Function */
static void TimerCallback (  uintptr_t context, uint32_t alarmCount )
{
    global_events.global_event_1 = true;   
    BSP_LEDToggle(BSP_LED_1);
}
コード例 #8
0
ファイル: app.c プロジェクト: mjc401/ME433
void APP_Tasks (void )
{
    unsigned char print[26];
    int jj = 0,row;
    short accels[3];
    /* Check if device is configured.  See if it is configured with correct
     * configuration value  */

    switch(appData.state)
    {
        case APP_STATE_INIT:

            /* Open the device layer */
            appData.usbDevHandle = USB_DEVICE_Open( USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE );

            if(appData.usbDevHandle != USB_DEVICE_HANDLE_INVALID)
            {
                /* Register a callback with device layer to get event notification (for end point 0) */
                USB_DEVICE_EventHandlerSet(appData.usbDevHandle, APP_USBDeviceEventHandler, 0);

                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else
            {
                /* The Device Layer is not ready to be opened. We should try
                 * again later. */
            }

            break;

        case APP_STATE_WAIT_FOR_CONFIGURATION:

            if(appData.deviceConfigured == true)
            {
                /* Device is ready to run the main task */
                appData.hidDataReceived = false;
                appData.hidDataTransmitted = true;
                appData.state = APP_STATE_MAIN_TASK;

                /* Place a new read request. */
                USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                        &appData.rxTransferHandle, appData.receiveDataBuffer, 64);
            }
            break;

        case APP_STATE_MAIN_TASK:

            if(!appData.deviceConfigured)
            {
                /* Device is not configured */
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            }
            else if( appData.hidDataReceived )
            {
                /* Look at the data the host sent, to see what
                 * kind of application specific command it sent. */

                switch(appData.receiveDataBuffer[0])
                {
                    case 0x1:
                        /* Toggle on board LED1 to LED2. */
                        BSP_LEDToggle( APP_USB_LED_1 );
                        BSP_LEDToggle( APP_USB_LED_2 );

                        memcpy(print,&appData.receiveDataBuffer[2],25);
                        print[26] = '\0';

                        display_clear();
                        write_OLED_message(print,appData.receiveDataBuffer[1],0);
                        display_draw();

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        _CP0_SET_COUNT(0);

                        break;

                    case 0x2:

                        if(appData.hidDataTransmitted)
                        {
                            /* Echo back to the host PC the command we are fulfilling in
                             * the first byte.  In this case, the Get Push-button State
                             * command. */
                             BSP_LEDToggle( APP_USB_LED_1 );
                             BSP_LEDToggle( APP_USB_LED_2 );
   
                            if(_CP0_GET_COUNT() > 200000){
                                appData.transmitDataBuffer[0] = 1;
                                acc_read_register(OUT_X_L_A,(unsigned char *) accels, 6);
                                appData.transmitDataBuffer[1] = accels[0] >> 8;
                                appData.transmitDataBuffer[2] = accels[0];
                                appData.transmitDataBuffer[3] = accels[1] >> 8;
                                appData.transmitDataBuffer[4] = accels[1];
                                appData.transmitDataBuffer[5] = accels[2] >> 8;
                                appData.transmitDataBuffer[6] = accels[2];
                                 _CP0_SET_COUNT(0);
                            }
                            else{
                                appData.transmitDataBuffer[0] = 0;
                            }
//                            appData.transmitDataBuffer[0] = 0x81;
//
//                            if( BSP_SwitchStateGet(APP_USB_SWITCH_1) == BSP_SWITCH_STATE_PRESSED )
//                            {
//                                appData.transmitDataBuffer[1] = 0x00;
//                            }
//                            else
//                            {
//                                appData.transmitDataBuffer[1] = 0x01;
//                            }

                            appData.hidDataTransmitted = false;

                            /* Prepare the USB module to send the data packet to the host */
                            USB_DEVICE_HID_ReportSend (USB_DEVICE_HID_INDEX_0,
                                    &appData.txTransferHandle, appData.transmitDataBuffer, 64 );

                            appData.hidDataReceived = false;

                            /* Place a new read request. */
                            USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                    &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        }
                        break;

                    default:

                        appData.hidDataReceived = false;

                        /* Place a new read request. */
                        USB_DEVICE_HID_ReportReceive (USB_DEVICE_HID_INDEX_0,
                                &appData.rxTransferHandle, appData.receiveDataBuffer, 64 );
                        break;
                }
コード例 #9
0
ファイル: app.c プロジェクト: jtaseff/433_jnt606
void APP_Tasks(void) {

    /* Check if device is configured.  See if it is configured with correct
     * configuration value  */

    switch (appData.state) {
        case APP_STATE_INIT:



            /* Open the device layer */
            appData.usbDevHandle = USB_DEVICE_Open(USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE);

            if (appData.usbDevHandle != USB_DEVICE_HANDLE_INVALID) {
                /* Register a callback with device layer to get event notification (for end point 0) */
                USB_DEVICE_EventHandlerSet(appData.usbDevHandle, APP_USBDeviceEventHandler, 0);

                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            } else {
                /* The Device Layer is not ready to be opened. We should try
                 * again later. */
            }

            break;

        case APP_STATE_WAIT_FOR_CONFIGURATION:

            if (appData.deviceConfigured == true) {
                /* Device is ready to run the main task */
                appData.hidDataReceived = false;
                appData.hidDataTransmitted = true;
                appData.state = APP_STATE_MAIN_TASK;

                /* Place a new read request. */
                USB_DEVICE_HID_ReportReceive(USB_DEVICE_HID_INDEX_0,
                        &appData.rxTransferHandle, appData.receiveDataBuffer, 64);
            }
            break;

        case APP_STATE_MAIN_TASK:

            if (!appData.deviceConfigured) {
                /* Device is not configured */
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            } else if (appData.hidDataReceived) {
                /* Look at the data the host sent, to see what
                 * kind of application specific command it sent. */

                switch (appData.receiveDataBuffer[0]) {
                    case 0x80:

                        /* Toggle on board LED1 to LED2. */
                        BSP_LEDToggle(APP_USB_LED_1);
                        BSP_LEDToggle(APP_USB_LED_2);



                        setRTR();
                        break;

                    case 0x81:
                        if (appData.hidDataTransmitted) {
                            /* Echo back to the host PC the command we are fulfilling in
                             * the first byte.  In this case, the Get Push-button State
                             * command. */

                            appData.transmitDataBuffer[0] = 0x81;

                            appData.transmitDataBuffer[1] = 0b1 & BSP_SwitchStateGet(APP_USB_SWITCH_1);

                            appData.transmitDataBuffer[2] = 111;


                            setRTS();
                            setRTR();
                        }
                        break;


                    case 0x82:
                        if (!appData.numTX || _CP0_GET_COUNT() > 200000) {

                            //prepare new data to send
                            acc_read_register(OUT_X_L_A, (unsigned char *) appData.accels, 6);
                            appData.transmitDataBuffer[0] = 1; //we have data to send
                            appData.transmitDataBuffer[1] = appData.accels[0] >> 8; //x high byte
                            appData.transmitDataBuffer[2] = appData.accels[0] & 0xFF; //x low byte
                            appData.transmitDataBuffer[3] = appData.accels[1] >> 8; //y high byte
                            appData.transmitDataBuffer[4] = appData.accels[1] & 0xFF; //y low byte
                            appData.transmitDataBuffer[5] = appData.accels[2] >> 8; //z high byte
                            appData.transmitDataBuffer[6] = appData.accels[2] & 0xFF; //z low byte

                            // reset core timer for 100 hz
                            _CP0_SET_COUNT(0);
                            appData.numTX++;
                        }
                        else {
                            appData.transmitDataBuffer[0] = 0;  // we don't have new data
                        }

                        setRTS();
                        setRTR();
                        break;

                    case 0x83:
                        // prepare for a bout of sending accel data
                        //parse incoming data to screen
                        oled_clear_buffer();
                        int row = appData.receiveDataBuffer[1];
                        char * msg;
                        msg = &appData.receiveDataBuffer[2];

                        oled_draw_string(0, row, msg, 1);
                        oled_update();


                        // clear buffered accel data so we read new data to send
                        acc_read_register(OUT_X_L_A, (unsigned char *) appData.accels, 6);

                        appData.numTX = 0; //we're starting over

                        setRTR();
                        break;

                    case 0x84:
                        // done asking for data
                        oled_draw_string(0, 55, "Done!", 1);
                        oled_update();

                        setRTR();
                        break;

                    default:
                        setRTR();
                        break;
                }
            }