feat(ble): 更新蓝牙配对多模块显示名称逻辑
- 移除DEFAULT_DISPLAY_NAME_BONDED宏定义 - 添加display_name_set_addr函数用于根据设备地址设置显示名称 - 修改display_name_set_default函数逻辑,当有已占用槽位且存在最后连接的对等设备地址时, 使用该地址作为显示名称 - 在slot_update_from_bonds函数中添加逻辑,当显示名称为空或为默认空名称时,使用对等 设备地址更新显示名称 - 在处理BLE对等事件时,使用对等设备地址直接设置显示名称 fix(ui): 调整UI设置项文本对齐和截断方式 - 将设置项值的文本对齐方式从右对齐改为左对齐 - 将标签长文本模式从裁剪(CLIP)改为滚动(SCROLL),以便更好地显示长设备名称
This commit is contained in:
@@ -28,7 +28,6 @@ LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
|
|||||||
#define IDENTITY_DONGLE BLE_BOND_MULTI_DONGLE_SLOT_ID
|
#define IDENTITY_DONGLE BLE_BOND_MULTI_DONGLE_SLOT_ID
|
||||||
#define SETTINGS_KEY_CURRENT_SLOT "current_slot"
|
#define SETTINGS_KEY_CURRENT_SLOT "current_slot"
|
||||||
#define SETTINGS_KEY_META_PREFIX "meta/"
|
#define SETTINGS_KEY_META_PREFIX "meta/"
|
||||||
#define DEFAULT_DISPLAY_NAME_BONDED "Bonded Device"
|
|
||||||
#define DEFAULT_DISPLAY_NAME_EMPTY "Empty"
|
#define DEFAULT_DISPLAY_NAME_EMPTY "Empty"
|
||||||
|
|
||||||
struct ble_bond_multi_slot_meta_storage {
|
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);
|
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)
|
static void display_name_set_default(uint8_t slot)
|
||||||
{
|
{
|
||||||
struct ble_bond_multi_slot_meta *meta = &ctx.slot_meta[slot];
|
struct ble_bond_multi_slot_meta *meta = &ctx.slot_meta[slot];
|
||||||
const char *name = meta->occupied ? DEFAULT_DISPLAY_NAME_BONDED :
|
const char *name = DEFAULT_DISPLAY_NAME_EMPTY;
|
||||||
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));
|
strncpy(meta->display_name, name, sizeof(meta->display_name));
|
||||||
meta->display_name[sizeof(meta->display_name) - 1U] = '\0';
|
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)) {
|
} 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);
|
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);
|
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') ||
|
if ((ctx.slot_meta[ctx.current_slot].display_name[0] == '\0') ||
|
||||||
!strcmp(ctx.slot_meta[ctx.current_slot].display_name,
|
!strcmp(ctx.slot_meta[ctx.current_slot].display_name,
|
||||||
DEFAULT_DISPLAY_NAME_EMPTY)) {
|
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);
|
(void)settings_save_slot_meta(ctx.current_slot);
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ static void create_row(struct ui_settings_row *row)
|
|||||||
lv_obj_set_flex_grow(row->value, 1);
|
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_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_color(row->value, lv_color_hex(0x97A3B5), 0);
|
||||||
lv_obj_set_style_text_align(row->value, LV_TEXT_ALIGN_RIGHT, 0);
|
lv_obj_set_style_text_align(row->value, LV_TEXT_ALIGN_LEFT, 0);
|
||||||
lv_label_set_long_mode(row->value, LV_LABEL_LONG_CLIP);
|
lv_label_set_long_mode(row->value, LV_LABEL_LONG_SCROLL);
|
||||||
|
|
||||||
row->custom = lv_obj_create(row->row);
|
row->custom = lv_obj_create(row->row);
|
||||||
lv_obj_remove_style_all(row->custom);
|
lv_obj_remove_style_all(row->custom);
|
||||||
|
|||||||
Reference in New Issue
Block a user