forked from NordicPlayground/nRF52-ble-app-lbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathble_lbs.h
100 lines (87 loc) · 3.73 KB
/
ble_lbs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
/** @file
*
* @brief LED Button Service module.
*
* @details This module implements the LED Button Service with the LED and Button characteristics.
* During initialization it adds the LED Button Service and LED and Button characteristics
* to the BLE stack database.
*
* The module will support notification of the Button characteristic
* through the ble_lbs_on_button_change() function.
* If an event handler is supplied by the application, the LED Button Service will
* generate LED characteristic events to the application.
*
* @note The application must propagate BLE stack events to the BLE Button Service module by calling
* ble_lbs_on_ble_evt() from the @ref softdevice_handler callback.
*
* @note Attention!
* To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
* qualification listings, this section of source code must not be modified.
*/
#ifndef BLE_LBS_H__
#define BLE_LBS_H__
#include <stdint.h>
#include "ble.h"
#include "ble_srv_common.h"
#define LBS_UUID_BASE {0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}
#define LBS_UUID_SERVICE 0x1523
#define LBS_UUID_LED_CHAR 0x1525
#define LBS_UUID_BUTTON_CHAR 0x1524
// Forward declaration of the ble_lbs_t type.
typedef struct ble_lbs_s ble_lbs_t;
/**@brief LED Button Service event handler type. */
typedef void (*ble_lbs_led_write_handler_t) (ble_lbs_t * p_lbs, uint8_t new_state);
/**@brief LED Button Service init structure. */
typedef struct
{
ble_lbs_led_write_handler_t led_write_handler; /**< Called when the LED characteristic is written to. */
} ble_lbs_init_t;
/**@brief LED Button Service structure. This contains various status information for the service. */
struct ble_lbs_s
{
uint16_t service_handle;
ble_gatts_char_handles_t led_char_handles;
ble_gatts_char_handles_t button_char_handles;
uint8_t uuid_type;
uint16_t conn_handle;
ble_lbs_led_write_handler_t led_write_handler;
};
/**@brief Function for initializing the LED Button Service.
*
* @param[out] p_lbs LED Button Service structure. This structure will have to be supplied by
* the application. It will be initialized by this function, and will later
* be used to identify this particular service instance.
* @param[in] p_lbs_init Information needed to initialize the service.
*
* @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
*/
uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init);
/**@brief Function for handling the Application's BLE Stack events.
*
* @details Handles all events from the BLE stack of interest to the LED Button Service.
*
* @param[in] p_lbs LED Button Service structure.
* @param[in] p_ble_evt Event received from the BLE stack.
*/
void ble_lbs_on_ble_evt(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt);
/**@brief Function for sending a button state notification.
*
* @param[in] p_lbs LED Button Service structure.
* @param[in] button_state New button state.
*
* @retval NRF_SUCCESS If the notification was sent successfully. Otherwise, an error code is returned.
*/
uint32_t ble_lbs_on_button_change(ble_lbs_t * p_lbs, uint8_t button_state);
#endif // BLE_LBS_H__
/** @} */