ble_ths.h
2.98 KB
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
#ifndef BLE_THS_H__
#define BLE_THS_H__
#include <stdint.h>
#include <stdbool.h>
#include "ble.h"
#include "ble_srv_common.h"
#define BLE_THS_DEF(_name) \
static ble_ths_t _name; \
NRF_SDH_BLE_OBSERVER(_name ## _obs, \
BLE_HRS_BLE_OBSERVER_PRIO, \
ble_ths_on_ble_evt, &_name)
#define TH_CUSTOM_SERVICE_UUID_BASE {0x59, 0x46, 0x8c, 0x62, 0xf9, 0x8d, 0x4d, 0x13, \
0xa8, 0x7c, 0x52, 0xdd, 0x18, 0xa1, 0xff, 0xf7}
#define TH_CUSTOM_SERVICE_UUID 0x1200
#define TH_CUSTOM_TEMP_CHAR_UUID 0x1201
#define TH_CUSTOM_HUMD_CHAR_UUID 0x1202
typedef enum
{
BLE_THS_EVT_NOTIFICATION_ENABLED, /**< Custom value notification enabled event. */
BLE_THS_EVT_NOTIFICATION_DISABLED, /**< Custom value notification disabled event. */
BLE_THS_EVT_DISCONNECTED,
BLE_THS_EVT_CONNECTED
} ble_ths_evt_type_t;
typedef struct
{
ble_ths_evt_type_t evt_type; /**< Type of event. */
} ble_ths_evt_t;
typedef struct ble_ths_s ble_ths_t;
typedef void (*ble_ths_evt_handler_t) (ble_ths_t * p_bas, ble_ths_evt_t * p_evt);
typedef struct
{
ble_ths_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Custom Service. */
uint8_t initial_custom_value; /**< Initial custom value */
ble_srv_cccd_security_mode_t custom_value_char_attr_md; /**< Initial security level for Custom characteristics attribute */
} ble_ths_init_t;
struct ble_ths_s
{
ble_ths_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Custom Service. */
uint16_t service_handle; /**< Handle of Custom Service (as provided by the BLE stack). */
ble_gatts_char_handles_t temp_value_handles; /**< Handles related to the Custom Value characteristic. */
ble_gatts_char_handles_t humd_value_handles;
uint16_t conn_handle; /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
uint8_t uuid_type;
};
uint32_t ble_ths_init(ble_ths_t * p_cus, const ble_ths_init_t * p_ths_init);
void ble_ths_on_ble_evt( ble_evt_t const * p_ble_evt, void * p_context);
uint32_t ble_ths_temp_value_update(ble_ths_t * p_ths, uint8_t custom_value);
uint32_t ble_ths_humd_value_update(ble_ths_t * p_ths, uint8_t custom_value);
#endif // BLE_THS_H__