From: 袁清梦 <3449750381@qq.com> Date: Fri, 26 Jul 2024 10:09:58 +0000 (+0000) Subject: Merge #593 into sdk602patch0626 from refs/changes/593/head X-Git-Tag: release_V1.2.70_20241020_135402~730^2~17^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=cbd8b3d5bf47c2ff565382542a9be3ad00606218;p=mirrors%2FFD230.git Merge #593 into sdk602patch0626 from refs/changes/593/head Code review from 袁清梦 * refs/changes/593/head: (6 commits squashed) - 增加自定义表盘配置文件相对应接口 - 修复maomao表盘异常 - 暂时屏蔽自定义表盘配置文件读取 - 取消训练状态下的心率存储 - 增加runtime训练状态管理 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/593 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h index 5113f3c50..5c4920735 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h @@ -90,14 +90,13 @@ namespace OHOS void UpdateBatteryColor(void); /*配置文件*/ void SetDialPath(std::string dialpath); - bool InitialConfig(int Id); + /*配置函数*/ bool InitBackground(const char *filename); bool InitTimeView(TimeDisplayPosition type); // 时间 bool InitBatteryView(BatteryDisplayType type); // 电量 bool InitColor(ColorTypeSet type); // 颜色 - /*返回文件夹路径*/ - std::string GetSaveDir(int Id); + private: void InitStepValue(); @@ -108,7 +107,7 @@ namespace OHOS bool InitClock(void); bool LoadClockImage(Image *view, uint32_t resId); bool LoadClockImage(UIImageView *view, uint32_t resId); - void CreateDirectoryIfNotExists(const std::string &path); + /*表盘背景*/ UIImageView *curFace{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp index 05a97ffa8..87739fb10 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp @@ -136,90 +136,6 @@ namespace OHOS dialFile.clear(); dialFile = dialpath; } - /* - 从配置文件读取设置 - 配置文件名:表盘ID - 第一个字节:电池图标样式 - 第二个字节:时间label位置 - 第三个字节:字体颜色 - */ - bool MainClockView::InitialConfig(int Id) - { - std::string filename = APP_CUSTOM_DIAL_PATH + std::to_string(Id) + ".bin"; - - // 打开文件 - std::ifstream configFile(filename, std::ios::binary); - if (!configFile.is_open()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unable to open config file: %s", filename.c_str()); - return false; // 文件打开失败 - } - - // 读取配置 - char settings[3]; // 读取3个字节 - configFile.read(settings, sizeof(settings)); - if (configFile.gcount() != sizeof(settings)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to read config file or insufficient file content!"); - configFile.close(); - return false; // 读取失败 - } - - // 为成员变量赋值 - batterySetting = static_cast(settings[0]); // 第一个字节:电池图标样式 - timePosition = static_cast(settings[1]); // 第二个字节:时间label位置 - colorType = static_cast(settings[2]); // 第三个字节:字体颜色 - - // 关闭文件 - configFile.close(); - - return true; // 成功读取配置 - } - /* - 获取存储文件夹 - Id(0~4)通过ID返回对应的文件夹路径 - 0 - 1 - 2 - 3 - 4 - */ - /*创建文件夹*/ - void MainClockView::CreateDirectoryIfNotExists(const std::string &path) - { - struct stat info; - if (stat(path.c_str(), &info) != 0) - { - if (mkdir(path.c_str(), 0755) != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Could not create directory %s. Errno: %d", path.c_str(), errno); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Created directory: %s", path.c_str()); - } - } - else if (info.st_mode & S_IFDIR) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", path.c_str()); - } - } - /*获取文件夹路径*/ - std::string MainClockView::GetSaveDir(int Id) - { - // 首先检查Id是否在0~4的范围内 - if (Id < 0 || Id > 4) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Id must be between 0 and 4."); - return ""; // 或者返回一个空字符串 - } - - std::string folderPath = std::string(APP_CUSTOM_DIAL_PATH) + "/" + std::to_string(Id); // 修复这一行 - CreateDirectoryIfNotExists(folderPath); // 确保目录存在 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory is %s", folderPath.c_str()); - - return folderPath; // 返回目录路径 - } bool MainClockView::InitClock(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp index d3228c16c..f78e5ce39 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -13,6 +13,9 @@ #include "health_service.h" #include "custom_utils.h" #include "ppg_service.h" +#include "custom_runtime.h" +#include +#include #ifdef __cplusplus extern "C" @@ -82,6 +85,11 @@ extern "C" { UNUSED(args); UNUSED(topic); + + /*训练过程中 不需要判断数据准确性 不需要存储心率数据*/ + if (uapi_dev_runtime_get_train_status() == 1) + return; + if (request == nullptr) { return; @@ -98,7 +106,7 @@ extern "C" return; } #endif - uint16_t preheart = *(uint16_t *)request->data; + uint16_t preheart = *reinterpret_cast(request->data); // 筛选出正常数据 if (preheart > HEART_RATE_LIMIT_LOWER && preheart <= HEART_RATE_LIMIT_UPPER) { @@ -107,6 +115,7 @@ extern "C" if (heartInfo == nullptr) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[Notify] malloc fail"); + return; } heartInfo->index = index_; heartInfo->maxX = index_; @@ -623,6 +632,10 @@ namespace OHOS void HeartModel::UpHeartdata(uint16_t heart) { + /*训练过程中 不需要判断数据准确性 不需要存储心率数据*/ + if (uapi_dev_runtime_get_train_status() == 1) + return; + Show_Heart_ = heart; if (Show_Heart_ != 0) { @@ -656,7 +669,7 @@ namespace OHOS data->timestamp = HeartPresenter::GetInstance()->GetCurrentTime(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " Save %d %d", data->Heart, data->timestamp); SetCheckTime(data->timestamp); - HealthService::GetInstance()->UpdateHealthData(*data); + HealthService::GetInstance()->UpdateHealthData(*data); // 心率数据存储 // 关闭自动检测心率 如果有其他高级心率检测在进行,则不会进行关闭[低优先级] HeartModel::GetInstance()->Heart_Control(HeartState::End, HeartCheck::PASSIVITY); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp index d6657bf67..4eb104635 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -383,7 +383,7 @@ namespace OHOS #endif MainClockView *clock = new MainClockView(); clock->SetDialPath(setting.dialFullName); - clock->InitialConfig(setting.dialId); + // clock->InitialConfig(setting.dialId); //配置文件 return clock; } UICardPage *MainViewSample::InitWatchFacePage(void) 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 b316c61f4..30ea317fb 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 @@ -36,6 +36,13 @@ namespace OHOS DEFULTDIAL, DOWNLOADDIAL, }; + struct DialLayout + { + uint8_t dialId; + uint8_t batteryDisplay; // 电池配置 + uint8_t timeDisplay; // 时间位置 + uint8_t colorTypeSet; // 颜色配置 + }; class SetDialModel { public: @@ -53,12 +60,19 @@ namespace OHOS uint16_t GetDialIdFromName(const std::string &dialName); void PrintRegisteredDials(const std::unordered_map &dials); int GetAllDialIDs(char *allidStr); + + /*表盘map文件*/ bool readDialfile(); bool saveDialfile(); + /*自定义表盘配置文件*/ + bool saveDialConfig(const DialLayout &layout); + bool loadDialConfig(int Id, DialLayout &layout); + /*获取存储自定义表盘文件夹路径*/ std::string GetSaveDir(int Id); + /*【判断文件夹是否存在 不存在创建】*/ + void CreateDirectoryIfNotExists(const std::string &path); private: - void CreateDirectoryIfNotExists(const std::string &path); void LoadAllDialFromRam(void); void LoadAllDialFromFs(void); void LoadAllDialFromDefult(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 f86a8386d..e60864a26 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 @@ -28,10 +28,13 @@ #include #include #include +#include +#include #include -#include "NativeAbility.h" -#include "UiConfig.h" #include +#include +#include "NativeAbility.h" +#include "clock/include/MainClockView.h" namespace OHOS { // 定义特殊Id @@ -285,42 +288,6 @@ namespace OHOS } } - void SetDialModel::CreateDirectoryIfNotExists(const std::string &path) - { - struct stat info; - if (stat(path.c_str(), &info) != 0) - { - if (mkdir(path.c_str(), 0755) != 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Could not create directory %s. Errno: %d", path.c_str(), errno); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Created directory: %s", path.c_str()); - } - } - else if (info.st_mode & S_IFDIR) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", path.c_str()); - } - } - - std::string SetDialModel::GetSaveDir(int Id) - { - // 首先检查Id是否在0~4的范围内 - if (Id < 0 || Id > 4) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Id must be between 0 and 4."); - return ""; // 或者返回一个空字符串 - } - CreateDirectoryIfNotExists(std::string(APP_CUSTOM_DIAL_PATH)); - std::string folderPath = std::string(APP_CUSTOM_DIAL_PATH) + "/" + std::to_string(Id); // 修复这一行 - CreateDirectoryIfNotExists(folderPath); // 确保目录存在 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory is %s", folderPath.c_str()); - - return folderPath; // 返回目录路径 - } - /*加载所有表盘*/ void SetDialModel::LoadAllDial() { @@ -558,5 +525,115 @@ namespace OHOS } return 0; } + /* --------------------------------- 自定义表盘配置 -------------------------------- */ + // 保存自定义表盘配置到文件 + bool SetDialModel::saveDialConfig(const DialLayout &layout) + { + std::string filename = APP_CUSTOM_DIAL_PATH + std::to_string(layout.dialId) + ".bin"; + + // 创建或打开文件 + std::ofstream configFile(filename, std::ios::binary | std::ios::out | std::ios::trunc); + if (!configFile.is_open()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unable to open config file for writing: %s", filename.c_str()); + return false; // 文件打开失败 + } + + // 将结构体的三个数据按1个字节的存储到文件 + configFile.put(static_cast(layout.batteryDisplay)); // 第一字节:电池图标样式 + configFile.put(static_cast(layout.timeDisplay)); // 第二字节:时间label位置 + configFile.put(static_cast(layout.colorTypeSet)); // 第三字节:字体颜色 + + // 关闭文件 + configFile.close(); + return true; // 成功写入配置 + } + + /* + 从配置文件读取设置 + 配置文件名:表盘ID + 第一个字节:电池图标样式 + 第二个字节:时间label位置 + 第三个字节:字体颜色 + */ + bool SetDialModel::loadDialConfig(int Id, DialLayout &layout) + { + std::string filename = APP_CUSTOM_DIAL_PATH + std::to_string(Id) + ".bin"; + + // 打开文件 + std::ifstream configFile(filename, std::ios::binary); + if (!configFile.is_open()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unable to open config file for reading: %s", filename.c_str()); + return false; // 文件打开失败 + } + + // 读取配置 + char settings[3]; // 读取3个字节 + configFile.read(settings, sizeof(settings)); + if (configFile.gcount() != sizeof(settings)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to read config file or insufficient file content!"); + configFile.close(); + return false; // 读取失败 + } + + // 为成员变量赋值 + layout.batteryDisplay = static_cast(settings[0]); // 电池图标样式 + layout.timeDisplay = static_cast(settings[1]); // 时间label位置 + layout.colorTypeSet = static_cast(settings[2]); // 字体颜色 + + // 关闭文件 + configFile.close(); + return true; // 成功读取配置 + } + + /*创建文件夹*/ + void SetDialModel::CreateDirectoryIfNotExists(const std::string &path) + { + struct stat info; + if (stat(path.c_str(), &info) != 0) + { + if (mkdir(path.c_str(), 0755) != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Could not create directory %s. Errno: %d", path.c_str(), errno); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Created directory: %s", path.c_str()); + } + } + else if (info.st_mode & S_IFDIR) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", path.c_str()); + } + } + + /* + 获取存储文件夹 + Id(0~4)通过ID返回对应的文件夹路径 + 0 + 1 + 2 + 3 + 4 + */ + std::string SetDialModel::GetSaveDir(int Id) + { + // 首先检查Id是否在0~4的范围内 + if (Id < 0 || Id > 4) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Id must be between 0 and 4."); + return ""; // 或者返回一个空字符串 + } + // 检查 APP_CUSTOM_DIAL_PATH 是否存在 + CreateDirectoryIfNotExists(APP_CUSTOM_DIAL_PATH); + + std::string folderPath = std::string(APP_CUSTOM_DIAL_PATH) + "/" + std::to_string(Id); // 修复这一行 + CreateDirectoryIfNotExists(folderPath); // 确保目录存在 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory is %s", folderPath.c_str()); + + return folderPath; // 返回目录路径 + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index d93cb4b1a..12d878025 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -43,6 +43,7 @@ #include #include #include +#include "custom_runtime.h" #include "traingrecord/include/TraingRecordModel.h" #define MAX_FILE_PATH_LENGTH 128 @@ -404,15 +405,14 @@ namespace OHOS { // 不同的运动类型解析不同的数据 // 通用数据 - sportdata->steps = cyweeInfo->steps; - sportdata->distance = cyweeInfo->distance; + sportdata->distance = cyweeInfo->distance; // 只赋值一次 sportdata->calories = cyweeInfo->calories; sportdata->cdc = cyweeInfo->step_frequency; sportdata->std = cyweeInfo->step_length; sportdata->pc = cyweeInfo->pace; - sportdata->distance = cyweeInfo->distance; - /*最慢配速*/ + + // 更新最慢配速 if (sportdata->spc < sportdata->pc) { sportdata->spc = sportdata->pc; @@ -420,42 +420,25 @@ namespace OHOS sportdata->heart = cyweeInfo->hrs; SetIntensity(sportdata->heart); // 设置训练强度 - if (cyweeInfo->hrs > 50) + + // 计算平均心率 + if (sportdata->heart > 50) { - // sportdata->heart = CalculateFilteredHeartRate(cyweeInfo->hrs); // 处理显示心率 - // sportdata->avgheart = CalculateAverageHeartRate(cyweeInfo->hrs); // 处理正常的平均心率 sportdata->avgheart = Averageheartrate(sportdata->heart); } - // 达到最高心率进行心率提醒弹窗 - if (sportdata->heart >= ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_TRAINING_HEART_MAX)) + // 心率提醒 + int maxHeartRate = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_TRAINING_HEART_MAX); + if (sportdata->heart >= maxHeartRate) { uapi_set_screen_on_api(); // 亮屏检测 custom_VibratorFunc(VibratorType::VIBRATOR_TYPE_TWO); // 震动提醒 TraingCardView::GetInstance()->SetPopupViewStatus(HeartPopup, true); } -#if 0 - // sportdata->duration = cyweeInfo->duration; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "normal sportdata->calories[%d],sportdata->heart[%d] \r\n", sportdata->calories, sportdata->heart); - switch (type) - { - case ExerciseClass::OUTDOOR: - case ExerciseClass::INDOOR: - sportdata->distance = cyweeInfo->distance; - sportdata->steps = cyweeInfo->steps; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "indoor sportdata->distance[%d],sportdata->steps[%d] \r\n", sportdata->distance, sportdata->steps); - break; - case ExerciseClass::FREE_TRAINING: - break; - default: - break; - } -#endif - /* -------------------------------------------------------------------------- */ - // 首先需要判断有没有设置训练目标,并且保障弹窗只出现一次 - if (sportdata->tag && (!Gettagstuats)) + + // 训练目标检查 + if (sportdata->tag && !Gettagstuats) { - // 根据设置的训练目标类型去对应相对的数据 int currentdata = GetSportTagData(); if (currentdata >= sportdata->tag) { @@ -591,6 +574,9 @@ namespace OHOS // 增加标志位互斥保障"开始"和"结束"的唯一性操作 if (currentState == ExerciseState::Start && !Startstate) { + // 设置训练 runtime 为 1 训练中 + uapi_dev_runtime_set_train_status(1); + ResetSharedTrainingData(); // 重置共享训练数据 printf("SetTimestamp::time:%u \r\n", time); @@ -616,6 +602,9 @@ namespace OHOS } else if (currentState == ExerciseState::End && !Endstate) { + // 设置训练 runtime 为 0 训练结束 + uapi_dev_runtime_set_train_status(0); + sportdata->endtime = time; SetEndTime(); diff --git a/tools/dial_converter_tool/dial_lzma/101/sport.lzma b/tools/dial_converter_tool/dial_lzma/101/sport.lzma index 0f3b1713b..18f4b376e 100644 Binary files a/tools/dial_converter_tool/dial_lzma/101/sport.lzma and b/tools/dial_converter_tool/dial_lzma/101/sport.lzma differ diff --git a/tools/dial_converter_tool/dial_lzma/108/maomao.lzma b/tools/dial_converter_tool/dial_lzma/108/maomao.lzma index 0aeff1584..dd12e746d 100644 Binary files a/tools/dial_converter_tool/dial_lzma/108/maomao.lzma and b/tools/dial_converter_tool/dial_lzma/108/maomao.lzma differ diff --git a/tools/dial_converter_tool/instance/108/maomao.xml b/tools/dial_converter_tool/instance/108/maomao.xml index a6427516b..4d9da635c 100644 --- a/tools/dial_converter_tool/instance/108/maomao.xml +++ b/tools/dial_converter_tool/instance/108/maomao.xml @@ -1,4 +1,4 @@ - +