diff --git a/CMakeLists.txt b/CMakeLists.txt index 8482dec..cc7bf5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ target_sources(app PRIVATE src/mode_policy_module.c src/time_sync_module.c src/settings_module.c + src/swift_pair_module.c src/ui/ui_main.c src/ui/ui_settings.c src/ui/ui_settings_controller.c diff --git a/Kconfig b/Kconfig index e7454e1..5e8aaa8 100644 --- a/Kconfig +++ b/Kconfig @@ -4,16 +4,14 @@ source "Kconfig.zephyr" menu "Application" -config BLINKY_BLE_BOND_MULTI - bool "Blinky BLE multi-slot bond support" +config BLINKY_BLE_BOND_MULTI_INTERNAL + bool depends on BT_BONDABLE depends on BT_SETTINGS depends on CAF_SETTINGS_LOADER depends on CAF_BLE_COMMON_EVENTS select CAF_BLE_BOND_SUPPORTED default y - help - Enable the application-specific Bluetooth LE multi-slot bond module. endmenu diff --git a/prj.conf b/prj.conf index 843c0a7..d4024a8 100644 --- a/prj.conf +++ b/prj.conf @@ -117,6 +117,7 @@ CONFIG_BT_ADV_PROV_FLAGS=y CONFIG_BT_ADV_PROV_GAP_APPEARANCE=y CONFIG_BT_ADV_PROV_DEVICE_NAME=y CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=y +CONFIG_BT_ADV_PROV_SWIFT_PAIR=y # LVGL CONFIG_LVGL=y diff --git a/src/swift_pair_module.c b/src/swift_pair_module.c new file mode 100644 index 0000000..00efa80 --- /dev/null +++ b/src/swift_pair_module.c @@ -0,0 +1,58 @@ +#include + +#define MODULE swift_pair_module +#include + +#include + +#include "ble_bond_multi_event.h" + +LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF); + +static void update_swift_pair_payload(uint8_t selected_identity) +{ + bool enable = (selected_identity != BLE_BOND_MULTI_DONGLE_SLOT_ID); + + bt_le_adv_prov_swift_pair_enable(enable); + LOG_INF("Swift Pair payload %s for identity %u", + enable ? "enabled" : "disabled", selected_identity); +} + +static bool handle_ble_bond_multi_event(const struct ble_bond_multi_event *event) +{ + update_swift_pair_payload(event->active_identity_id); + return false; +} + +static bool handle_ble_peer_operation_event(const struct ble_peer_operation_event *event) +{ + switch (event->op) { + case PEER_OPERATION_SELECTED: + case PEER_OPERATION_ERASED: + update_swift_pair_payload(event->bt_stack_id); + break; + + default: + break; + } + + return false; +} + +static bool app_event_handler(const struct app_event_header *aeh) +{ + if (is_ble_bond_multi_event(aeh)) { + return handle_ble_bond_multi_event(cast_ble_bond_multi_event(aeh)); + } + + if (is_ble_peer_operation_event(aeh)) { + return handle_ble_peer_operation_event( + cast_ble_peer_operation_event(aeh)); + } + + return false; +} + +APP_EVENT_LISTENER(MODULE, app_event_handler); +APP_EVENT_SUBSCRIBE(MODULE, ble_bond_multi_event); +APP_EVENT_SUBSCRIBE_EARLY(MODULE, ble_peer_operation_event);