diff --git a/include/bluetooth/services/hids.h b/include/bluetooth/services/hids.h index 7a893d324f5d..7d3de3fbbba1 100644 --- a/include/bluetooth/services/hids.h +++ b/include/bluetooth/services/hids.h @@ -170,6 +170,13 @@ struct bt_hids_rep { */ typedef void (*bt_hids_notify_handler_t) (enum bt_hids_notify_evt evt); +/** @brief HID notification event handler, with report identification. + * + * @param report_id Report ID defined in the HIDS Report Map. + * @param evt Notification event. + */ +typedef void (*bt_hids_notify_ext_handler_t) (uint8_t report_id, enum bt_hids_notify_evt evt); + /** @brief HID Report event handler. * * @param rep Pointer to the report descriptor. @@ -228,8 +235,15 @@ struct bt_hids_inp_rep { */ const uint8_t *rep_mask; - /** Callback with the notification event. */ + /** Callback with the notification event. + * Used if set and extended callback is not set. + */ bt_hids_notify_handler_t handler; + + /** Extended callback with the notification event. + * Has preference over the normal callback. + */ + bt_hids_notify_ext_handler_t handler_ext; }; diff --git a/subsys/bluetooth/services/hids.c b/subsys/bluetooth/services/hids.c index b12c6fcd3394..0e5f47b2ad5b 100644 --- a/subsys/bluetooth/services/hids.c +++ b/subsys/bluetooth/services/hids.c @@ -477,16 +477,21 @@ static void hids_input_report_ccc_changed(struct bt_gatt_attr const *attr, CONTAINER_OF((struct _bt_gatt_ccc *)attr->user_data, struct bt_hids_inp_rep, ccc); + uint8_t report_id = inp_rep->id; + enum bt_hids_notify_evt evt; + if (value == BT_GATT_CCC_NOTIFY) { LOG_DBG("Notification has been turned on"); - if (inp_rep->handler != NULL) { - inp_rep->handler(BT_HIDS_CCCD_EVT_NOTIFY_ENABLED); - } + evt = BT_HIDS_CCCD_EVT_NOTIFY_ENABLED; } else { LOG_DBG("Notification has been turned off"); - if (inp_rep->handler != NULL) { - inp_rep->handler(BT_HIDS_CCCD_EVT_NOTIFY_DISABLED); - } + evt = BT_HIDS_CCCD_EVT_NOTIFY_DISABLED; + } + + if (inp_rep->handler_ext != NULL) { + inp_rep->handler_ext(report_id, evt); + } else if (inp_rep->handler != NULL) { + inp_rep->handler(evt); } }