HID library
Posted: 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:
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.
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();