This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

what does the function "evt_handler()" do and the definition be?

Hi! I am studying some program code of BLE examples. I have a doubt about what does the evt_handler() do. E.g. in the example "ble_app_hrs_s130_pca10028"

static void on_hrm_cccd_write(ble_hrs_t * p_hrs, ble_gatts_evt_write_t * p_evt_write)
{...p_hrs->evt_handler(p_hrs, &evt); .. }

in the example "ble_app_rscs_s130_pca10028

static void on_meas_cccd_write(ble_rscs_t * p_rscs, ble_gatts_evt_write_t * p_evt_write)
{...p_rscs->evt_handler(p_rscs, &evt);...}

I can just find the typedef struct about it, such as:

typedef void(* 	ble_hrs_evt_handler_t )(ble_hrs_t *p_hrs, ble_hrs_evt_t *p_evt)

But I can not unstandard what does the evt_handler() do from the the typedef. Could anybody give me some explain about it or tell me where can find the more detail definition about the function "evt_handler()"? Thank you for your reply and help!

Parents
  • The event handler is given to the service upon init, and stored in a struct of type ble_hrs_t. Looking into what fields ble_hrs_t contains, you'll see one of them is a evt_handler of type ble_hrs_evt_handler_t. This means that the function you give this struct as the event handler needs to be of void type, and take two arguments, one of type ble_hrs_t* and one with ble_gatts_ect_write_t*.

Reply
  • The event handler is given to the service upon init, and stored in a struct of type ble_hrs_t. Looking into what fields ble_hrs_t contains, you'll see one of them is a evt_handler of type ble_hrs_evt_handler_t. This means that the function you give this struct as the event handler needs to be of void type, and take two arguments, one of type ble_hrs_t* and one with ble_gatts_ect_write_t*.

Children
Related