USB Libraries Help > USB Device Libraries > USB HID Device Library > Library Interface > a) Functions > USB_DEVICE_HID_EventHandlerSet Function
MPLAB Harmony USB Stack
USB_DEVICE_HID_EventHandlerSet Function

This function registers a event handler for the specified HID function driver instance. This function should be called by the client when it receives a SET CONFIGURATION event from the device layer. A event handler must be registered for function driver to respond to function driver specific commands. If the event handler is not registered, the device layer will stall function driver specific commands and the USB device may not function.

C
USB_DEVICE_HID_RESULT USB_DEVICE_HID_EventHandlerSet(
    USB_DEVICE_HID_INDEX instanceIndex, 
    USB_DEVICE_HID_EVENT_HANDLER eventHandler, 
    uintptr_t context
);
Preconditions

This function should be called when the function driver has been initialized as a result of a set configuration.

Parameters
Parameters 
Description 
instance 
Instance of the HID Function Driver.
 
eventHandler 
A pointer to event handler function.
 
context 
Application specific context that is returned in the event handler. 
Returns

USB_DEVICE_HID_RESULT_OK - The operation was successful 

USB_DEVICE_HID_RESULT_ERROR_INSTANCE_INVALID - The specified instance does not exist. 

USB_DEVICE_HID_RESULT_ERROR_PARAMETER_INVALID - The eventHandler parameter is NULL

Remarks

None.

Example
// This code snippet shows an example registering an event handler. Here
// the application specifies the context parameter as a pointer to an
// application object (appObject) that should be associated with this 
// instance of the HID function driver.

USB_DEVICE_HID_RESULT result;

USB_DEVICE_HID_EVENT_RESPONSE APP_USBDeviceHIDEventHandler 
(
    USB_DEVICE_HID_INDEX instanceIndex,
    USB_DEVICE_HID_EVENT event,
    void * pData,
    uintptr_t context 
)
{
    // Event Handling comes here

    switch(event) 
    {
        ...
    }

    return(USB_DEVICE_HID_EVENT_RESPONSE_NONE);
}

result = USB_DEVICE_HID_EventHandlerSet (0, &APP_EventHandler, (uintptr_t) &appObject);

if(USB_DEVICE_HID_RESULT_OK != result)
{
    SYS_ASSERT ( false , "Error while registering event handler" );
}