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

what can I do ,if I want to send left or right button data

HI

I used nrf51822- EK board.

BLE HID MOUSE - SDK 8.0

`

How to send left button or right button data?

How to modify below method?

static void mouse_click_send()
{
    uint32_t err_code;
    uint8_t buffer[3];
    if (m_in_boot_mode)
        return;    
	
	buffer[0] = 0; // Left button (bit 0) pressed
	buffer[1] = 1; // Scroll value (-127, 128)
	buffer[2] = 1; // Sideways scroll value (-127, 128)

	err_code = ble_hids_inp_rep_send(&m_hids,INPUT_REP_BUTTONS_INDEX, INPUT_REP_BUTTONS_LEN, buffer);
    if ((err_code != NRF_SUCCESS) &&
        (err_code != NRF_ERROR_INVALID_STATE) &&
        (err_code != BLE_ERROR_NO_TX_BUFFERS) &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
    )
    {
        APP_ERROR_CHECK(err_code);
    }
}

this code not repeat.

So i want always send Mouse Left button.

case BSP_EVENT_KEY_0:
mouse_click_send();
break;

please, help me

Parents
  • In hids_init() function there is a the hid report descriptor that defines the content of the hid reports. For the mouse report sent in your code this is the relevant section.

          // Report ID 1: Mouse buttons + scroll/pan
        0x85, 0x01,       //     Report Id 1
        0x09, 0x01,       //     Usage (Pointer)
        0xA1, 0x00,       //     Collection (Physical)
        0x95, 0x05,       //         Report Count (5)
        0x75, 0x01,       //         Report Size (1)
        0x05, 0x09,       //         Usage Page (Buttons)
        0x19, 0x01,       //             Usage Minimum (01)
        0x29, 0x05,       //             Usage Maximum (05)
        0x15, 0x00,       //             Logical Minimum (0)
        0x25, 0x01,       //             Logical Maximum (1)
        0x81, 0x02,       //             Input (Data, Variable, Absolute)
        0x95, 0x01,       //             Report Count (1)
        0x75, 0x03,       //             Report Size (3)
        0x81, 0x01,       //             Input (Constant) for padding
        0x75, 0x08,       //         Report Size (8)
        0x95, 0x01,       //         Report Count (1)
        0x05, 0x01,       //         Usage Page (Generic Desktop)
        0x09, 0x38,       //             Usage (Wheel)
        0x15, 0x81,       //             Logical Minimum (-127)
        0x25, 0x7F,       //             Logical Maximum (127)
        0x81, 0x06,       //             Input (Data, Variable, Relative)
        0x05, 0x0C,       //         Usage Page (Consumer)
        0x0A, 0x38, 0x02, //             Usage (AC Pan)
        0x95, 0x01,       //             Report Count (1)
        0x81, 0x06,       //             Input (Data,Value,Relative,Bit Field)
        0xC0,             //     End Collection (Physical)
    

    This might look a bit cryptic, but basically says that five first bits in the first byte corresponds to button 1 to button 5 on a standard HID mouse. Button 1 is left button, Button 2 is right button, Button 3 is center button and button 4 and 5 are typically the "back" and "forward" buttons you find on the sides of a mouse.

    Second byte is for the scrollwheel. It takes values from -127 to 127

    Third byte is for panning. Takes same valus as the scrollwhell I believe.

    To send a "right button" press you must set the second bit in the first byte to '1' before sending it. You must always send all three bytes.

    The report would then have the value {1, 0, 0} for left button. {2,0,0} for right button. {4,0,0} for center button. Both left and right would be {3,0,0}.

Reply
  • In hids_init() function there is a the hid report descriptor that defines the content of the hid reports. For the mouse report sent in your code this is the relevant section.

          // Report ID 1: Mouse buttons + scroll/pan
        0x85, 0x01,       //     Report Id 1
        0x09, 0x01,       //     Usage (Pointer)
        0xA1, 0x00,       //     Collection (Physical)
        0x95, 0x05,       //         Report Count (5)
        0x75, 0x01,       //         Report Size (1)
        0x05, 0x09,       //         Usage Page (Buttons)
        0x19, 0x01,       //             Usage Minimum (01)
        0x29, 0x05,       //             Usage Maximum (05)
        0x15, 0x00,       //             Logical Minimum (0)
        0x25, 0x01,       //             Logical Maximum (1)
        0x81, 0x02,       //             Input (Data, Variable, Absolute)
        0x95, 0x01,       //             Report Count (1)
        0x75, 0x03,       //             Report Size (3)
        0x81, 0x01,       //             Input (Constant) for padding
        0x75, 0x08,       //         Report Size (8)
        0x95, 0x01,       //         Report Count (1)
        0x05, 0x01,       //         Usage Page (Generic Desktop)
        0x09, 0x38,       //             Usage (Wheel)
        0x15, 0x81,       //             Logical Minimum (-127)
        0x25, 0x7F,       //             Logical Maximum (127)
        0x81, 0x06,       //             Input (Data, Variable, Relative)
        0x05, 0x0C,       //         Usage Page (Consumer)
        0x0A, 0x38, 0x02, //             Usage (AC Pan)
        0x95, 0x01,       //             Report Count (1)
        0x81, 0x06,       //             Input (Data,Value,Relative,Bit Field)
        0xC0,             //     End Collection (Physical)
    

    This might look a bit cryptic, but basically says that five first bits in the first byte corresponds to button 1 to button 5 on a standard HID mouse. Button 1 is left button, Button 2 is right button, Button 3 is center button and button 4 and 5 are typically the "back" and "forward" buttons you find on the sides of a mouse.

    Second byte is for the scrollwheel. It takes values from -127 to 127

    Third byte is for panning. Takes same valus as the scrollwhell I believe.

    To send a "right button" press you must set the second bit in the first byte to '1' before sending it. You must always send all three bytes.

    The report would then have the value {1, 0, 0} for left button. {2,0,0} for right button. {4,0,0} for center button. Both left and right would be {3,0,0}.

Children
Related