ble_rms.h
3.11 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
#ifndef BLE_RMS_H__
#define BLE_RMS_H__
#include <stdint.h>
#include <stdbool.h>
#include "ble.h"
#include "ble_srv_common.h"
#define BLE_RMS_DEF(_name) \
static ble_rms_t _name; \
NRF_SDH_BLE_OBSERVER(_name ## _obs, \
BLE_HRS_BLE_OBSERVER_PRIO, \
ble_rms_on_ble_evt, &_name)
#define RM_CUSTOM_SERVICE_UUID_BASE {0x61, 0x04, 0xa5, 0xa1, 0x3a, 0x51, 0x08, 0xaa, \
0xeb, 0x46, 0xf3, 0xfc, 0x53, 0xcf, 0x12, 0xf3}
#define RM_CUSTOM_SERVICE_UUID 0x2100
#define RM_R_VALUE_CHAR_UUID 0x2101
#define RM_G_VALUE_CHAR_UUID 0x2102
#define RM_B_VALUE_CHAR_UUID 0x2103
typedef enum
{
BLE_RMS_EVT_NOTIFICATION_ENABLED, /**< Custom value notification enabled event. */
BLE_RMS_EVT_NOTIFICATION_DISABLED, /**< Custom value notification disabled event. */
BLE_RMS_EVT_DISCONNECTED,
BLE_RMS_EVT_CONNECTED
} ble_rms_evt_type_t;
typedef struct
{
ble_rms_evt_type_t evt_type; /**< Type of event. */
} ble_rms_evt_t;
typedef struct ble_rms_s ble_rms_t;
typedef void (*ble_rms_evt_handler_t) (ble_rms_t * p_bas, ble_rms_evt_t * p_evt);
typedef struct
{
ble_rms_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_rms_init_t;
struct ble_rms_s
{
ble_rms_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 r_value_handles; /**< Handles related to the Custom Value characteristic. */
ble_gatts_char_handles_t g_value_handles;
ble_gatts_char_handles_t b_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_rms_init(ble_rms_t * p_rms, const ble_rms_init_t * p_rms_init);
void ble_rms_on_ble_evt( ble_evt_t const * p_ble_evt, void * p_context);
uint32_t ble_rms_r_value_update(ble_rms_t * p_rms, uint8_t custom_value);
uint32_t ble_rms_g_value_update(ble_rms_t * p_rms, uint8_t custom_value);
uint32_t ble_rms_b_value_update(ble_rms_t * p_rms, uint8_t custom_value);
#endif // BLE_RMS_H__