Skip to content

Commit

Permalink
bluetooth: services: report id in input report notification callback
Browse files Browse the repository at this point in the history
Add report identifier to input report notification callback.
The old callback format is kept for backwards compatibility.

Signed-off-by: Pawel Dunaj <[email protected]>
  • Loading branch information
pdunaj committed Jan 8, 2025
1 parent 659c4a3 commit 4e7b2c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
16 changes: 15 additions & 1 deletion include/bluetooth/services/hids.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
};


Expand Down
17 changes: 11 additions & 6 deletions subsys/bluetooth/services/hids.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 4e7b2c1

Please sign in to comment.