From 7adad2e676d61d325ed36d1a455eaf8a6c70af72 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Thu, 28 Nov 2024 20:05:08 +0800 Subject: [PATCH] =?utf8?q?=E5=BF=83=E7=8E=87=E8=A1=80=E6=B0=A7=EF=BC=9A?= =?utf8?q?=E4=BC=98=E5=8C=96=E5=BC=82=E5=B8=B8=E6=95=B0=E6=8D=AE=E5=AD=98?= =?utf8?q?=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../bloodoxygen/src/BloodOxygenModel.cpp | 16 +++-- .../nativeui/heartrate/src/HeartModel.cpp | 61 ++++++++++-------- .../peripheral/config/include/ConfigModelC.h | 11 +++- .../peripheral/config/src/ConfigModel.cpp | 21 ++++++- .../peripheral/utils/custom_utils_at_cmd.c | 63 +++++++++++-------- 5 files changed, 110 insertions(+), 62 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp index 9cf112a33..f8d5a614d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp @@ -159,12 +159,14 @@ namespace OHOS { uint16_t MiniBlood = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_OXYGEN_THRESHOLD_VALUE); - // 检查当前血氧值并设置结果 - if (currentspo2 < MiniBlood && currentspo2 != 0) - { - // 测量结果小于最小血氧值 - bloodresult_ = BloodResult::LOW_RESULT; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 低结果情况, currentspo2 = %d, MiniBlood = %d", currentspo2, MiniBlood); + // 检查当前血氧值并设置结果 需要检测成功 + if(bloodresult_ == BloodResult::SUCCESS){ + if (currentspo2 < MiniBlood && currentspo2 != 0) + { + // 测量结果小于最小血氧值 + bloodresult_ = BloodResult::LOW_RESULT; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "检测结果: 低结果情况, currentspo2 = %d, MiniBlood = %d", currentspo2, MiniBlood); + } } // 根据结果进行处理 @@ -197,6 +199,8 @@ namespace OHOS healthState.resultStatus = LOW; healthState.checkResult = MiniBlood; HealthService::GetInstance()->SetHealthCurrent(healthState); + //保存异常数据 + Blood_Save(); NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID); break; } 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 38ac39b37..ee2c95a5a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -21,6 +21,7 @@ #include "uiservice/include/ui_service.h" #include "wearable_log.h" #include + #include #include #include @@ -40,6 +41,8 @@ #include "languagecode/LanguageInit.h" #include "ui_service.h" +#include "hx3695.h" + #ifdef __cplusplus extern "C" { #endif @@ -475,6 +478,7 @@ void HeartModel::Heart_Stop() { Heart_Control(HeartState::End, HeartCheck::PASSIVITY); return; } + //呼吸训练模式下不进行息屏与保存 if (sensorstate && uapi_dev_runtime_get_respiratory_training_status() != 1) { // 恢复正常亮屏 HeartModel::GetInstance()->heart_stop_screen60s_timer(); @@ -514,34 +518,39 @@ void HeartModel::Heart_Save() { } void HeartModel::Heart_Result() { - // 获取心率提醒状态和阈值 - heartRemindState = ConfigModel::GetInstance()->get_configData_int( - ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND); - thresholdValue = ConfigModel::GetInstance()->get_configData_int( - ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE); - - if (heartRemindState) { - // 获取当前心率状态 - thresholdState = ConfigModel::GetInstance()->get_configData_int( - ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN); - - if (currentheart != 0) { - if (thresholdState == 0 && currentheart < thresholdValue) { - // 当前心率低于阈值 - heartresult_ = HeartResult::LOW_RESULT; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "检测结果:低结果情况,currentheart=%d,ThresholdValue=%d", - currentheart, thresholdValue); - } else if (thresholdState == 1 && currentheart > thresholdValue) { - // 当前心率高于阈值 - heartresult_ = HeartResult::HIGH_RESULT; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "检测结果:高结果情况,currentheart=%d,ThresholdValue=%d", - currentheart, thresholdValue); + + if (heartresult_ == HeartResult::SUCCESS) { + // 获取心率提醒状态和阈值 + heartRemindState = ConfigModel::GetInstance()->get_configData_int( + ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND); + thresholdValue = ConfigModel::GetInstance()->get_configData_int( + ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "心率提醒状态:%d,阈值:%d,當前值:%d", + heartRemindState, thresholdValue, currentheart); + + if (heartRemindState) { + // 获取当前心率状态 + thresholdState = ConfigModel::GetInstance()->get_configData_int( + ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN); + + if (currentheart != 0) { + if (thresholdState == 0 && currentheart < thresholdValue) { + // 当前心率低于阈值 + heartresult_ = HeartResult::LOW_RESULT; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "检测结果:低结果情况,currentheart=%d,ThresholdValue=%d", + currentheart, thresholdValue); + } else if (thresholdState == 1 && currentheart > thresholdValue) { + // 当前心率高于阈值 + heartresult_ = HeartResult::HIGH_RESULT; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "检测结果:高结果情况,currentheart=%d,ThresholdValue=%d", + currentheart, thresholdValue); + } } } } - // 根据结果进行处理 handleHeartResult(); } @@ -565,10 +574,12 @@ void HeartModel::handleHeartResult() { break; case HeartResult::LOW_RESULT: + Heart_Save(); handleLowHeartRate(); break; case HeartResult::HIGH_RESULT: + Heart_Save(); handleHighHeartRate(); break; diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h index 6d998b528..de2fb6ad2 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h @@ -107,8 +107,17 @@ int get_sedentary_time_from_config_model(void); int get_sedentary_interval_from_config_model(void); bool get_motion_recognition_from_config_model(void); int get_config_heart_from_config_model(void); -//设置睡眠频率 + +/* ---------------------------------- 健康管理 ---------------------------------- */ +//设置心率周期检测频率 void set_config_heart(int heartRateDetectionFreq); +//設置心率最高值 +void set_config_heart_max(int heartRateMax); +//設置心率最低值 +void set_config_heart_min(int heartRateMin); +//設置血氧最低值 +void set_config_spo2_min(int spo2Min); +/* -------------------------------------------------------------------------- */ // sleep mode switch void mmi_sleep_mode_switch_read(void); diff --git a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp index 04da1a3a5..46d350db0 100644 --- a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp +++ b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp @@ -1472,10 +1472,9 @@ int get_wake_up_time_from_config_model(void) wake_up_time = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_GET_UP); return wake_up_time; } - +// 设置心率检测频率 void set_config_heart(int heartRateDetectionFreq) { - // 设置心率检测频率 OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_DETECTED, heartRateDetectionFreq); } @@ -1486,7 +1485,23 @@ int get_config_heart_from_config_model(void) time = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_DETECTED); return time; } - +//设置最大心率 +void set_config_heart_max(int heartRateMax) { + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND, 1); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN, 1); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE, heartRateMax); +} +//设置最小心率 +void set_config_heart_min(int heartRateMin) { + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND, 1); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN, 0); + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE, heartRateMin); +} +//设置最小血氧 +void set_config_spo2_min(int spo2Min) { + OHOS::ConfigModel::GetInstance()->set_condigData_Int( + OHOS::ConfigModel::CONFIGMODEL_ITEM_OXYGEN_THRESHOLD_VALUE, spo2Min); +} //获取久坐提醒开关 int get_sedentary_switch_from_config_model(void) { diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 863f79814..fdaf34e25 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -776,37 +776,44 @@ static uint32_t custom_mem_debug(uint8_t *para, uint32_t paraLen, char *strCommo wstp_print("Restoring Factory Settings...\n"); return ERRCODE_SUCC; } - -#if 1 - /*设置心率检测频率*/ - static uint32_t custom_set_heart(uint8_t *para, uint32_t paraLen, char *strCommonCmd) - { - UNUSED(strCommonCmd); + static uint32_t custom_set_health(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { + UNUSED(strCommonCmd); uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = {0}; uint32_t argc = 0; - int ret = ConvertCmdToParam(para, paraLen, argv, &argc); - if (ret != CUSTOM_UTILS_SUCCESS) - { - wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n"); - return ERRCODE_FAIL; - } - - if (argc != 1) - { - wstp_print("CUSTOM_UTILSTEST power_test ATCMD Set Parameter Failed argc %d\r\n"); - return ERRCODE_FAIL; - } - int heartRateDetectionFreq = atol((char *)argv[0]); - - // 设置心率检测频率 - set_config_heart(heartRateDetectionFreq); - - wstp_print("heartRateDetectionFreq is %d\n", heartRateDetectionFreq); - return ERRCODE_SUCC; + wstp_print("開始設置健康數據\n"); + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + wstp_print("CUSTOM_UTILSTEST ATCMD 转换命令失败\n"); + return ERRCODE_FAIL; + } + + int set_health_type = atol((char *)argv[0]); + int data = atol((char *)argv[1]); + wstp_print("設置健康數據 %d %d\n", set_health_type, data); + + switch (set_health_type) { + case 0: // 心率检测周期 + set_config_heart(data); + break; + case 1: // 心率最高值 + set_config_heart_max(data); + break; + case 2: // 心率最低值 + set_config_heart_min(data); + break; + case 3: // 血氧最低值 + set_config_spo2_min(data); + break; + default: + wstp_print("错误:无效的健康类型 %d\n", set_health_type); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; // 成功 } -#endif static uint32_t custom_get_cywee_chip_info(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { @@ -1513,7 +1520,9 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^MEMDEBUG", custom_mem_debug, (char *)" " }, {(char *)"AT^RESTORE", custom_restore_factory_settings, (char *)" "}, - {(char *)"AT^SETHEART", custom_set_heart, (char *)" "}, + {(char *)"AT^SETHEALTH", custom_set_health, (char *)" "}, + + {(char *)"AT^LSFD", custom_lsfd, (char *)" "}, {(char *)"AT^GETMAC", custom_get_bt_addr, (char *)" "}, -- 2.17.1