From 45569c346defc77d864a4ca3a0746e4563c6e9f1 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 22 Jun 2023 11:43:49 +0200 Subject: [PATCH] gatt-service/hids_device: provide hids_device_send_input_report_for_id --- src/ble/gatt-service/hids_device.c | 19 +++++++++++++------ src/ble/gatt-service/hids_device.h | 13 ++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/ble/gatt-service/hids_device.c b/src/ble/gatt-service/hids_device.c index a382bf441..178b4281d 100644 --- a/src/ble/gatt-service/hids_device.c +++ b/src/ble/gatt-service/hids_device.c @@ -113,6 +113,17 @@ static hids_device_report_t * hids_device_get_report_for_client_configuration_ha return NULL; } +static hids_device_report_t * hids_device_get_report_for_type_and_id(hids_device_t * device, hid_report_type_t type, uint16_t report_id){ + uint8_t pos; + uint8_t total_reports = device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num; + for (pos = 0 ; pos < total_reports ; pos++){ + if ((device->hid_reports[pos].type == type) && (device->hid_reports[pos].id == report_id)){ + return &device->hid_reports[pos]; + } + } + return NULL; +} + static hids_device_report_t * hids_device_get_report_for_id(hids_device_t * device, uint16_t report_id){ uint8_t pos; uint8_t total_reports = device->hid_input_reports_num + device->hid_output_reports_num + device->hid_feature_reports_num; @@ -422,18 +433,14 @@ void hids_device_request_can_send_now_event(hci_con_handle_t con_handle){ att_server_register_can_send_now_callback(&instance->battery_callback, con_handle); } -/** - * @brief Send HID Report: Input - */ - -uint8_t hids_device_send_report_with_id(hci_con_handle_t con_handle, uint16_t report_id, const uint8_t * report, uint16_t report_len){ +uint8_t hids_device_send_input_report_for_id(hci_con_handle_t con_handle, uint16_t report_id, const uint8_t * report, uint16_t report_len){ hids_device_t * instance = hids_device_get_instance_for_con_handle(con_handle); if (!instance){ log_error("no instance for handle 0x%02x", con_handle); return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } - hids_device_report_t * report_storage = hids_device_get_report_for_id(instance, report_id); + hids_device_report_t * report_storage = hids_device_get_report_for_type_and_id(instance, HID_REPORT_TYPE_INPUT, report_id); if (report_storage == NULL){ return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; } diff --git a/src/ble/gatt-service/hids_device.h b/src/ble/gatt-service/hids_device.h index df687abb3..d6e1f5e95 100644 --- a/src/ble/gatt-service/hids_device.h +++ b/src/ble/gatt-service/hids_device.h @@ -93,12 +93,19 @@ void hids_device_register_packet_handler(btstack_packet_handler_t callback); void hids_device_request_can_send_now_event(hci_con_handle_t con_handle); /** - * @brief Send HID Report with given ID + * @brief Send HID Input Report for Report ID + * @param con_handle + * @param report_id + * @param report + * @param report_len */ -uint8_t hids_device_send_report_with_id(hci_con_handle_t con_handle, uint16_t report_id, const uint8_t * report, uint16_t report_len); +uint8_t hids_device_send_input_report_for_id(hci_con_handle_t con_handle, uint16_t report_id, const uint8_t * report, uint16_t report_len); /** - * @brief Send HID Report: Input + * @brief Send HID Input Report for first Input Report + * @param con_handle + * @param report + * @param report_len */ void hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len);