From 0b6c2eb88dc4e122b9fc974ad4a88a8ac460df3f Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 9 Nov 2024 11:33:21 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E4=BC=98=E5=8C=96vot?= =?utf8?q?e=E8=8E=B7=E5=8F=96=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../drivers/peripheral/utils/custom_utils.c | 46 ++++++++++++------- .../drivers/peripheral/utils/custom_utils.h | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 2a820252e..5838ed3b4 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -1290,23 +1290,35 @@ void uapi_set_screen_on_api(void) { } //获取vote正在执行的状态 -errcode_t get_vote_status(char*str) -{ - uint8_t i = 0; - uint8_t falg = 0; - pm_veto_t *pm_veto_ptr = pm_veto_get_info(); - for (i = 0; i < PM_ID_MAX; i++) { - if (pm_veto_ptr->veto_counts.sub_counts[i] == 1) { - sprintf(str, "%s %s", str, get_pm_id_name(i)); - falg = 1; - } - } - if (falg==0) { - str = "没有正在进行的服务"; - } - PRINT("***************get_vote_status***************\n %s\n", str); - return ERRCODE_SUCC; -} +// 获取 vote 正在执行的状态 +errcode_t get_vote_status(char* str, size_t str_size) { + uint8_t i; + uint8_t flag = 0; + pm_veto_t* pm_veto_ptr = pm_veto_get_info(); + + PRINT("***************get_vote_status***************\n"); + + // 初始化字符串为空 + str[0] = '\0'; + + for (i = 0; i < PM_ID_MAX; i++) { + if (pm_veto_ptr->veto_counts.sub_counts[i] == 1) { + // 拼接当前 pm ID 并添加换行符 + snprintf(str + strlen(str), str_size - strlen(str), "%s%s\n", (flag ? " " : ""), get_pm_id_name(i)); + flag = 1; + PRINT("vote_status: %s %d\n", get_pm_id_name(i), pm_veto_ptr->veto_counts.sub_counts[i]); + } else { + PRINT("vote_status: %s %d\n", get_pm_id_name(i), pm_veto_ptr->veto_counts.sub_counts[i]); + } + } + + if (flag == 0) { + snprintf(str, str_size, "没有正在进行的服务"); + } + + PRINT("***************get_vote_status*************** %s\n", str); + return ERRCODE_SUCC; +} /*系统声音设置*/ void uapi_systemVolumeSet(int32_t sounding) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 3c584593f..9d65c0de7 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -87,7 +87,7 @@ errcode_t uapi_get_WeekStr(char *p_week); /*设置屏幕亮屏*/ void uapi_set_screen_on_api(void); /*获取Vote状态*/ -errcode_t get_vote_status(char *str); +errcode_t get_vote_status(char *str,size_t str_size); /** * @brief 日期格式选项枚举 -- 2.17.1