This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Modify HID descriptor

I am trying to send 'h' or the number 1 using vendor defined page (custom HID descriptor). How do I do it?

NOTE: I have worked with hid mouse & keyboard examples and also successfully tried a few modifications.

I am unable to customize the descriptor. Please help!

Parents
  • I assume you want to write a value to one of the report characteristics. In the HID Mouse Application, the creation of these characteristics is already taken care of (and they support notification). 

    In order to notify a value to one of these characteristics, the SVCALL sd_ble_gatts_hvx(...) needs to be called.

    This function have two inputs:

    • conn_handle: A handle to the current connection, which will be assigned after connected
    • p_hvx_params: This is a struct that contains all the information when notifying an attribute value, for more information check out this link

    I modified the HID Mouse Application to write a value of 1 to the report characteristic for button movement, and the function below is called when button 4 is pressed.

    static void send_awesome_message(){
        NRF_LOG_INFO("sending awesome message");
    
        ble_gatts_hvx_params_t hvx_params;
        uint16_t               hvx_length = 1;
        uint32_t err_code;
        uint8_t my_data = 1;
    
        hvx_params.handle = m_hids.inp_rep_array[INPUT_REP_MOVEMENT_INDEX].char_handles.value_handle;
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset = 0;
        hvx_params.p_len  = &hvx_length;
        hvx_params.p_data = &my_data;
    
    
        err_code = sd_ble_gatts_hvx(m_conn_handle, &hvx_params);
        if ((err_code == NRF_SUCCESS) && (*hvx_params.p_len != INPUT_REP_MOVEMENT_LEN))
        {
            err_code = NRF_ERROR_DATA_SIZE;
        }
    }

    p_hvx_params fields:

    • Handle: Characteristic Value Handle that belongs to the report characteristics for button movement
    • Type: Used BLE_GATT_HVX_NOTIFICATION for notification
    • Offset: The offset within the attribute value is zero
    • Length: Length is 1 byte
    • Data: The data to be sent is 1

    I have provided the code down below:

    ble_app_hids_mouse_modified.zip

    In order to receive the notifications, you must remember to enable it from the client (e.g. phone or computer).

    Best regards, Simon

Reply
  • I assume you want to write a value to one of the report characteristics. In the HID Mouse Application, the creation of these characteristics is already taken care of (and they support notification). 

    In order to notify a value to one of these characteristics, the SVCALL sd_ble_gatts_hvx(...) needs to be called.

    This function have two inputs:

    • conn_handle: A handle to the current connection, which will be assigned after connected
    • p_hvx_params: This is a struct that contains all the information when notifying an attribute value, for more information check out this link

    I modified the HID Mouse Application to write a value of 1 to the report characteristic for button movement, and the function below is called when button 4 is pressed.

    static void send_awesome_message(){
        NRF_LOG_INFO("sending awesome message");
    
        ble_gatts_hvx_params_t hvx_params;
        uint16_t               hvx_length = 1;
        uint32_t err_code;
        uint8_t my_data = 1;
    
        hvx_params.handle = m_hids.inp_rep_array[INPUT_REP_MOVEMENT_INDEX].char_handles.value_handle;
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset = 0;
        hvx_params.p_len  = &hvx_length;
        hvx_params.p_data = &my_data;
    
    
        err_code = sd_ble_gatts_hvx(m_conn_handle, &hvx_params);
        if ((err_code == NRF_SUCCESS) && (*hvx_params.p_len != INPUT_REP_MOVEMENT_LEN))
        {
            err_code = NRF_ERROR_DATA_SIZE;
        }
    }

    p_hvx_params fields:

    • Handle: Characteristic Value Handle that belongs to the report characteristics for button movement
    • Type: Used BLE_GATT_HVX_NOTIFICATION for notification
    • Offset: The offset within the attribute value is zero
    • Length: Length is 1 byte
    • Data: The data to be sent is 1

    I have provided the code down below:

    ble_app_hids_mouse_modified.zip

    In order to receive the notifications, you must remember to enable it from the client (e.g. phone or computer).

    Best regards, Simon

Children
No Data
Related