ble_rms.h 3.11 KB
#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__