nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
bas_client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef __BAS_C_H
8#define __BAS_C_H
9
17#include <zephyr/kernel.h>
18#include <sys/types.h>
19#include <zephyr/bluetooth/gatt.h>
20#include <zephyr/bluetooth/conn.h>
21#include <zephyr/bluetooth/uuid.h>
22#include <bluetooth/gatt_dm.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
37#define BT_BAS_VAL_INVALID (255)
38
44#define BT_BAS_VAL_MAX (100)
45
46struct bt_bas_client;
47
60typedef void (*bt_bas_notify_cb)(struct bt_bas_client *bas,
61 uint8_t battery_level);
62
72typedef void (*bt_bas_read_cb)(struct bt_bas_client *bas,
73 uint8_t battery_level,
74 int err);
75
76/* @brief Battery Service Client characteristic periodic read. */
79 struct k_work_delayable read_work;
81 struct bt_gatt_read_params params;
83 atomic_t interval;
84};
85
89 struct bt_conn *conn;
91 struct bt_gatt_subscribe_params notify_params;
93 struct bt_gatt_read_params read_params;
103 uint16_t val_handle;
105 uint16_t ccc_handle;
109 uint8_t properties;
111 bool notify;
112};
113
123
141int bt_bas_handles_assign(struct bt_gatt_dm *dm,
142 struct bt_bas_client *bas);
143
156 bt_bas_notify_cb func);
157
167
175struct bt_conn *bt_bas_conn(const struct bt_bas_client *bas);
176
177
190
203
212static inline bool bt_bas_notify_supported(struct bt_bas_client *bas)
213{
214 return bas->notify;
215}
216
229 int32_t interval,
230 bt_bas_notify_cb func);
231
238
239#ifdef __cplusplus
240}
241#endif
242
248#endif /* __BAS_C_H */
void bt_bas_stop_per_read_battery_level(struct bt_bas_client *bas)
Stop periodic reading of the battery value from the device.
int bt_bas_start_per_read_battery_level(struct bt_bas_client *bas, int32_t interval, bt_bas_notify_cb func)
Periodically read the battery level value from the device with specific time interval.
int bt_bas_get_last_battery_level(struct bt_bas_client *bas)
Get the last known battery level.
int bt_bas_handles_assign(struct bt_gatt_dm *dm, struct bt_bas_client *bas)
Assign handles to the BAS Client instance.
int bt_bas_subscribe_battery_level(struct bt_bas_client *bas, bt_bas_notify_cb func)
Subscribe to the battery level value change notification.
struct bt_conn * bt_bas_conn(const struct bt_bas_client *bas)
Get the connection object that is used with a given BAS Client.
void bt_bas_client_init(struct bt_bas_client *bas)
Initialize the BAS Client instance.
int bt_bas_read_battery_level(struct bt_bas_client *bas, bt_bas_read_cb func)
Read the battery level value from the device.
void(* bt_bas_read_cb)(struct bt_bas_client *bas, uint8_t battery_level, int err)
Read complete callback.
Definition: bas_client.h:72
static bool bt_bas_notify_supported(struct bt_bas_client *bas)
Check whether notification is supported by the service.
Definition: bas_client.h:212
void(* bt_bas_notify_cb)(struct bt_bas_client *bas, uint8_t battery_level)
Value notification callback.
Definition: bas_client.h:60
int bt_bas_unsubscribe_battery_level(struct bt_bas_client *bas)
Remove the subscription.
struct bt_conn * conn
Definition: bas_client.h:89
uint16_t val_handle
Definition: bas_client.h:103
struct bt_gatt_read_params read_params
Definition: bas_client.h:93
uint8_t battery_level
Definition: bas_client.h:107
bt_bas_notify_cb notify_cb
Definition: bas_client.h:99
struct bt_bas_periodic_read periodic_read
Definition: bas_client.h:97
struct bt_gatt_subscribe_params notify_params
Definition: bas_client.h:91
bool notify
Definition: bas_client.h:111
bt_bas_read_cb read_cb
Definition: bas_client.h:101
uint16_t ccc_handle
Definition: bas_client.h:105
uint8_t properties
Definition: bas_client.h:109
Battery Service Client instance.
Definition: bas_client.h:87
struct bt_gatt_read_params params
Definition: bas_client.h:81
atomic_t interval
Definition: bas_client.h:83
struct k_work_delayable read_work
Definition: bas_client.h:79
Definition: bas_client.h:77