HID library

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

HID library

Postby chegewara » Thu Jan 04, 2018 7:41 pm

Hi.
Recently we have introduced HID class in mr Neil's Kolban BLE library. To be more accurate its HID over GATT. Its not extensively tested yet, but i was able to simulate on my windows laptop bluetooth devices such as: mouse, keyboard, gamepad and joystick.

HID class is designed to create all mandatory services and characteristics during HID object instantate, this include hid info and battery service. This way programmer which will use this library can use it like interface between esp32 and hid driver on laptop or android device.

In this example we can see minimal code required to make it works:

Code: Select all

    BLEHIDDevice* hid;
    hid = new BLEHIDDevice(pServer);

    BLECharacteristic* input = hid->inputReport(1); // <-- input REPORTID from report map
    std::string name = "chegewara";   // <-- OPTIONAL
    hid->manufacturer()->setValue(name);  // <-- OPTIONAL

    hid->pnp(0x01, 0xe502, 0xa111, 0x0210);  // <-- example pnp values
    hid->hidInfo(0x00,0x01);  
    
    
    const uint8_t report[] = {

0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
0x09, 0x02,        // Usage (Mouse)
0xA1, 0x01,        // Collection (Application)
0x85, 0x01,        //   Report ID (1)
0x09, 0x01,        //   Usage (Pointer)
0xA1, 0x00,        //   Collection (Physical)
0x05, 0x09,        //     Usage Page (Button)
0x19, 0x01,        //     Usage Minimum (0x01)
0x29, 0x03,        //     Usage Maximum (0x03)
0x25, 0x01,        //     Logical Maximum (1)
0x75, 0x01,        //     Report Size (1)
0x95, 0x03,        //     Report Count (3)
0x81, 0x02,        //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x75, 0x05,        //     Report Size (5)
0x95, 0x01,        //     Report Count (1)
0x81, 0x01,        //     Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x01,        //     Usage Page (Generic Desktop Ctrls)
0x09, 0x30,        //     Usage (X)
0x26, 0x05,0x56,        //     Logical Maximum (127)
0x09, 0x31,        //     Usage (Y)
0x26, 0x03,0x00,        //     Logical Maximum (127)
0x09, 0x38,        //     Usage (Wheel)
0x15, 0x00,        //     Logical Minimum (-127)
0x25, 0x7f,        //     Logical Maximum (127)
0x75, 0x08,        //     Report Size (8)
0x95, 0x03,        //     Report Count (3)
0x81, 0x02,        //     Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
0xC0,              //   End Collection
0xC0,              // End Collection

// 52 bytes
    };

    hid->reportMap((uint8_t*)report, sizeof(report));
    hid->startServices();

In this example report map is very unique, because it suppose to be mouse and is recognized as a mouse, but its prepared to use joystick from ordinary gamepad. When joystick is idle then cursor is also idle in middle of screen. This way cursor will follow joysticks move. With very small changes it will behave like normal mouse.

arturolimon
Posts: 2
Joined: Fri Mar 16, 2018 3:23 am

Re: HID library

Postby arturolimon » Fri Mar 16, 2018 3:43 am

Hi,

First of all thanks for sharing the HID library!

I'm working on an IMU-based mouse using the ESP32 and an MPU-9150. Everything seems to be working good so far except for one thing:

I'm having trouble sending negative values for the X and Y coordinates. I see the mouse moving in the positive directions (right and down) but no movement at all in the negative directions.

I'm using pretty much the exact same report map as the example in the HID Device Class Definition document:

Code: Select all

   0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
    0x09, 0x02,        // Usage (Mouse)
    0xA1, 0x01,        // Collection (Application)
    0x85, 0x01,        //   Report ID (1)
    0x09, 0x01,        //   Usage (Pointer)
    0xA1, 0x00,        //   Collection (Physical)
    0x05, 0x09,        //     Usage Page (Button)
      0x19, 0x01,        //     Usage Minimum (0x01)
      0x29, 0x03,        //     Usage Maximum (0x03)
      0x15, 0x00,        //     Logical Minimum (0)
      0x25, 0x01,        //     Logical Maximum (1)
      0x95, 0x03,        //     Report Count (3)
      0x75, 0x01,        //     Report Size (1)
      0x81, 0x02,        //     Input (Data,Var,Abs) 3bit button
      0x95, 0x01,        //     Report Count (1)
      0x75, 0x05,        //     Report Size (5)
      0x81, 0x01,        //     Input (Const,Array,Abs) 5 bits padding
    0x05, 0x01,        //     Usage Page (Generic Desktop Ctrls)
      0x09, 0x30,        //     Usage (X)
      0x09, 0x31,        //     Usage (Y)
      0x09, 0x38,        //     Usage (WHEEL)
      0x15, 0x81,        //     Logical Minimum (-127)
      0x25, 0x7f,        //     Logical Maximum (127)
      0x75, 0x08,        //     Report Size (8)
      0x95, 0x03,        //     Report Count (3)
      0x81, 0x06,        //     Input (Data,Var,Rel) 3 bytes (x,y,wheel)
    0xC0,              //   End Collection
    0xC0,              // End Collection
From the notify logs I can confirm I'm sending negative values. I feel like I'm terribly missing something.

Any ideas?

arturolimon
Posts: 2
Joined: Fri Mar 16, 2018 3:23 am

Re: HID library

Postby arturolimon » Mon Mar 19, 2018 12:12 am

UPDATE: Not sure why but I'm now able to move the mouse in every direction by increasing the size of the logical minimum/logical maximum report entry to two bytes:

Code: Select all

const uint8_t REPORT_MAP[] = {
    0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
    0x09, 0x02,        // Usage (Mouse)
    0xA1, 0x01,        // Collection (Application)
    0x85, 0x01,        //   Report ID (1)
    0x09, 0x01,        //   Usage (Pointer)
    0xA1, 0x00,        //   Collection (Physical)
    0x05, 0x09,        //     Usage Page (Button)
      0x19, 0x01,        //     Usage Minimum (0x01)
      0x29, 0x03,        //     Usage Maximum (0x03)
      0x15, 0x00,        //     Logical Minimum (0)
      0x25, 0x01,        //     Logical Maximum (1)
      0x95, 0x03,        //     Report Count (3)
      0x75, 0x01,        //     Report Size (1)
      0x81, 0x02,        //     Input (Data,Var) 3bits button
      0x95, 0x01,        //     Report Count (1)
      0x75, 0x05,        //     Report Size (5)
      0x81, 0x01,        //     Input (Const,Array) 5 bits padding
    0x05, 0x01,        //     Usage Page (Generic Desktop Ctrls)
      0x09, 0x30,        //     Usage (X)
      0x09, 0x31,        //     Usage (Y)
      0x09, 0x38,        //     Usage (WHEEL)
      0x16, 0x81, 0xff,  //     Logical Minimum (-127)
      0x26, 0x7f, 0x00,  //     Logical Maximum (127)
      0x75, 0x08,        //     Report Size (8)
      0x95, 0x03,        //     Report Count (3)
      0x81, 0x06,        //     Input (Data,Var,Rel) 3 bytes (x,y,wheel)
    0xC0,              //   End Collection
    0xC0,              // End Collection
};


grantb
Posts: 9
Joined: Thu Oct 18, 2018 9:51 pm

Re: HID library

Postby grantb » Tue Oct 23, 2018 9:17 pm

What OS version of WIndows supports this? I tried the Espressif demo and it worked on my phone but none of my PCs.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: HID library

Postby chegewara » Wed Oct 24, 2018 9:05 am

Windows 10 tested. Espressif hid demo is having issue with windows, it shows driver error, but i have no time to see what is causing it (most likely report map).

Who is online

Users browsing this forum: No registered users and 192 guests