My class:
Code: Select all
class BLEClass {
public:
BLEClass(ISettings *settings) : settings(settings){}
void initialize(void)
{
esp_err_t ret;
ret = nvs_flash_init();
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
ret = esp_bluedroid_init();
ret = esp_bluedroid_enable();
ret = esp_ble_gatts_register_callback(gatts_event_handler);
ret = esp_ble_gap_register_callback(gap_event_handler);
ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500);
return;
}
Code: Select all
/**
* @brief GAP callback function type
* @param event : Event type
* @param param : Point to callback parameter, currently is union type
*/
typedef void (* esp_gap_ble_cb_t)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
/**
* @brief This function is called to occur gap event, such as scan result
*
* @param[in] callback: callback function
*
* @return
* - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback);