2016-09-27 09:38:07 -04:00
|
|
|
/**
|
|
|
|
****************************************************************************************
|
|
|
|
*
|
|
|
|
* @file button_pro.c
|
|
|
|
*
|
|
|
|
* @brief Application entry point
|
|
|
|
*
|
|
|
|
* Copyright (C) Espressif 2016
|
|
|
|
* Created by Yulong at 2016/8/18
|
|
|
|
*
|
|
|
|
*
|
|
|
|
****************************************************************************************
|
2016-09-26 09:37:39 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
#include "bt_target.h"
|
|
|
|
#include "bt_trace.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#include "bt_types.h"
|
2016-09-27 09:38:07 -04:00
|
|
|
#include "gatt_api.h"
|
|
|
|
#include "bta_api.h"
|
|
|
|
#include "bta_gatt_api.h"
|
|
|
|
#include "bta_gatts_int.h"
|
|
|
|
#include "button_pro.h"
|
|
|
|
|
2016-10-11 05:43:36 -04:00
|
|
|
#include "prf_defs.h"
|
|
|
|
|
|
|
|
#if (BUT_PROFILE_CFG)
|
|
|
|
|
|
|
|
|
2016-09-27 09:38:07 -04:00
|
|
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
button_env_cb_t button_cb_env;
|
2016-09-27 09:38:07 -04:00
|
|
|
|
2016-10-28 01:54:42 -04:00
|
|
|
tBLE_BD_ADDR p_peer_bda = {
|
|
|
|
.type = API_PUBLIC_ADDR,
|
|
|
|
.bda = {0}
|
|
|
|
};
|
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_adv_params_all_t adv_params =
|
2016-10-28 01:54:42 -04:00
|
|
|
{
|
|
|
|
.adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100,
|
|
|
|
.adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100,
|
|
|
|
.adv_type = API_NON_DISCOVERABLE,
|
|
|
|
.addr_type_own = API_PUBLIC_ADDR,
|
2016-11-02 02:05:30 -04:00
|
|
|
.channel_map = ESP_BLE_ADV_CHNL_MAP,
|
2016-10-28 01:54:42 -04:00
|
|
|
.adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY,
|
|
|
|
.p_dir_bda = &p_peer_bda
|
|
|
|
};
|
|
|
|
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** Constants
|
|
|
|
*****************************************************************************/
|
2016-11-02 02:05:30 -04:00
|
|
|
static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data);
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function button_profile_cb
|
|
|
|
**
|
|
|
|
** Description the callback function after the profile has been register to the BTA manager module
|
|
|
|
**
|
|
|
|
** Returns NULL
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-02 02:05:30 -04:00
|
|
|
static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
|
2016-09-27 09:38:07 -04:00
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_gatts_rsp_t rsp;
|
|
|
|
esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}};
|
|
|
|
but_inst_t *p_inst = &button_cb_env.button_inst;
|
|
|
|
uint8_t net_event = 0xff;
|
|
|
|
uint8_t len = 0;
|
|
|
|
uint8_t *p_rec_data = NULL;
|
2016-09-26 09:37:39 -04:00
|
|
|
//LOG_ERROR("p_data->status = %x\n",p_data->status);
|
2016-09-27 09:38:07 -04:00
|
|
|
//if(p_data->status != BTA_GATT_OK){
|
|
|
|
// LOG_ERROR("button profile register failed\n");
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
LOG_ERROR("button profile cb event = %x\n",event);
|
|
|
|
switch(event)
|
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_REG_EVT:
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
LOG_ERROR("p_data->reg_oper.status = %x\n",p_data->reg_oper.status);
|
|
|
|
LOG_ERROR("(p_data->reg_oper.uuid.uu.uuid16=%x\n",p_data->reg_oper.uuid.uu.uuid16);
|
|
|
|
if(p_data->reg_oper.status != BTA_GATT_OK)
|
|
|
|
{
|
|
|
|
LOG_ERROR("button profile register failed\n");
|
|
|
|
}
|
2016-09-27 09:38:07 -04:00
|
|
|
button_cb_env.gatt_if = p_data->reg_oper.server_if;
|
|
|
|
button_cb_env.enabled = true;
|
|
|
|
//button_cb_env.button_inst.app_id = p_data->reg_oper.uuid;
|
|
|
|
//create the button service to the service data base.
|
2016-09-26 09:37:39 -04:00
|
|
|
if(p_data->reg_oper.uuid.uu.uuid16 == ATT_SVC_BUTTON)
|
|
|
|
{
|
|
|
|
Button_CreateService();
|
2016-09-27 09:38:07 -04:00
|
|
|
}
|
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_READ_EVT:
|
2016-09-26 09:37:39 -04:00
|
|
|
//tBTA_GATTS_RSP rsp;
|
|
|
|
memset(&rsp,0,sizeof(tBTA_GATTS_API_RSP));
|
|
|
|
rsp.attr_value.handle = p_data->req_data.p_data->read_req.handle;
|
|
|
|
rsp.attr_value.len = 2;
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id,
|
2016-09-26 09:37:39 -04:00
|
|
|
p_data->req_data.status,&rsp);
|
2016-09-27 09:38:07 -04:00
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_WRITE_EVT:
|
|
|
|
esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id,
|
2016-09-27 09:38:07 -04:00
|
|
|
p_data->req_data.status,NULL);
|
2016-10-11 05:43:36 -04:00
|
|
|
LOG_ERROR("Received button data:");
|
|
|
|
for(int i = 0; i < p_data->req_data.p_data->write_req.len; i++){
|
|
|
|
LOG_ERROR("%x",p_data->req_data.p_data->write_req.value[i]);
|
|
|
|
}
|
|
|
|
LOG_ERROR("\n");
|
|
|
|
if(p_data->req_data.p_data->write_req.handle == button_cb_env.button_inst.but_wirt_hdl){
|
|
|
|
if(p_data->req_data.p_data->write_req.value[0] == 0xFF){
|
|
|
|
net_event = RECEIVE_NET_PASSWD_EVT;
|
|
|
|
len = p_data->req_data.p_data->write_req.len - 1;
|
|
|
|
p_rec_data = &p_data->req_data.p_data->write_req.value[1];
|
|
|
|
LOG_ERROR("RECEIVE_NET_PASSWD_EVT\n");
|
|
|
|
}else if(p_data->req_data.p_data->write_req.value[0] == 0xEE){
|
|
|
|
|
|
|
|
net_event = RECEIVE_NET_SSD_EVT;
|
|
|
|
len = p_data->req_data.p_data->write_req.len - 1;
|
|
|
|
p_rec_data = &p_data->req_data.p_data->write_req.value[1];
|
|
|
|
LOG_ERROR("RECEIVE_NET_SSD_EVT\n");
|
|
|
|
}else{
|
|
|
|
net_event = 0xff;
|
|
|
|
len = p_data->req_data.p_data->write_req.len;
|
|
|
|
p_rec_data = p_data->req_data.p_data->write_req.value;
|
|
|
|
|
|
|
|
}
|
|
|
|
// button_msg_notify(len,p_rec_data);
|
|
|
|
(*p_inst->p_cback)(button_cb_env.button_inst.app_id,net_event,len,p_rec_data);
|
|
|
|
}
|
2016-09-27 09:38:07 -04:00
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_CFM_EVT:
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_CREATE_EVT:
|
2016-09-26 09:37:39 -04:00
|
|
|
//tBT_UUID uuid_butt_write;
|
2016-09-27 09:38:07 -04:00
|
|
|
uuid.uu.uuid16 = ATT_CHAR_BUTTON_WIT;
|
|
|
|
//tBTA_GATT_PERM perm = (GATT_PERM_WRITE|GATT_PERM_READ);
|
|
|
|
//tBTA_GATT_CHAR_PROP prop = (GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_WRITE);
|
2016-11-02 02:05:30 -04:00
|
|
|
//uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}};
|
2016-09-27 09:38:07 -04:00
|
|
|
button_cb_env.clcb.cur_srvc_id= p_data->create.service_id;
|
|
|
|
button_cb_env.is_primery = p_data->create.is_primary;
|
2016-09-26 09:37:39 -04:00
|
|
|
//uuid = {LEN_UUID_16, {ATT_CHAR_BUTTON_WIT}};
|
|
|
|
//start the button service after created
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_start_srvc(p_data->create.service_id);
|
2016-09-27 09:38:07 -04:00
|
|
|
//add the frist button characteristic --> write characteristic
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_add_char(button_cb_env.clcb.cur_srvc_id,&uuid,
|
2016-09-26 09:37:39 -04:00
|
|
|
(GATT_PERM_WRITE|GATT_PERM_READ),
|
2016-09-27 09:38:07 -04:00
|
|
|
(GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_WRITE));
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_ADD_CHAR_EVT:
|
2016-09-27 09:38:07 -04:00
|
|
|
if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_BUTTON_WIT)
|
|
|
|
{
|
|
|
|
uuid.uu.uuid16 = ATT_CHAR_BUTTON_NTF;
|
|
|
|
//tBTA_GATT_PERM perm = GATT_PERM_READ;
|
|
|
|
tBTA_GATT_CHAR_PROP prop = (GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_NOTIFY);
|
|
|
|
//save the att handle to the env
|
|
|
|
button_cb_env.button_inst.but_wirt_hdl = p_data->add_result.attr_id;
|
|
|
|
//add the frist button characteristic --> Notify characteristic
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_add_char(button_cb_env.clcb.cur_srvc_id,&uuid,
|
2016-09-27 09:38:07 -04:00
|
|
|
GATT_PERM_READ,(GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_NOTIFY));
|
|
|
|
}else if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_BUTTON_NTF){ // add the gattc config descriptor to the notify charateristic
|
|
|
|
//tBTA_GATT_PERM perm = (GATT_PERM_WRITE|GATT_PERM_WRITE);
|
|
|
|
uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG;
|
|
|
|
button_cb_env.button_inst.but_ntf_hdl = p_data->add_result.attr_id;
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_add_char_descr (button_cb_env.clcb.cur_srvc_id,
|
2016-09-26 09:37:39 -04:00
|
|
|
(GATT_PERM_WRITE|GATT_PERM_WRITE),
|
2016-09-27 09:38:07 -04:00
|
|
|
&uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_ADD_CHAR_DESCR_EVT:
|
2016-09-27 09:38:07 -04:00
|
|
|
if(p_data->add_result.char_uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG)
|
|
|
|
{
|
|
|
|
button_cb_env.button_inst.but_cfg_hdl = p_data->add_result.attr_id;
|
|
|
|
}
|
2016-10-28 01:54:42 -04:00
|
|
|
///Start advertising
|
2016-11-04 02:34:52 -04:00
|
|
|
LOG_ERROR("\n*******Start sent the ADV.*************\n");
|
|
|
|
//esp_ble_start_advertising (&adv_params);
|
|
|
|
BTA_GATTS_Listen(button_cb_env.gatt_if, true, NULL);
|
2016-09-27 09:38:07 -04:00
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_CONNECT_EVT:
|
2016-09-27 09:38:07 -04:00
|
|
|
//set the connection flag to true
|
|
|
|
button_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda);
|
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_DISCONNECT_EVT:
|
2016-09-27 09:38:07 -04:00
|
|
|
//set the connection flag to true
|
|
|
|
button_cb_env.clcb.connected = false;
|
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_OPEN_EVT:
|
2016-10-26 08:19:48 -04:00
|
|
|
///stop the advertising after connected
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_stop_advertising();
|
2016-09-27 09:38:07 -04:00
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_CLOSE_EVT:
|
2016-09-27 09:38:07 -04:00
|
|
|
if(button_cb_env.clcb.connected && (button_cb_env.clcb.conn_id == p_data->conn.conn_id))
|
|
|
|
{
|
|
|
|
//set the connection channal congested flag to true
|
|
|
|
button_cb_env.clcb.congest = p_data->congest.congested;
|
|
|
|
}
|
|
|
|
break;
|
2016-11-02 02:05:30 -04:00
|
|
|
case ESP_GATTS_CONGEST_EVT:
|
2016-09-27 09:38:07 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function Button_CreateService
|
|
|
|
**
|
|
|
|
** Description Create a Service for the button profile
|
|
|
|
**
|
|
|
|
** Returns NULL
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void Button_CreateService(void)
|
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_gatts_if_t server_if ;
|
|
|
|
esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}};
|
|
|
|
uint16_t num_handle = KEY_IDX_NB;
|
|
|
|
uint8_t inst = 0x00;
|
2016-09-26 09:37:39 -04:00
|
|
|
server_if = button_cb_env.gatt_if;
|
|
|
|
button_cb_env.inst_id = inst;
|
|
|
|
//if(!button_cb_env.enabled)
|
|
|
|
//{
|
|
|
|
// LOG_ERROR("button service added error.");
|
|
|
|
//}
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_create_srvc(server_if,&uuid,inst,num_handle,true);
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function button_env_clcb_alloc
|
|
|
|
**
|
|
|
|
** Description The function allocates a GATT profile connection link control block
|
|
|
|
**
|
|
|
|
** Returns NULL if not found. Otherwise pointer to the connection link block.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-02 02:05:30 -04:00
|
|
|
but_clcb_t *button_env_clcb_alloc (uint16_t conn_id, BD_ADDR remote_bda)
|
2016-09-27 09:38:07 -04:00
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
but_clcb_t *p_clcb = NULL;
|
2016-09-27 09:38:07 -04:00
|
|
|
p_clcb = &button_cb_env.clcb;
|
|
|
|
|
|
|
|
if(!p_clcb->in_use)
|
|
|
|
{
|
|
|
|
p_clcb->in_use = TRUE;
|
|
|
|
p_clcb->conn_id = conn_id;
|
|
|
|
LOG_ERROR("p_clcb->conn_id = %x\n",conn_id);
|
|
|
|
p_clcb->connected = TRUE;
|
|
|
|
memcpy(p_clcb->remote_bda,remote_bda,BD_ADDR_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return p_clcb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function button_env_find_conn_id_by_bd_adddr
|
|
|
|
**
|
|
|
|
** Description The function searches all LCB with macthing bd address
|
|
|
|
**
|
|
|
|
** Returns total number of clcb found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-02 02:05:30 -04:00
|
|
|
uint16_t button_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda)
|
2016-09-27 09:38:07 -04:00
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
uint8_t i_clcb;
|
|
|
|
but_clcb_t *p_clcb = NULL;
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < BUTT_MAX_APPS; i_clcb++, p_clcb++)
|
|
|
|
{
|
|
|
|
if(p_clcb->in_use && p_clcb->connected &&memcmp(p_clcb->remote_bda,remote_bda,BD_ADDR_LEN))
|
|
|
|
{
|
|
|
|
return p_clcb->conn_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GATT_INVALID_CONN_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function button_env_clcb_dealloc
|
|
|
|
**
|
|
|
|
** Description The function deallocates a GATT profile connection link control block
|
|
|
|
**
|
|
|
|
** Returns True the deallocation is successful
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-10-18 05:22:36 -04:00
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
BOOLEAN button_env_clcb_dealloc(uint16_t conn_id)
|
2016-09-27 09:38:07 -04:00
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
uint16_t i_clcb = 0;
|
|
|
|
but_clcb_t *p_clcb = NULL;
|
2016-09-27 09:38:07 -04:00
|
|
|
|
2016-10-18 05:22:36 -04:00
|
|
|
for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < 1; i_clcb++, p_clcb++)
|
2016-09-27 09:38:07 -04:00
|
|
|
{
|
|
|
|
if(p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id))
|
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
memset(p_clcb, 0, sizeof(but_clcb_t));
|
2016-09-27 09:38:07 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2016-10-18 05:22:36 -04:00
|
|
|
}
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function button_init
|
|
|
|
**
|
|
|
|
** Description Initializa the GATT Service for button profiles.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_gatt_status_t button_init (but_prf_cb_t call_back)
|
2016-09-27 09:38:07 -04:00
|
|
|
{
|
|
|
|
tBT_UUID app_uuid = {LEN_UUID_16,{ATT_SVC_BUTTON}};
|
2016-10-11 05:43:36 -04:00
|
|
|
|
2016-11-04 02:34:52 -04:00
|
|
|
LOG_ERROR("\n=============================button_init==============================================\n");
|
2016-09-27 09:38:07 -04:00
|
|
|
if(button_cb_env.enabled)
|
|
|
|
{
|
2016-11-04 02:34:52 -04:00
|
|
|
LOG_ERROR("button svc already initaliezd\n");
|
|
|
|
return ESP_GATT_ERROR;
|
2016-09-27 09:38:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
memset(&button_cb_env,0,sizeof(button_env_cb_t));
|
2016-09-27 09:38:07 -04:00
|
|
|
}
|
|
|
|
|
2016-10-11 05:43:36 -04:00
|
|
|
|
|
|
|
if(call_back != NULL)
|
|
|
|
{
|
|
|
|
button_cb_env.button_inst.p_cback = call_back;
|
|
|
|
}
|
|
|
|
|
2016-09-27 09:38:07 -04:00
|
|
|
|
2016-10-15 05:46:10 -04:00
|
|
|
/* register the button profile to the BTA_GATTS module*/
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_app_register(&app_uuid,button_profile_cb);
|
2016-09-27 09:38:07 -04:00
|
|
|
|
|
|
|
button_cb_env.enabled = TRUE;
|
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
return ESP_GATT_OK;
|
2016-09-27 09:38:07 -04:00
|
|
|
}
|
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
void button_disable(uint16_t connid)
|
2016-10-18 05:22:36 -04:00
|
|
|
{
|
|
|
|
button_env_clcb_dealloc(connid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
void button_msg_notify(uint16_t len, uint8_t *button_msg)
|
2016-09-27 09:38:07 -04:00
|
|
|
{
|
|
|
|
BOOLEAN conn_status = button_cb_env.clcb.connected;
|
2016-11-02 02:05:30 -04:00
|
|
|
uint16_t conn_id = button_cb_env.clcb.conn_id;
|
|
|
|
uint16_t attr_id = button_cb_env.button_inst.but_ntf_hdl;
|
2016-09-27 09:38:07 -04:00
|
|
|
//notify rsp==false; indicate rsp==true.
|
|
|
|
BOOLEAN rsp = false;
|
|
|
|
if(!conn_status && button_cb_env.clcb.congest)
|
|
|
|
{
|
2016-11-02 02:05:30 -04:00
|
|
|
LOG_ERROR("the conneciton for button profile has been loss\n");
|
2016-09-27 09:38:07 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 02:05:30 -04:00
|
|
|
esp_ble_gatts_hdl_val_indica (conn_id, attr_id, len,
|
2016-09-27 09:38:07 -04:00
|
|
|
button_msg, rsp);
|
|
|
|
}
|
2016-10-11 05:43:36 -04:00
|
|
|
|
|
|
|
#endif ///BUT_PROFILE_CFG
|