I’m building a device with Esp32c3 chip, that acts as a switch access on iOS and Android.
I’m extending esp_hid_device
example.
I’ve tried both nimble and bluedroid options.
Nimble
- on Android, with example configured as Gamepad, looks good – everything works.
- on iOS, MacOS – there are issues after pairing. The phone does not show “Device information” icon, “Forget device” icon, and also even after modified the hid map, device is not recognising as a gamepad
Bluedroid / ble
- on Android it is fine again – no issues so far.
- on iOS, MacOS, this time here are no issues with recognising as a gamepad, and also “Device information”, “Forget device” are available. However, button clicks are not recognised by the platform.
Can you please help my find a way of sending button press to iOS, MacOS?
Here’s my device report map,
<code>const unsigned char mediaReportMap[] = {
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x05, // Usage (Game Pad)
0xA1, 0x01, // Collection (Application)
0x85, 0x01, // Report ID (6)
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)
0x75, 0x01, // Report Size (1)
0x95, 0x10, // Report Count (16)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
};
</code>
<code>const unsigned char mediaReportMap[] = {
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x05, // Usage (Game Pad)
0xA1, 0x01, // Collection (Application)
0x85, 0x01, // Report ID (6)
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)
0x75, 0x01, // Report Size (1)
0x95, 0x10, // Report Count (16)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
};
</code>
const unsigned char mediaReportMap[] = {
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x05, // Usage (Game Pad)
0xA1, 0x01, // Collection (Application)
0x85, 0x01, // Report ID (6)
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)
0x75, 0x01, // Report Size (1)
0x95, 0x10, // Report Count (16)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
};
And the function to send data. For now I’m just sending one button.
<code>void esp_hidd_send_consumer_value(uint8_t key_cmd, bool key_pressed)
{
uint8_t buffer[1] = {0};
if (key_pressed)
{
buffer[0] = 0x81;
}
esp_err_t res = esp_hidd_dev_input_set(s_ble_hid_param.hid_dev, 0, 0x01, buffer, 1);
ESP_LOGI(TAG, "Send button result %d", res);
return;
}
</code>
<code>void esp_hidd_send_consumer_value(uint8_t key_cmd, bool key_pressed)
{
uint8_t buffer[1] = {0};
if (key_pressed)
{
buffer[0] = 0x81;
}
esp_err_t res = esp_hidd_dev_input_set(s_ble_hid_param.hid_dev, 0, 0x01, buffer, 1);
ESP_LOGI(TAG, "Send button result %d", res);
return;
}
</code>
void esp_hidd_send_consumer_value(uint8_t key_cmd, bool key_pressed)
{
uint8_t buffer[1] = {0};
if (key_pressed)
{
buffer[0] = 0x81;
}
esp_err_t res = esp_hidd_dev_input_set(s_ble_hid_param.hid_dev, 0, 0x01, buffer, 1);
ESP_LOGI(TAG, "Send button result %d", res);
return;
}
New contributor
Alexey Kuropiantnyk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.