From 5da25471bbc0759d302868245c23db786ca0c382 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:04:14 +0000 Subject: [PATCH] feat(split): Add is_bonded function There is already a function to see if the peripheral is connected, a matching one for if it's bonded is a useful addition for displays/indicators. `is_bonded` gets reset to false in the advertising function in preparation for runtime peripheral bond clearing --- app/include/zmk/split/bluetooth/peripheral.h | 4 +++- app/src/split/bluetooth/peripheral.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/include/zmk/split/bluetooth/peripheral.h b/app/include/zmk/split/bluetooth/peripheral.h index a650508ad53..44ac8062a51 100644 --- a/app/include/zmk/split/bluetooth/peripheral.h +++ b/app/include/zmk/split/bluetooth/peripheral.h @@ -6,4 +6,6 @@ #pragma once -bool zmk_split_bt_peripheral_is_connected(void); \ No newline at end of file +bool zmk_split_bt_peripheral_is_connected(void); + +bool zmk_split_bt_peripheral_is_bonded(void); \ No newline at end of file diff --git a/app/src/split/bluetooth/peripheral.c b/app/src/split/bluetooth/peripheral.c index 1d649f71221..79da78eec8d 100644 --- a/app/src/split/bluetooth/peripheral.c +++ b/app/src/split/bluetooth/peripheral.c @@ -43,6 +43,8 @@ static const struct bt_data zmk_ble_ad[] = { static bool is_connected = false; +static bool is_bonded = false; + static void each_bond(const struct bt_bond_info *info, void *user_data) { bt_addr_le_t *addr = (bt_addr_le_t *)user_data; @@ -57,10 +59,12 @@ static int start_advertising(bool low_duty) { bt_foreach_bond(BT_ID_DEFAULT, each_bond, ¢ral_addr); if (bt_addr_le_cmp(¢ral_addr, BT_ADDR_LE_NONE) != 0) { + is_bonded = true; struct bt_le_adv_param adv_param = low_duty ? *BT_LE_ADV_CONN_DIR_LOW_DUTY(¢ral_addr) : *BT_LE_ADV_CONN_DIR(¢ral_addr); return bt_le_adv_start(&adv_param, NULL, 0, NULL, 0); } else { + is_bonded = false; return bt_le_adv_start(BT_LE_ADV_CONN, zmk_ble_ad, ARRAY_SIZE(zmk_ble_ad), NULL, 0); } }; @@ -134,6 +138,8 @@ static struct bt_conn_cb conn_callbacks = { bool zmk_split_bt_peripheral_is_connected() { return is_connected; } +bool zmk_split_bt_peripheral_is_bonded() { return is_bonded; } + static int zmk_peripheral_ble_init(const struct device *_arg) { int err = bt_enable(NULL);