Exemplo n.º 1
0
/****************************************************************************
  Function:
    void App_ProcessInputReport(void)

  Description:
    This function processes input report received from HID device.

  Precondition:
    None

  Parameters:
    None

  Return Values:
    None

  Remarks:
    None
***************************************************************************/
static void App_ProcessInputReport(void)
{
    char printBuffer[30];
    
   /* process input report received from device */
    USBHostHID_ApiImportData(   mouse.buffer,
                                mouse.size,
                                mouse.deflection.parsed.data,
                                &mouse.deflection.parsed.details
                            );
    
    USBHostHID_ApiImportData(   mouse.buffer,
                                mouse.size,
                                mouse.buttons.parsed.data,
                                &mouse.buttons.parsed.details
                            );

    /* For the string that we will print out.  It will be of the following form:
     * X: 0xAA Y: 0xBB
     * L: 0 R: 1
     */
    sprintf(printBuffer, "L:%01X R:%01X\r\nX:0x%02X Y:0x%02X\r\n", mouse.buttons.parsed.data[0], mouse.buttons.parsed.data[1], mouse.deflection.parsed.data[0], mouse.deflection.parsed.data[1]);

    PRINT_String(printBuffer, 24);
}
Exemplo n.º 2
0
/****************************************************************************
  Function:
    void App_ProcessInputReport_Mouse(void)

  Description:
    This function processes input report received from HID Mouse device.

  Precondition:
    None

  Parameters:
    None

  Return Values:
    None

  Remarks:
    None
***************************************************************************/
void App_ProcessInputReport_Mouse(void)
{
   /* process input report received from device */
    USBHostHID_ApiImportData(Appl_raw_report_buffer.ReportData, Appl_raw_report_buffer.ReportSize
                          ,Appl_Button_report_buffer, &Appl_Mouse_Buttons_Details);
    USBHostHID_ApiImportData(Appl_raw_report_buffer.ReportData, Appl_raw_report_buffer.ReportSize
                          ,Appl_XY_report_buffer, &Appl_XY_Axis_Details);

    {
        unsigned int i;

        UART2PrintString( "\r\n" );
        UART2PrintString( UHP_MOUSE_REPORT );
        for(i=0;i<(Appl_raw_report_buffer.ReportSize);i++)
        {
            if(i!=0) UART2PrintString( "-" );
            UART2PutHex( Appl_raw_report_buffer.ReportData[i]);
        }
        UART2PrintString( "\r\n" );
//        UART2PrintString( "\r\n  Left Bt :  " ); UART2PutHex( Appl_Button_report_buffer[0]);
//        UART2PrintString( "\r\n  Right Bt :  " ); UART2PutHex( Appl_Button_report_buffer[1]);
//
//        UART2PrintString( "\r\n  X-Axis :  " ); UART2PutHex( Appl_XY_report_buffer[0]);
//        UART2PrintString( "\r\n  Y-Axis :  " ); UART2PutHex( Appl_XY_report_buffer[1]);

        if(Appl_Button_report_buffer[0] == 0x01)
        {
                // Turn on Left Button, Green LED, D1
                TRISBbits.TRISB12 = 0;
                _RB12=0;
        }
        else
        {
                // Turn off Left Button, Green LED, D1
                TRISBbits.TRISB12 = 1;
        }

        if(Appl_Button_report_buffer[1] == 0x01)
        {
                // Turn on Left Button, Green LED, D1
                TRISBbits.TRISB14 = 0;
                _RB14=0;
        }
        else
        {
                // Turn off Left Button, Green LED, D1
                TRISBbits.TRISB14 = 1;
        }

    }

}
Exemplo n.º 3
0
static void App_KeyboardInputReport(BYTE deviceAddress, USB_KEYBOARD_DATA *data)
{
    int i;
    /* process input report received from device */
    USBHostHID_ApiImportData(Appl_raw_report_buffer[deviceAddress].ReportData, Appl_raw_report_buffer[deviceAddress].ReportSize
            ,Appl_BufferModifierKeys, &Appl_ModifierKeysDetails[deviceAddress]);
    USBHostHID_ApiImportData(Appl_raw_report_buffer[deviceAddress].ReportData, Appl_raw_report_buffer[deviceAddress].ReportSize
            ,Appl_BufferNormalKeys, &Appl_NormalKeysDetails[deviceAddress]);

#ifdef DEBUG_MODE
    int i;
    putstr( "HID: Raw Report \r\n");
    putstr("ReportSize="); putdec(Appl_raw_report_buffer[deviceAddress].ReportSize);putstr("\r\n");
    for(i=0;i<(Appl_raw_report_buffer[deviceAddress].ReportSize);i++){
        puthex( Appl_raw_report_buffer[deviceAddress].ReportData[i]);
    }
    putstr("\r\n");
#endif

    // modifier
    *((BYTE *)&(data->modifier)) = Appl_raw_report_buffer[deviceAddress].ReportData[0];
    // keycode
    memcpy(data->keycode, &(Appl_raw_report_buffer[deviceAddress].ReportData[2]), 3);

    // check CapsLock NumericLock
    for(i=2;i<(Appl_raw_report_buffer[deviceAddress].ReportSize);i++){
        if(Appl_raw_report_buffer[deviceAddress].ReportData[i] != 0){
            if(Appl_raw_report_buffer[deviceAddress].ReportData[i] == HID_CAPS_LOCK_VAL){
                CAPS_Lock_Pressed[deviceAddress] = !CAPS_Lock_Pressed[deviceAddress];
                LED_Key_Pressed[deviceAddress] = TRUE;
                Appl_led_report_buffer[deviceAddress].CAPS_LOCK = CAPS_Lock_Pressed[deviceAddress];
            }else if(Appl_raw_report_buffer[deviceAddress].ReportData[i] == HID_NUM_LOCK_VAL){
                NUM_Lock_Pressed[deviceAddress] = !NUM_Lock_Pressed[deviceAddress];
                LED_Key_Pressed[deviceAddress] = TRUE;
                Appl_led_report_buffer[deviceAddress].NUM_LOCK = NUM_Lock_Pressed[deviceAddress];
            }
        }
    }

    if(CAPS_Lock_Pressed[deviceAddress]) data->modifier.capslock=1;
    else  data->modifier.capslock=0;

    if(NUM_Lock_Pressed[deviceAddress])  data->modifier.numlock=1;
    else  data->modifier.numlock=0;

    // clear receive buffer
    for(i=0;i<Appl_raw_report_buffer[deviceAddress].ReportSize;i++){
        Appl_raw_report_buffer[deviceAddress].ReportData[i] = 0;
    }

}
Exemplo n.º 4
0
void App_ProcessInputReport_Keyboard(void)
{
    BYTE  i;
    BYTE  j;
   /* process input report received from device */
    USBHostHID_ApiImportData(Appl_raw_report_buffer.ReportData, Appl_raw_report_buffer.ReportSize
                          ,Appl_BufferModifierKeys, &Appl_ModifierKeysDetails);
    USBHostHID_ApiImportData(Appl_raw_report_buffer.ReportData, Appl_raw_report_buffer.ReportSize
                          ,Appl_BufferNormalKeys, &Appl_NormalKeysDetails);

    BOOL before = TRUE;
    BOOL csnLock = FALSE;
    BOOL allZero = TRUE;
    for(i=0;i<(sizeof(Appl_BufferNormalKeys)/sizeof(Appl_BufferNormalKeys[0]));i++)
    {
        if(Appl_BufferNormalKeys[i])
            allZero = FALSE;
        if(!App_CompareKeyPressedPrevBuf(Appl_BufferNormalKeys[i]))  {
            before = FALSE;
            if(Appl_BufferNormalKeys[i] == HID_CAPS_LOCK_VAL)
            {
               CAPS_Lock_Pressed = !CAPS_Lock_Pressed;
               LED_Key_Pressed = csnLock = TRUE;
               Appl_led_report_buffer.CAPS_LOCK = CAPS_Lock_Pressed;
            }else if(Appl_BufferNormalKeys[i] == HID_NUM_LOCK_VAL)
            {
                NUM_Lock_Pressed = !NUM_Lock_Pressed;
                LED_Key_Pressed = csnLock = TRUE;
                Appl_led_report_buffer.NUM_LOCK = NUM_Lock_Pressed;
            }else if(Appl_BufferNormalKeys[i] == HID_SCROLL_LOCK_VAL)
            {
                SCROLL_Lock_Pressed = !SCROLL_Lock_Pressed;
                LED_Key_Pressed = csnLock = TRUE;
                Appl_led_report_buffer.SCROLL_LOCK = SCROLL_Lock_Pressed;
            }
        }
    }
    if(allZero && allZero!=lastAllZero)
        before = FALSE;
    lastAllZero = allZero;
    
    if(!csnLock) {
        if(before && KeyRepeatCounter<=REPEAT_COUNT)
            KeyRepeatCounter++;
        if(!before || KeyRepeatCounter>REPEAT_COUNT) {
        /* check if key press was present in previous report */
        // if key press was pressed in previous report neglect it ????
            UART2PrintString( "\r\n" );
            UART2PrintString( UHP_KEYBOARD_REPORT );
            for(j=0;j<(Appl_raw_report_buffer.ReportSize);j++)
            {
                if(j!=0) UART2PrintString( "-" );
                if(j==0 && CAPS_Lock_Pressed)
                    UART2PutHex( Appl_raw_report_buffer.ReportData[j] ^ 0x02);
                else
                    UART2PutHex( Appl_raw_report_buffer.ReportData[j]);
            }
            UART2PrintString( "\r\n" );
            //data = App_HID2ASCII(Appl_BufferNormalKeys[i]);  // convert data to ascii
            //UART2PutChar(data);
        }
    }
    if(!before)
        KeyRepeatCounter = 0;
  App_CopyToShadowBuffer();
  App_Clear_Data_Buffer();
}
/****************************************************************************
  Function:
    void App_ProcessInputReport(void)

  Description:
    This function processes input report received from HID device.

  Precondition:
    None

  Parameters:
    None

  Return Values:
    None

  Remarks:
    None
***************************************************************************/
static void App_ProcessInputReport(void)
{
    uint8_t  i, j;
    bool heldCharacter = false;
    bool shift = false;

   /* process input report received from device */
    USBHostHID_ApiImportData(   keyboard.keys.buffer,
                                keyboard.keys.size,
                                keyboard.keys.modifier.parsed.data,
                                &keyboard.keys.modifier.parsed.details
                            );
    
    USBHostHID_ApiImportData(   keyboard.keys.buffer,
                                keyboard.keys.size,
                                keyboard.keys.normal.parsed.newData,
                                &keyboard.keys.normal.parsed.details
                            );

    if(keyboard.keys.modifier.parsed.data[USB_HID_KEYBOARD_KEYPAD_KEYBOARD_LEFT_SHIFT - USB_HID_KEYBOARD_KEYPAD_KEYBOARD_LEFT_CONTROL] == 1)
    {
        shift = true;
    }

    if(keyboard.keys.modifier.parsed.data[USB_HID_KEYBOARD_KEYPAD_KEYBOARD_RIGHT_SHIFT - USB_HID_KEYBOARD_KEYPAD_KEYBOARD_LEFT_CONTROL] == 1)
    {
        shift = true;
    }

    for(i=0; i<keyboard.keys.normal.parsed.details.reportLength ;i++)
    {
        heldCharacter = false;
        
        if(keyboard.keys.normal.parsed.newData[i] != 0)
        {
            for(j=0; j<keyboard.keys.normal.parsed.details.reportLength ;j++)
            {
                if(keyboard.keys.normal.parsed.newData[i] == keyboard.keys.normal.parsed.oldData[j])
                {
                    heldCharacter = true;
                    break;
                }
            }

            if(heldCharacter == true)
            {
                continue;
            }
            
            if(keyboard.keys.normal.parsed.newData[i] == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_CAPS_LOCK)
            {
                keyboard.leds.report.bits.capsLock ^= 1;
                keyboard.leds.updated = true;
            }else if(keyboard.keys.normal.parsed.newData[i] == USB_HID_KEYBOARD_KEYPAD_KEYPAD_NUM_LOCK_AND_CLEAR)
            {
                keyboard.leds.report.bits.numLock ^= 1;
                keyboard.leds.updated = true;
            }else
            {
                HID_USER_DATA_SIZE key = keyboard.keys.normal.parsed.newData[i];
               
                if(key == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_ESCAPE)
                {
                    PRINT_ClearScreen();
                }
                else if(key == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_RETURN_ENTER)
                {
                    PRINT_String("\r\n", 2);
                }
                else if( (key == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_RIGHT_SHIFT) ||
                         (key == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_LEFT_SHIFT)
                       )
                {
                    shift = true;
                }
                else if( (key == USB_HID_KEYBOARD_KEYPAD_KEYPAD_BACKSPACE) ||
                         (key == USB_HID_KEYBOARD_KEYPAD_KEYBOARD_DELETE)
                       )
                {
                    PRINT_Char('\b');
                }
                else if( (key >= USB_HID_KEYBOARD_KEYPAD_KEYBOARD_A) &&
                         (key <= USB_HID_KEYBOARD_KEYPAD_KEYBOARD_Z)
                       )
                {
                    uint8_t index;

                    for(index = 0; index < sizeof(keyTranslationTable)/sizeof(HID_KEY_TRANSLATION_TABLE_ENTRY); index++)
                    {
                        if(keyTranslationTable[index].key == key)
                        {
                            if( (keyboard.leds.report.bits.capsLock == 1) || (shift == true) )
                            {
                                PRINT_Char(keyTranslationTable[index].modified);
                            }
                            else
                            {
                                PRINT_Char(keyTranslationTable[index].unmodified);
                            }
                        }
                    }
                }
                else
                {
                    uint8_t index;

                    for(index = 0; index < sizeof(keyTranslationTable)/sizeof(HID_KEY_TRANSLATION_TABLE_ENTRY); index++)
                    {
                        if(keyTranslationTable[index].key == key)
                        {
                            if( shift == true )
                            {
                                PRINT_Char(keyTranslationTable[index].modified);
                            }
                            else
                            {
                                PRINT_Char(keyTranslationTable[index].unmodified);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            break;
        }
    }

    memcpy(keyboard.keys.normal.parsed.oldData, keyboard.keys.normal.parsed.newData, sizeof(keyboard.keys.normal.parsed.newData));
    memset(keyboard.keys.normal.parsed.newData, 0x00, sizeof(keyboard.keys.normal.parsed.newData));
}
Exemplo n.º 6
0
/****************************************************************************
	Function:
		void App_ProcessInputReport(void)

	Description:
		This function processes input report received from HID device.

	Precondition:
		None

	Parameters:
		None

	Return Values:
		None

	Remarks:
		None
 ***************************************************************************/
void App_ProcessInputReport(void)
{
	BYTE  i, j;
	BOOL pressed;
	BYTE modifier_keys;
	BYTE pressed_keys_count;

	/* process input report received from device */
	USBHostHID_ApiImportData(Appl_raw_report_buffer.ReportData, Appl_raw_report_buffer.ReportSize
													, Appl_BufferModifierKeys, &Appl_ModifierKeysDetails);
	USBHostHID_ApiImportData(Appl_raw_report_buffer.ReportData, Appl_raw_report_buffer.ReportSize
													, Appl_BufferNormalKeys, &Appl_NormalKeysDetails);


	// process modifier keys
	modifier_keys = 0;
	if(Appl_BufferModifierKeys[MODIFIER_LEFT_CONTROL] != 0)
		modifier_keys |= MF_LEFT_CONTROL;

	if(Appl_BufferModifierKeys[MODIFIER_LEFT_SHIFT] != 0)
		modifier_keys |= MF_LEFT_SHIFT;

	if(Appl_BufferModifierKeys[MODIFIER_LEFT_ALT] != 0)
		modifier_keys |= MF_LEFT_ALT;

	if(Appl_BufferModifierKeys[MODIFIER_LEFT_GUI] != 0)
		modifier_keys |= MF_LEFT_GUI;

	if(Appl_BufferModifierKeys[MODIFIER_RIGHT_CONTROL] != 0)
		modifier_keys |= MF_RIGHT_CONTROL;

	if(Appl_BufferModifierKeys[MODIFIER_RIGHT_SHIFT] != 0)
		modifier_keys |= MF_RIGHT_SHIFT;

	if(Appl_BufferModifierKeys[MODIFIER_RIGHT_ALT] != 0)
		modifier_keys |= MF_RIGHT_ALT;

	if(Appl_BufferModifierKeys[MODIFIER_RIGHT_GUI] != 0)
		modifier_keys |= MF_RIGHT_GUI;

	UpdateModifierKeys(modifier_keys);

	// update keys
	pressed_keys_count = 0;
	for (i = 0; i < KEY_REPORT_DATA_LENGTH; i++)
	{
		// pressed keys
		if (Appl_BufferNormalKeys[i] != 0)
		{
			pressed_keys_count++;

			switch (Appl_BufferNormalKeys[i])
			{
					// CAPS lock
				case HID_CAPS_LOCK_VAL:
					CAPS_Lock_Pressed = !CAPS_Lock_Pressed;
					LED_Key_Pressed = TRUE;
					Appl_led_report_buffer.CAPS_LOCK = CAPS_Lock_Pressed;
					break;

					// NUM lock
				case HID_NUM_LOCK_VAL:
					NUM_Lock_Pressed = !NUM_Lock_Pressed;
					LED_Key_Pressed = TRUE;
					Appl_led_report_buffer.NUM_LOCK = NUM_Lock_Pressed;
					break;

					// any other key
				default:
					// check if it was pressed earlier
					pressed = TRUE;
					for (j = 0; j < KEY_REPORT_DATA_LENGTH && pressed; j++)
					{
						if (Appl_BufferNormalKeys[i] == Appl_BufferPreviousKeys[j])
							pressed = FALSE;
					}

					// it appears first in the current report -> key was pressed
					if (pressed)
					{
						UpdateKeyboardMatrix(Appl_BufferNormalKeys[i], modifier_keys, TRUE);
					}
			}
		}
		else
		{
			// no more keys to process
			break;
		}
	}

	// process released keys
	for (i = 0; i < KEY_REPORT_DATA_LENGTH; i++)
	{
		if(Appl_BufferPreviousKeys[i] != 0)
		{
			pressed = FALSE;
			for(j=0;j<KEY_REPORT_DATA_LENGTH && !pressed;j++)
			{
				if(Appl_BufferPreviousKeys[i] == Appl_BufferNormalKeys[j])
					pressed = TRUE;
			}

			if(!pressed)
			{
				// key was released
				UpdateKeyboardMatrix(Appl_BufferPreviousKeys[i], modifier_keys, FALSE);
			}
		}
		else
		{
			break;
		}
	}

	// just for sure clear matrix when no key is pressed
	if(modifier_keys == 0 && pressed_keys_count == 0)
		ClearKeyboardMatrix();

	// copy report data to the previous buffer
	for (i = 0; i < KEY_REPORT_DATA_LENGTH; i++)
		Appl_BufferPreviousKeys[i] = Appl_BufferNormalKeys[i];

	// clear report buffer
	for (i = 0; i < KEY_REPORT_DATA_LENGTH; i++)
		Appl_BufferNormalKeys[i] = 0;

	for (i = 0; i < Appl_raw_report_buffer.ReportSize; i++)
		Appl_raw_report_buffer.ReportData[i] = 0;
}