feat(ble): 添加 Swift Pair 模块支持
- 在 CMakeLists.txt 中添加 swift_pair_module.c 源文件 - 将 BLINKY_BLE_BOND_MULTI 配置项重命名为 BLINKY_BLE_BOND_MULTI_INTERNAL 并移除帮助文本 - 在 prj.conf 中启用 CONFIG_BT_ADV_PROV_SWIFT_PAIR 配置选项 - 新增 swift_pair_module.c 实现 Swift Pair 功能,包括: - 监听蓝牙配对多设备事件和蓝牙对等操作事件 - 根据选中的身份标识控制 Swift Pair 载荷的启用/禁用 - 当设备被选中或擦除时更新 Swift Pair 状态
This commit is contained in:
@@ -37,6 +37,7 @@ target_sources(app PRIVATE
|
|||||||
src/mode_policy_module.c
|
src/mode_policy_module.c
|
||||||
src/time_sync_module.c
|
src/time_sync_module.c
|
||||||
src/settings_module.c
|
src/settings_module.c
|
||||||
|
src/swift_pair_module.c
|
||||||
src/ui/ui_main.c
|
src/ui/ui_main.c
|
||||||
src/ui/ui_settings.c
|
src/ui/ui_settings.c
|
||||||
src/ui/ui_settings_controller.c
|
src/ui/ui_settings_controller.c
|
||||||
|
|||||||
6
Kconfig
6
Kconfig
@@ -4,16 +4,14 @@ source "Kconfig.zephyr"
|
|||||||
|
|
||||||
menu "Application"
|
menu "Application"
|
||||||
|
|
||||||
config BLINKY_BLE_BOND_MULTI
|
config BLINKY_BLE_BOND_MULTI_INTERNAL
|
||||||
bool "Blinky BLE multi-slot bond support"
|
bool
|
||||||
depends on BT_BONDABLE
|
depends on BT_BONDABLE
|
||||||
depends on BT_SETTINGS
|
depends on BT_SETTINGS
|
||||||
depends on CAF_SETTINGS_LOADER
|
depends on CAF_SETTINGS_LOADER
|
||||||
depends on CAF_BLE_COMMON_EVENTS
|
depends on CAF_BLE_COMMON_EVENTS
|
||||||
select CAF_BLE_BOND_SUPPORTED
|
select CAF_BLE_BOND_SUPPORTED
|
||||||
default y
|
default y
|
||||||
help
|
|
||||||
Enable the application-specific Bluetooth LE multi-slot bond module.
|
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
|||||||
1
prj.conf
1
prj.conf
@@ -117,6 +117,7 @@ CONFIG_BT_ADV_PROV_FLAGS=y
|
|||||||
CONFIG_BT_ADV_PROV_GAP_APPEARANCE=y
|
CONFIG_BT_ADV_PROV_GAP_APPEARANCE=y
|
||||||
CONFIG_BT_ADV_PROV_DEVICE_NAME=y
|
CONFIG_BT_ADV_PROV_DEVICE_NAME=y
|
||||||
CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=y
|
CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=y
|
||||||
|
CONFIG_BT_ADV_PROV_SWIFT_PAIR=y
|
||||||
|
|
||||||
# LVGL
|
# LVGL
|
||||||
CONFIG_LVGL=y
|
CONFIG_LVGL=y
|
||||||
|
|||||||
58
src/swift_pair_module.c
Normal file
58
src/swift_pair_module.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include <bluetooth/adv_prov/swift_pair.h>
|
||||||
|
|
||||||
|
#define MODULE swift_pair_module
|
||||||
|
#include <caf/events/ble_common_event.h>
|
||||||
|
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
Reference in New Issue
Block a user