Beispiel #1
0
/***********************************************************************************
* @fn          appRfReceiverTask
*
* @brief       Check if a new packet has been received. If a new packet
*              is received the payload is sent to the UART.
*
* @param       none
*
* @return      none
*/
static void appRfReceiverTask(void)
{

    if (mrfiLinkDataRdy()) {
        uint8 nToSend;
        uint8 fSuccess;

        // Tell the PC not to send data
        halUartEnableRxFlow(FALSE);

        // Wait for the PC to respond
        halMcuWaitUs(1000);

        // Receive RF data
        nToSend = mrfiLinkRecv(pRxData);

        // If reception successful, send packet to UART
        fSuccess= FALSE;
        if(nToSend>0) {
            if (halUartWrite(pRxData,nToSend)==nToSend)
                fSuccess= TRUE;
        }

        if (!fSuccess) {
            nRxErr++;
            appUpdateDisplay();
        }

        // Signal RX flow on, the PC may send data again
        halUartEnableRxFlow(TRUE);
    }
}
/***********************************************************************************
* @fn          main
*
* @brief       This is the main entry of the RF HID application. It sets
*              distinct short addresses for the nodes, initalises and runs
*              receiver and sender tasks sequentially in an endless loop.
*
* @return      none
*/
void main(void)
{

    // Initialise board peripherals
    halBoardInit();

    // Initialise USB
    usbHidInit();

    // Initialize MRFI
    mrfiLinkInit(DONGLE_ADDRESS,EB_ADDRESS,MRFI_CHANNEL);

    // Indicate that the device is initialised
    halLedSet(1);

    //  Main processing loop
    while (TRUE) {

        // Process USB standard requests
        usbHidProcessEvents();

        // Process incoming radio traffic from HID devices
        if (mrfiLinkDataRdy()) {

            uint8 numBytes;

            // Receive RF packet
            numBytes = mrfiLinkRecv(pRfData);

            // If reception successful, ACK it and send packet to host over USB
            if(numBytes>0) {

                if (pRfData[0]==KEYBOARD_DATA_ID && numBytes==KEYBOARD_DATA_SIZE) {
                    // Process keyboard data
                    usbHidProcessKeyboard(pRfData);
                    halLedToggle(1);
                }

                if (pRfData[0]==MOUSE_DATA_ID && numBytes==MOUSE_DATA_SIZE) {
                    // Process mouse data
                    usbHidProcessMouse(pRfData);
                    halLedToggle(1);
                }

            }

        }

    }

}