From 02f3168c596a75d4c8e87fcd1efc6219153fd728 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 26 Nov 2024 21:37:23 +0800 Subject: [PATCH] =?utf8?q?=E5=BF=83=E7=8E=87=EF=BC=9A=E5=84=AA=E5=8C=96?= =?utf8?q?=E5=BF=83=E7=8E=87=E7=95=B0=E5=B8=B8=E8=99=95=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/heartrate/src/HeartModel.cpp | 154 +++++++++--------- 1 file changed, 81 insertions(+), 73 deletions(-) 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 55b37f1e9..38ac39b37 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -37,8 +37,8 @@ #include #include "battery_hal.h" -#include "ui_service.h" #include "languagecode/LanguageInit.h" +#include "ui_service.h" #ifdef __cplusplus extern "C" { @@ -396,9 +396,7 @@ void HeartModel::Heart_Control(HeartState state, HeartCheck check) { uapi_dev_runtime_set_hrs_passivity(1); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_dev_runtime_set_hrs_passivity(1)"); - } - else - { + } else { uapi_dev_runtime_set_hrs_passivity(0); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_dev_runtime_set_hrs_passivity(0)"); @@ -418,6 +416,7 @@ void HeartModel::Heart_Control(HeartState state, HeartCheck check) { if (checkstate == HeartCheck::CARDCHECK) { //重置传感器状态 sensorstate = false; + uapi_dev_runtime_set_heartrate_detect_status(0); } // 复原检测状态 checkstate = HeartCheck::RESTSTSTE; @@ -482,13 +481,14 @@ void HeartModel::Heart_Stop() { // 取消常亮屏 ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //设置runtime - uapi_dev_runtime_set_heartrate_detect_status(0); + Heart_Result(); // 处理结果 //为了防止主界面卡片一直重复开传感器 if (checkstate != HeartCheck::CARDCHECK) { //重置传感器状态 sensorstate = false; + uapi_dev_runtime_set_heartrate_detect_status(0); } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "本次心率检测结束"); } @@ -785,74 +785,82 @@ uint16_t *HeartModel::GetArrayData() { return dynamic_heartrate; } // 获取检测字符串 // 获取检测字符串 // TODO: 适配多国语言 -std::string HeartModel::GetCheckString() { - std::string check_string = "检测结果未知"; - - // 获取检测数据 - if (currentheart == 0) { - if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { - check_string = "暂无检测数据"; - } else { - check_string = "No detection data is available"; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "检测数据:%s", check_string.c_str()); - return check_string; - } - - // 获取目前的时间戳 - uint32_t currentTime; - if (uapi_get_timestampe_ss(¤tTime) != ERRCODE_SUCC) { - if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { - check_string = "获取当前时间失败"; - } else { - check_string = "Get time failed"; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "获取当前时间失败"); - return check_string; - } - - // 检查时间戳是否有效 - if (timestamp_ms == 0) { - if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { - check_string = std::to_string(currentheart) + " " + "时间无效,无法检测"; - } else { - check_string = std::to_string(currentheart) + " " + "Invalid time, cannot detect"; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "时间戳无效,无法检测:%s", check_string.c_str()); - return check_string; - } - - // 进行时间戳相减计算 - uint32_t diff = currentTime - timestamp_ms; - uint32_t diff_min = diff / 60; - uint32_t diff_hour = diff_min / 60; - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "当前时间:%d, 上次检测时间:%d", currentTime, timestamp_ms); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "时间差(秒):%d, 时间差(分钟):%d, 时间差(小时):%d", diff, diff_min, diff_hour); - - // 根据时间差生成检测字符串 - if (diff_min < 1) { - if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { - check_string = std::to_string(currentheart) + "次/分 " + "刚刚检测"; // - } else { - check_string = std::to_string(currentheart) + " bpm " + "Just detected"; - } - } else if (diff_hour < 1) { // Within one hour - if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { - check_string = std::to_string(currentheart) + "次/分 " + std::to_string(diff_min) + "分钟前"; - } else { - check_string = std::to_string(currentheart) + " bpm " + std::to_string(diff_min) + " minutes ago"; - } - } else { - if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { - check_string = std::to_string(currentheart) + "次/分 " + "超过一个小时前"; - } else { - check_string = std::to_string(currentheart) + " bpm " + "More than an hour ago"; - } - } - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "检测结果:%s", check_string.c_str()); - return check_string; // Return the final string +std::string HeartModel::GetCheckString() { + std::string check_string = "检测结果未知"; + + // 获取检测数据 + if (currentheart == 0) { + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { + check_string = "暂无检测数据"; + } else { + check_string = "No detection data is available"; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "检测数据:%s", check_string.c_str()); + return check_string; + } + + // 获取目前的时间戳 + uint32_t currentTime; + if (uapi_get_timestampe_ss(¤tTime) != ERRCODE_SUCC) { + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { + check_string = "获取当前时间失败"; + } else { + check_string = "Get time failed"; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "获取当前时间失败"); + return check_string; + } + + // 检查时间戳是否有效 + if (timestamp_ms == 0) { + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { + check_string = std::to_string(currentheart) + " " + "时间无效,无法检测"; + } else { + check_string = + std::to_string(currentheart) + " " + "Invalid time, cannot detect"; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "时间戳无效,无法检测:%s", + check_string.c_str()); + return check_string; + } + + // 进行时间戳相减计算 + uint32_t diff = currentTime - timestamp_ms; + uint32_t diff_min = diff / 60; + uint32_t diff_hour = diff_min / 60; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "当前时间:%d, 上次检测时间:%d", + currentTime, timestamp_ms); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "时间差(秒):%d, 时间差(分钟):%d, 时间差(小时):%d", diff, + diff_min, diff_hour); + + // 根据时间差生成检测字符串 + if (diff_min < 1) { + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { + check_string = std::to_string(currentheart) + "次/分 " + "刚刚检测"; // + } else { + check_string = std::to_string(currentheart) + " bpm " + "Just detected"; + } + } else if (diff_hour < 1) { // Within one hour + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { + check_string = std::to_string(currentheart) + "次/分 " + + std::to_string(diff_min) + "分钟前"; + } else { + check_string = std::to_string(currentheart) + " bpm " + + std::to_string(diff_min) + " minutes ago"; + } + } else { + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { + check_string = std::to_string(currentheart) + "次/分 " + "超过一个小时前"; + } else { + check_string = + std::to_string(currentheart) + " bpm " + "More than an hour ago"; + } + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "检测结果:%s", check_string.c_str()); + return check_string; // Return the final string } // 声明定时器变量 -- 2.17.1