mirror of https://github.com/zmkfirmware/zmk.git
refactor(ble): add functions to check if profile is open/connected by address (#2993)
Helper functions for BLE profile statuses.
This commit is contained in:
parent
cef7af4408
commit
fe91cc6625
|
|
@ -33,6 +33,9 @@ bt_addr_le_t *zmk_ble_profile_address(uint8_t index);
|
||||||
bt_addr_le_t *zmk_ble_active_profile_addr(void);
|
bt_addr_le_t *zmk_ble_active_profile_addr(void);
|
||||||
struct bt_conn *zmk_ble_active_profile_conn(void);
|
struct bt_conn *zmk_ble_active_profile_conn(void);
|
||||||
|
|
||||||
|
bool zmk_ble_profile_is_connected(uint8_t index);
|
||||||
|
bool zmk_ble_profile_is_open(uint8_t index);
|
||||||
|
|
||||||
bool zmk_ble_active_profile_is_open(void);
|
bool zmk_ble_active_profile_is_open(void);
|
||||||
bool zmk_ble_active_profile_is_connected(void);
|
bool zmk_ble_active_profile_is_connected(void);
|
||||||
char *zmk_ble_active_profile_name(void);
|
char *zmk_ble_active_profile_name(void);
|
||||||
|
|
|
||||||
|
|
@ -95,8 +95,13 @@ static void raise_profile_changed_event_callback(struct k_work *work) {
|
||||||
|
|
||||||
K_WORK_DEFINE(raise_profile_changed_event_work, raise_profile_changed_event_callback);
|
K_WORK_DEFINE(raise_profile_changed_event_work, raise_profile_changed_event_callback);
|
||||||
|
|
||||||
bool zmk_ble_active_profile_is_open(void) {
|
bool zmk_ble_active_profile_is_open(void) { return zmk_ble_profile_is_open(active_profile); }
|
||||||
return !bt_addr_le_cmp(&profiles[active_profile].peer, BT_ADDR_LE_ANY);
|
|
||||||
|
bool zmk_ble_profile_is_open(uint8_t index) {
|
||||||
|
if (index >= ZMK_BLE_PROFILE_COUNT) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !bt_addr_le_cmp(&profiles[index].peer, BT_ADDR_LE_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_profile_address(uint8_t index, const bt_addr_le_t *addr) {
|
void set_profile_address(uint8_t index, const bt_addr_le_t *addr) {
|
||||||
|
|
@ -115,9 +120,16 @@ void set_profile_address(uint8_t index, const bt_addr_le_t *addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zmk_ble_active_profile_is_connected(void) {
|
bool zmk_ble_active_profile_is_connected(void) {
|
||||||
|
return zmk_ble_profile_is_connected(active_profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool zmk_ble_profile_is_connected(uint8_t index) {
|
||||||
|
if (index >= ZMK_BLE_PROFILE_COUNT) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
struct bt_conn_info info;
|
struct bt_conn_info info;
|
||||||
bt_addr_le_t *addr = zmk_ble_active_profile_addr();
|
bt_addr_le_t *addr = &profiles[index].peer;
|
||||||
if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) {
|
if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) {
|
||||||
return false;
|
return false;
|
||||||
} else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {
|
} else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue