123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- #ifndef BLE_BAS_H__
- #define BLE_BAS_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "ble.h"
- #include "ble_srv_common.h"
- #include "nrf_sdh_ble.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define BLE_BAS_DEF(_name) \
- static ble_bas_t _name; \
- NRF_SDH_BLE_OBSERVER(_name ## _obs, \
- BLE_BAS_BLE_OBSERVER_PRIO, \
- ble_bas_on_ble_evt, \
- &_name)
- typedef enum
- {
- BLE_BAS_EVT_NOTIFICATION_ENABLED,
- BLE_BAS_EVT_NOTIFICATION_DISABLED
- } ble_bas_evt_type_t;
- typedef struct
- {
- ble_bas_evt_type_t evt_type;
- uint16_t conn_handle;
- } ble_bas_evt_t;
- typedef struct ble_bas_s ble_bas_t;
- typedef void (* ble_bas_evt_handler_t) (ble_bas_t * p_bas, ble_bas_evt_t * p_evt);
- typedef struct
- {
- ble_bas_evt_handler_t evt_handler;
- bool support_notification;
- ble_srv_report_ref_t * p_report_ref;
- uint8_t initial_batt_level;
- security_req_t bl_rd_sec;
- security_req_t bl_cccd_wr_sec;
- security_req_t bl_report_rd_sec;
- } ble_bas_init_t;
- struct ble_bas_s
- {
- ble_bas_evt_handler_t evt_handler;
- uint16_t service_handle;
- ble_gatts_char_handles_t battery_level_handles;
- uint16_t report_ref_handle;
- uint8_t battery_level_last;
- bool is_notification_supported;
- };
- ret_code_t ble_bas_init(ble_bas_t * p_bas, const ble_bas_init_t * p_bas_init);
- void ble_bas_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context);
- ret_code_t ble_bas_battery_level_update(ble_bas_t * p_bas,
- uint8_t battery_level,
- uint16_t conn_handle);
- ret_code_t ble_bas_battery_lvl_on_reconnection_update(ble_bas_t * p_bas,
- uint16_t conn_handle);
- #ifdef __cplusplus
- }
- #endif
- #endif
|