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

How to Create an HID mouse application using nRF52DK board and few extra buttons?

Hi,

I have gone through the "ble_app_hids_mouse" example program. So far the program seems to work great, but how do we take control of the buttons since the function used only translates button press to mouse x-y translations. Please hep. Later i would try using a joystick to control the mouse movements and two buttons to control mouse left and right button functionality.

But before that i need to get through the basics first. Please help me get this stuff working.

Disappointed

Parents
  • Hi,

    This post here shows you how to add this functionality. 

    The function updated to SDK 15 looks like this:

    static void mouse_click_send(uint8_t x, uint8_t y, uint8_t z) 
    { 
        uint32_t err_code; uint8_t buffer[3]; 
        if (m_in_boot_mode) return; 
    
        buffer[0] = x; // Left button (bit 0) pressed
        buffer[1] = y; // Scroll value (-127, 128)
        buffer[2] = z; // Sideways scroll value (-127, 128)
    
        err_code = ble_hids_inp_rep_send(&m_hids,INPUT_REP_BUTTONS_INDEX, INPUT_REP_BUTTONS_LEN, buffer,m_conn_handle);
        if ((err_code != NRF_SUCCESS) &&
            (err_code != NRF_ERROR_INVALID_STATE) &&
            (err_code != NRF_ERROR_RESOURCES) &&
            (err_code != NRF_ERROR_BUSY) &&
            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
           )
        {
                        APP_ERROR_CHECK(err_code);
        }
    }

    Here is the list of values:

    0x00 - No buttons pressed
    
    0x01 - Left button pressed
    
    0x02 - Right button pressed
    
    0x03 - Both left and right button pressed

    To make a left click you call mouse_click_send(1,0,0); don't forget to release the key press by calling: mouse_click_send(0,0,0);

    You can test this on with button 4 (BSP_KEY_3) in bsp_event_handler() function like this:

    case BSP_EVENT_KEY_3:
    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
    {
    //mouse_movement_send(0, MOVEMENT_SPEED);
    mouse_click_send(1,0,0); //Click
    mouse_click_send(0,0,0); //Release
    }

Reply
  • Hi,

    This post here shows you how to add this functionality. 

    The function updated to SDK 15 looks like this:

    static void mouse_click_send(uint8_t x, uint8_t y, uint8_t z) 
    { 
        uint32_t err_code; uint8_t buffer[3]; 
        if (m_in_boot_mode) return; 
    
        buffer[0] = x; // Left button (bit 0) pressed
        buffer[1] = y; // Scroll value (-127, 128)
        buffer[2] = z; // Sideways scroll value (-127, 128)
    
        err_code = ble_hids_inp_rep_send(&m_hids,INPUT_REP_BUTTONS_INDEX, INPUT_REP_BUTTONS_LEN, buffer,m_conn_handle);
        if ((err_code != NRF_SUCCESS) &&
            (err_code != NRF_ERROR_INVALID_STATE) &&
            (err_code != NRF_ERROR_RESOURCES) &&
            (err_code != NRF_ERROR_BUSY) &&
            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
           )
        {
                        APP_ERROR_CHECK(err_code);
        }
    }

    Here is the list of values:

    0x00 - No buttons pressed
    
    0x01 - Left button pressed
    
    0x02 - Right button pressed
    
    0x03 - Both left and right button pressed

    To make a left click you call mouse_click_send(1,0,0); don't forget to release the key press by calling: mouse_click_send(0,0,0);

    You can test this on with button 4 (BSP_KEY_3) in bsp_event_handler() function like this:

    case BSP_EVENT_KEY_3:
    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
    {
    //mouse_movement_send(0, MOVEMENT_SPEED);
    mouse_click_send(1,0,0); //Click
    mouse_click_send(0,0,0); //Release
    }

Children
No Data
Related