Пример #1
0
u8 CDCgetkey(void)
{
    u8 buffer[_CDCBUFFERLENGTH_];		// always get a full packet

    while (!CDCgets(buffer));
    return (buffer[0]);	// return only the first character
}
    /********************************************************************
     * Function:        int pureDataCommunicate(void)*
     * Input:           None
     * Output:          None
     * Overview:        Reads the CDC port, and stores the read values on a
     *                  buffer (inputData)it then routes the input data to
     *                  functions that take care of specific actions.
     *                  Note that the size of the arrays passed to this function
     *                  correspond to the number of Pins available in the
     *                  specific Pinguino. It also prints a 50 through the CDC
     *                  when the button is pressed.
     * Return:          int dataLength - the length of the array received.
     * Note:            None
     *******************************************************************/
    int pureDataCommunicate(unsigned char inputData[], unsigned char reportDg[],
                                    unsigned long int reportAn[]){


        if (((PORTDbits.RD4 == 0)&&(TRISDbits.TRISD4))
                ||((PORTDbits.RD0 == 0)&&(TRISDbits.TRISD0))){ //IS BUTTON
            CDCwrite(50);                                      //PRESSED?
        }


        dataLength = CDCgets(inputData);


        if ((inputData[0] >= SET_DIGITAL_VALUE) && (inputData[0] < 0xA0)){

            pureDataSetDigital(inputData);

        }

        else if ((inputData[0] >= SET_ANALOG_VALUE) && (inputData[0] < SET_PIN_MODE)){

            pureDataSetAnalog(inputData);

        }

        else if ((inputData[0] >= SET_PIN_MODE) && (inputData[0] < 0xFF)){// SEE MIDI MESSAGE FORMAT


            pureDataSetPin(inputData);

        }

        counter++;

        // REPORT ONLY ONCE EVERY 20 TIMES, TO AVOID SATURATION OF RECEIVER.
        if(counter == 20){
        pureDataSendState(reportDg, reportAn);
        counter = 0;
        }

        return dataLength;

    }