From: Caisking <3449750381@qq.com> Date: Fri, 14 Jun 2024 10:23:06 +0000 (+0800) Subject: 增加获取所有表盘Id X-Git-Tag: release_V1.2.70_20241020_135402~994^2~9 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=0259eb79f67e72d4d2d040ed23c468b963c8b4ba;p=mirrors%2FFD230.git 增加获取所有表盘Id --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h index 07dfc62cd..171f56f34 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-05-30 15:59:37 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-14 16:51:13 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: SetDialModel.h @@ -29,6 +35,7 @@ namespace OHOS void UpdateDialSetting(uint16_t ID); uint16_t GetDialIdFromName(const std::string &dialName); void PrintRegisteredDials(const std::unordered_map &dials); + int GetAllDialIDs(char *allidStr); private: void LoadAllDialFromRam(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp index 15e930cc7..9f28c153e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp @@ -19,6 +19,9 @@ #include "DialBinParser.h" #include "custom_utils.h" #include "wearable_log.h" +#include +#include +#include namespace OHOS { @@ -79,6 +82,30 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentDialID is %d,name is %s", currentDialID, registeredDials[currentDialID].c_str()); return currentDialID; } + /* 获取所有表盘Id 每个表盘Id 2个字节 拼接为字符串 */ + int SetDialModel::GetAllDialIDs(char *allidStr) + { + std::string allIDs; + for (const auto &entry : registeredDials) + { + // 格式化表盘ID为两个字节长度的字符串,不足两位则在前面补0 + std::stringstream ss; + ss << std::setw(2) << std::setfill('0') << entry.first; + allIDs += ss.str(); + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "allidStr is %s", allIDs.c_str()); + + // 将字符串拷贝到allidStr中 + int length = allIDs.size(); + if (length > 0) + { + strcpy(allidStr, allIDs.c_str()); + allidStr[length] = '\0'; // 添加字符串结尾的空字符 + } + + return length; + } /* 判断表盘是否存在*/ bool SetDialModel::IsDialInstalled(uint16_t ID) { @@ -155,6 +182,9 @@ namespace OHOS /* 只排序离线表盘 */ std::sort(dialInfoList.begin() + dialSize, dialInfoList.end(), [](const SetDialInfo &f, const SetDialInfo &n) { return f.dialName < n.dialName; }); + // 表盘Id以及表盘map打印 + char dialId[128]; + GetAllDialIDs(dialId); PrintRegisteredDials(registeredDials); } /*加载自定义表盘*/ @@ -252,7 +282,7 @@ namespace OHOS dialInfo.dialName = preInfo.dialName; dialInfo.description = preInfo.description; dialInfo.preImageInfo = info; - +#if 0 // 需要判断表盘是否存在 不存在->新表盘注册 if (GetDialIdFromName(dialInfo.dialName) == 0) { @@ -270,7 +300,7 @@ namespace OHOS // 注册表盘,将表盘ID和表盘文件名添加到 registeredDials 中 RegisterDial(newDialId, (dialInfo.dialName).c_str()); } - +#endif fclose(fp); return 0; }