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:
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