From 07fe70becd3b10fc459317c1c1a6675d184ebbbf Mon Sep 17 00:00:00 2001 From: skiinder Date: Sat, 25 Apr 2026 15:57:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(ble):=20=E6=9B=B4=E6=96=B0=E8=93=9D?= =?UTF-8?q?=E7=89=99=E9=85=8D=E5=AF=B9=E5=A4=9A=E6=A8=A1=E5=9D=97=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=90=8D=E7=A7=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除DEFAULT_DISPLAY_NAME_BONDED宏定义 - 添加display_name_set_addr函数用于根据设备地址设置显示名称 - 修改display_name_set_default函数逻辑,当有已占用槽位且存在最后连接的对等设备地址时, 使用该地址作为显示名称 - 在slot_update_from_bonds函数中添加逻辑,当显示名称为空或为默认空名称时,使用对等 设备地址更新显示名称 - 在处理BLE对等事件时,使用对等设备地址直接设置显示名称 fix(ui): 调整UI设置项文本对齐和截断方式 - 将设置项值的文本对齐方式从右对齐改为左对齐 - 将标签长文本模式从裁剪(CLIP)改为滚动(SCROLL),以便更好地显示长设备名称 --- src/ble_bond_multi_module.c | 36 ++++++++++++++++++++++++++++++++---- src/ui/ui_settings.c | 4 ++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/ble_bond_multi_module.c b/src/ble_bond_multi_module.c index 57c8bdc..517e5e3 100644 --- a/src/ble_bond_multi_module.c +++ b/src/ble_bond_multi_module.c @@ -28,7 +28,6 @@ LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF); #define IDENTITY_DONGLE BLE_BOND_MULTI_DONGLE_SLOT_ID #define SETTINGS_KEY_CURRENT_SLOT "current_slot" #define SETTINGS_KEY_META_PREFIX "meta/" -#define DEFAULT_DISPLAY_NAME_BONDED "Bonded Device" #define DEFAULT_DISPLAY_NAME_EMPTY "Empty" struct ble_bond_multi_slot_meta_storage { @@ -88,11 +87,31 @@ static bool is_ble_slot(uint8_t slot) return (slot >= BLE_SLOT_MIN) && (slot <= BLE_SLOT_MAX); } +static void display_name_set_addr(uint8_t slot, const bt_addr_le_t *addr) +{ + struct ble_bond_multi_slot_meta *meta = &ctx.slot_meta[slot]; + + if ((addr == NULL) || !bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) { + strncpy(meta->display_name, DEFAULT_DISPLAY_NAME_EMPTY, + sizeof(meta->display_name)); + meta->display_name[sizeof(meta->display_name) - 1U] = '\0'; + return; + } + + bt_addr_le_to_str(addr, meta->display_name, sizeof(meta->display_name)); + meta->display_name[sizeof(meta->display_name) - 1U] = '\0'; +} + static void display_name_set_default(uint8_t slot) { struct ble_bond_multi_slot_meta *meta = &ctx.slot_meta[slot]; - const char *name = meta->occupied ? DEFAULT_DISPLAY_NAME_BONDED : - DEFAULT_DISPLAY_NAME_EMPTY; + const char *name = DEFAULT_DISPLAY_NAME_EMPTY; + + if (meta->occupied && + bt_addr_le_cmp(&meta->last_peer_addr, BT_ADDR_LE_ANY)) { + display_name_set_addr(slot, &meta->last_peer_addr); + return; + } strncpy(meta->display_name, name, sizeof(meta->display_name)); meta->display_name[sizeof(meta->display_name) - 1U] = '\0'; @@ -298,6 +317,13 @@ static void slot_update_from_bonds(uint8_t slot) } else if (!bt_addr_le_cmp(&meta->last_peer_addr, BT_ADDR_LE_ANY)) { bt_foreach_bond(slot, bond_addr_get_cb, &meta->last_peer_addr); } + + if (meta->occupied && + ((meta->display_name[0] == '\0') || + !strcmp(meta->display_name, DEFAULT_DISPLAY_NAME_EMPTY))) { + display_name_set_addr(slot, &meta->last_peer_addr); + } + slot_meta_ensure_name(slot); } @@ -425,7 +451,9 @@ static bool handle_ble_peer_event(const struct ble_peer_event *event) if ((ctx.slot_meta[ctx.current_slot].display_name[0] == '\0') || !strcmp(ctx.slot_meta[ctx.current_slot].display_name, DEFAULT_DISPLAY_NAME_EMPTY)) { - display_name_set_default(ctx.current_slot); + display_name_set_addr(ctx.current_slot, + &ctx.slot_meta[ctx.current_slot] + .last_peer_addr); } (void)settings_save_slot_meta(ctx.current_slot); diff --git a/src/ui/ui_settings.c b/src/ui/ui_settings.c index c3f1619..e915abb 100644 --- a/src/ui/ui_settings.c +++ b/src/ui/ui_settings.c @@ -71,8 +71,8 @@ static void create_row(struct ui_settings_row *row) lv_obj_set_flex_grow(row->value, 1); lv_obj_set_style_text_font(row->value, &lv_font_montserrat_14, 0); lv_obj_set_style_text_color(row->value, lv_color_hex(0x97A3B5), 0); - lv_obj_set_style_text_align(row->value, LV_TEXT_ALIGN_RIGHT, 0); - lv_label_set_long_mode(row->value, LV_LABEL_LONG_CLIP); + lv_obj_set_style_text_align(row->value, LV_TEXT_ALIGN_LEFT, 0); + lv_label_set_long_mode(row->value, LV_LABEL_LONG_SCROLL); row->custom = lv_obj_create(row->row); lv_obj_remove_style_all(row->custom);