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:
snoyer 2025-07-19 14:51:53 +01:00 committed by GitHub
parent cef7af4408
commit fe91cc6625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -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);
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_connected(void);
char *zmk_ble_active_profile_name(void);

View File

@ -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);
bool zmk_ble_active_profile_is_open(void) {
return !bt_addr_le_cmp(&profiles[active_profile].peer, BT_ADDR_LE_ANY);
bool zmk_ble_active_profile_is_open(void) { return zmk_ble_profile_is_open(active_profile); }
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) {
@ -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) {
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_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)) {
return false;
} else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {