ESP32 BLE HID Composite Device

rupin.chheda
Posts: 2
Joined: Sat May 04, 2019 10:46 am

ESP32 BLE HID Composite Device

Postby rupin.chheda » Sat May 04, 2019 10:55 am

Hello,
I have used starting code from issue #632 on the ESP32 Snippets Repo and based on suggestions there, I have managed to achieve quite a bit in my application. I searched through the issues list(both open and closed) but I could not find this or a similar issue reported. I have already reported the issue, have got a response, but that did not solve the problem for me, so I am trying my luck here. :lol: :lol:

What I am trying to get to is to build a ESP Composite Device ( over GATT), which consists of Two Independent Joysticks at least. These are to support two players.

Based on https://eleccelerator.com/tutorial-abou ... scriptors/, it is possible to create two independent joysticks using two reports.It is also possible that the report map may have a mouse and a keyboard and it will show up additional devices. But the site description is generic, and mostly talks about a USB cable based wired connection versus a BLE HID connection.

I have my code for perusal here https://github.com/rupin/ESPJoystick/bl ... ble632.ino

You will notice I have two reports in my code

Code: Select all

const uint8_t reportMap[] = {
  0x05, 0x01,  // USAGE_PAGE (Generic Desktop)
  0x09, 0x04,  // USAGE (Game Pad)
  0xa1, 0x01,  // COLLECTION (Application)

  0x85, 0x01,  //     REPORT_ID (1)
  0x05, 0x09,  //     USAGE_PAGE (Button)
  0x19, 0x01,  //     USAGE_MINIMUM (Button 1)
  0x29, 0x10,  //     USAGE_MAXIMUM (Button 16)
  0x15, 0x00,  //     LOGICAL_MINIMUM (0)
  0x25, 0x01,  //     LOGICAL_MAXIMUM (1)
  0x95, 0x08,  //     REPORT_COUNT (8)
  0x75, 0x02,  //     REPORT_SIZE (2)
  0x81, 0x02,  //     INPUT (Data,Var,Abs)
  //0xa1, 0x00,  //     COLLECTION (Physical)
  0x05, 0x01,  //       USAGE_PAGE (Generic Desktop)
  0x09, 0x30,  //       USAGE (X)
  0x09, 0x31,  //       USAGE (Y)
  0x15, 0x00,  //       LOGICAL_MINIMUM (0)
  0x25, 0xFF,  //       LOGICAL_MAXIMUM (100)
  0x75, 0x08,  //       REPORT_SIZE (8)
  0x95, 0x02,  //       REPORT_COUNT (2)
  0x81, 0x02,  //       INPUT (Data,Var,Abs)
  // 0xc0,        //     END_COLLECTION

  0xc0,         // END_COLLECTION

  0x05, 0x01,  // USAGE_PAGE (Generic Desktop)
  0x09, 0x04,  // USAGE (Game Pad)
  0xa1, 0x01,  // COLLECTION (Application)

  0x85, 0x02,  //     REPORT_ID (2)
  0x05, 0x09,  //     USAGE_PAGE (Button)
  0x19, 0x01,  //     USAGE_MINIMUM (Button 1)
  0x29, 0x10,  //     USAGE_MAXIMUM (Button 16)
  0x15, 0x00,  //     LOGICAL_MINIMUM (0)
  0x25, 0x01,  //     LOGICAL_MAXIMUM (1)
  0x95, 0x08,  //     REPORT_COUNT (8)
  0x75, 0x02,  //     REPORT_SIZE (2)
  0x81, 0x02,  //     INPUT (Data,Var,Abs)
  //0xa1, 0x00,  //     COLLECTION (Physical)
  0x05, 0x01,  //       USAGE_PAGE (Generic Desktop)
  0x09, 0x33,  //       USAGE (X)
  0x09, 0x34,  //       USAGE (Y)
  0x15, 0x00,  //       LOGICAL_MINIMUM (0)
  0x25, 0xFF,  //       LOGICAL_MAXIMUM (100)
  0x75, 0x08,  //       REPORT_SIZE (8)
  0x95, 0x02,  //       REPORT_COUNT (2)
  0x81, 0x02,  //       INPUT (Data,Var,Abs)
  // 0xc0,        //     END_COLLECTION

  0xc0         // END_COLLECTION


};
Now, the reportMap has two reports numbered 1 and 2.

I am sending the data independently using two individual report notifications.

Code: Select all

uint8_t a[] = {lButtonState, 0x00, X_Joystick, Y_Joystick};
device1->setValue(a, sizeof(a));
device1->notify();

uint8_t b[] = {0x00, lButtonState, X_Joystick, Y_Joystick};
device2->setValue(b, sizeof(b));
device2->notify();
I expected two joysticks to be visible on Android, but I see one only. Button presses and axis changes are all mapped to one single joystick.

What am I doing wrong?


Reponse from chegewara ( i tried this but it still shows up as a single joystick)

Try removing second USAGE_PAGE or even all 3:

Code: Select all

0x05, 0x01,  // USAGE_PAGE (Generic Desktop)
  0x09, 0x04,  // USAGE (Game Pad)
  0xa1, 0x01,  // COLLECTION (Application)

Who is online

Users browsing this forum: No registered users and 64 guests