/* This file was generated by plugin 'Nordic Semiconductor nRF5x v.1.2.2' (BDS version 1.1.3135.0) */

#include "service_if.h"
#include <stdint.h>
#include "app_trace.h" 
#include "ble_button_test_service.h" 

static ble_button_test_service_t    m_button_test_service; 



/**@brief Function for handling the Button test service events.
 *
 * @details This function will be called for all Button test service events which are passed to
 *          the application.
 *
 * @param[in]   p_button_test_service   Button test service structure.
 * @param[in]   p_evt   Event received from the Button test service.
 */
static void on_button_test_service_evt(ble_button_test_service_t * p_button_test_service, ble_button_test_service_evt_t * p_evt)
{
    switch (p_evt->evt_type)
    { 
        case BLE_BUTTON_TEST_SERVICE_BUTTON_TEST_SERVICE_NEW_CHARACTERISTIC_EVT_WRITE:
            app_trace_log("[Bluetooth_IF]: BUTTON_TEST_SERVICE_BUTTON_TEST_SERVICE_NEW_CHARACTERISTIC evt WRITE. \r\n");
            break; 
        default:
            // No implementation needed.
            break;
    }
}


/**@brief Function for initializing the Services generated by Bluetooth Developer Studio.
 *
 *
 * @return      NRF_SUCCESS on successful initialization of services, otherwise an error code.
 */
uint32_t bluetooth_init(void)
{
    uint32_t    err_code; 
    ble_button_test_service_init_t    button_test_service_init; 
    

    // Initialize Button test service.
    memset(&button_test_service_init, 0, sizeof(button_test_service_init));

    button_test_service_init.evt_handler = on_button_test_service_evt; 
    memset(&button_test_service_init.ble_button_test_service_button_test_service_new_characteristic_initial_value.button_field,
           0x00,
           sizeof(button_test_service_init.ble_button_test_service_button_test_service_new_characteristic_initial_value.button_field));

    err_code = ble_button_test_service_init(&m_button_test_service, &button_test_service_init);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    } 

    return NRF_SUCCESS;
}

/**@brief Function for handling the Application's BLE Stack events.
 *
 * @details Handles all events from the BLE stack of interest to all Bluetooth Developer Studio generated Services.
 *
 * @param[in]   p_ble_evt  Event received from the BLE stack.
 */
void bluetooth_on_ble_evt(ble_evt_t * p_ble_evt)
{ 
    ble_button_test_service_on_ble_evt(&m_button_test_service, p_ble_evt); 
}
