Skip to content

Commit

Permalink
4.4.4 Handling stack events & LED characteristic writes.
Browse files Browse the repository at this point in the history
  • Loading branch information
liquitious committed Dec 20, 2015
1 parent 90a51a4 commit d458687
Show file tree
Hide file tree
Showing 5 changed files with 518 additions and 521 deletions.
50 changes: 13 additions & 37 deletions ble_lbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@

#define INVALID_BATTERY_LEVEL 255

#if 0
/**@brief Function for handling the Connect event.
*
* @param[in] p_lbs Battery Service structure.
* @param[in] p_lbs LED Button service structure.
* @param[in] p_ble_evt Event received from the BLE stack.
*/
static void on_connect(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)
Expand All @@ -38,7 +37,7 @@ static void on_connect(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)

/**@brief Function for handling the Disconnect event.
*
* @param[in] p_lbs Battery Service structure.
* @param[in] p_lbs LED Button structure.
* @param[in] p_ble_evt Event received from the BLE stack.
*/
static void on_disconnect(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)
Expand All @@ -47,59 +46,36 @@ static void on_disconnect(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)
p_lbs->conn_handle = BLE_CONN_HANDLE_INVALID;
}


/**@brief Function for handling the Write event.
*
* @param[in] p_lbs Battery Service structure.
* @param[in] p_lbs LED Button structure.
* @param[in] p_ble_evt Event received from the BLE stack.
*/
static void on_write(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)
{
if (p_lbs->is_notification_supported)
{
ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

if (
(p_evt_write->handle == p_lbs->battery_level_handles.cccd_handle)
&&
(p_evt_write->len == 2)
)
{
// CCCD written, call application event handler
if (p_lbs->evt_handler != NULL)
{
ble_lbs_evt_t evt;

if (ble_srv_is_notification_enabled(p_evt_write->data))
{
evt.evt_type = BLE_LBS_EVT_NOTIFICATION_ENABLED;
}
else
{
evt.evt_type = BLE_LBS_EVT_NOTIFICATION_DISABLED;
}

p_lbs->evt_handler(p_lbs, &evt);
}
}
}
ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

if ((p_evt_write->handle == p_lbs->led_char_handles.value_handle) && (p_evt_write->len == 1)
&& (p_lbs->led_write_handler != NULL))
{
p_lbs->led_write_handler(p_lbs, p_evt_write->data[0]);
}
}
#endif // 0

void ble_lbs_on_ble_evt(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)
{
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
//on_connect(p_lbs, p_ble_evt);
on_connect(p_lbs, p_ble_evt);
break;

case BLE_GAP_EVT_DISCONNECTED:
//on_disconnect(p_lbs, p_ble_evt);
on_disconnect(p_lbs, p_ble_evt);
break;

case BLE_GATTS_EVT_WRITE:
//on_write(p_lbs, p_ble_evt);
on_write(p_lbs, p_ble_evt);
break;

default:
Expand Down
Loading

0 comments on commit d458687

Please sign in to comment.