From f6e83dec0720bafead064b706d179718686cf97e Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Mon, 11 Aug 2025 18:41:10 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E8=BF=90=E5=8A=A8=E5=BF=83?= =?utf8?q?=E7=8E=87=EF=BC=8C=E8=A1=80=E6=B0=A7=E6=A3=80=E6=B5=8B=EF=BC=8C?= =?utf8?q?=E4=BF=AE=E5=A4=8D=E8=BF=90=E5=8A=A8=E6=95=B0=E6=8D=AE=E5=BC=82?= =?utf8?q?=E5=B8=B8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../bloodoxygen/src/BloodOxygenModel.cpp | 2 +- code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c | 8 +- code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c | 80 ++++++++----- .../drivers/ppg/pah8009/sensor/pah800x_main.c | 111 ++++++++++-------- 4 files changed, 120 insertions(+), 81 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp index 60b8910be..e6d67c41e 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodOxygenModel.cpp @@ -26,7 +26,7 @@ #define MAX_UNWARE_COUNT 10 #define MAX_VALID_SPO2_COUNT 30 -#define MAX_DISVALID_SPO2_COUNT 100 +#define MAX_DISVALID_SPO2_COUNT 60 #define BLOOD_TIMER_DATA 1 namespace OHOS { diff --git a/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c b/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c index 4a83df3db..b727ae9f0 100644 --- a/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c +++ b/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c @@ -257,6 +257,7 @@ void cywee_check_acc(void) { if(!timeout) { + // printf("cywee_restart_acc\n"); cywee_restart_acc(); } else @@ -1586,6 +1587,9 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_EXTRA_INFO_UPDATE,&c_act_ext_result_t,sizeof(act_ext_result_t)); //CustomEventPublish(TOPIC_EVENT_ACTIVITY_EXTRA_INFO_UPDATE, &c_act_ext_result_t, sizeof(act_ext_result_t)); + // CWM_OS_dbgPrintf("PAH:avg_step_freq[%d], avg_step_len[%f],avg_pace[%d], max_step_freq[%d], max_pace[%d]\n", + // c_act_ext_result_t.avg_step_freq, c_act_ext_result_t.avg_step_len, c_act_ext_result_t.avg_pace, + // c_act_ext_result_t.max_step_freq,c_act_ext_result_t.max_pace); }else if((int)sensorEVT->fData[0] == 5001) { @@ -1622,7 +1626,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_act_result_t,sizeof(act_result_t)); //CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE, &c_act_result_t, sizeof(act_result_t)); //CustomEventPublish(TOPIC_EVENT_STEPDATA_UPDATE,&stepcount,sizeof(int)); - // CWM_OS_dbgPrintf("normal mode activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%.2f], pace[%d]\n", + // CWM_OS_dbgPrintf("PAH:normal mode activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%.2f], pace[%d]\n", // c_act_result_t.activity_mode, c_act_result_t.steps, c_act_result_t.distance, c_act_result_t.calories, // c_act_result_t.step_frequency,c_act_result_t.step_length, c_act_result_t.pace); } @@ -2138,6 +2142,6 @@ void cywee_get_act_ext_data(act_ext_result_t *data) { if(data == NULL) return; - memcpy_s(data,sizeof(act_ext_result_t),&c_act_result_t,sizeof(act_ext_result_t)); + memcpy_s(data,sizeof(act_ext_result_t),&c_act_ext_result_t,sizeof(act_ext_result_t)); } diff --git a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c index 769ba699d..f166ffbf5 100644 --- a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c +++ b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c @@ -132,7 +132,6 @@ uint8_t alg_ram[11 * 1024] __attribute__((aligned(4))); //uint8_t alg_ram[10] = {0}; ppg_sensor_data_t ppg_s_data; -static uint8_t hrs_result = 0; static int history_wear_status = -1; static uint8_t wear_status = 0; static uint8_t spo2_result = 0; @@ -2679,53 +2678,61 @@ void hx3695_ppg_Int_handle(void) #endif } +#define HRS_WINDOW_SIZE 5 static uint8_t hrs_num = 0; static int32_t sum_hrs = 0; static int32_t hrs_data[7] = {0}; static uint8_t left = 0; -static uint8_t right = -1; +static uint8_t right = 0; +static uint8_t avg_hrs = 0; -static void get_avg_hrs(int32_t hrs) +static void get_avg_hrs(uint8_t hrs) { - int32_t min_hrs = 0; - int32_t max_hrs = 0; - int32_t avg_hrs = 0; - if(hrs_num == 7) - { + + + if (hrs_num >= HRS_WINDOW_SIZE) { sum_hrs -= hrs_data[left]; - hrs_data[left] = 0; - left++; - left = left % 7; + left = (left + 1) % HRS_WINDOW_SIZE; hrs_num--; } + hrs_data[right] = hrs; + sum_hrs += hrs; + right = (right + 1) % HRS_WINDOW_SIZE; hrs_num++; - right++; - right = right % 7; - hrs_data[right] = hrs; - sum_hrs += hrs_data[right]; - if(hrs_num > 2) + if (hrs_num > 2) { - min_hrs = hrs_data[0]; - max_hrs = hrs_data[0]; - for (int i = 0;i < hrs_num; i++) - { - if (hrs_data[i] < min_hrs) - min_hrs = hrs_data[i]; - if (hrs_data[i] > max_hrs) - max_hrs = hrs_data[i]; + + uint8_t first_idx = left; + int32_t min_hrs = hrs_data[first_idx]; + int32_t max_hrs = hrs_data[first_idx]; + + + for (uint8_t i = 0; i < hrs_num; i++) { + uint8_t current_idx = (left + i) % HRS_WINDOW_SIZE; + uint8_t current_hrs = hrs_data[current_idx]; + + if (current_hrs < min_hrs) { + min_hrs = current_hrs; + } + if (current_hrs > max_hrs) { + max_hrs = current_hrs; + } } - avg_hrs = (sum_hrs - max_hrs - min_hrs) / (hrs_num - 2); - //PRINT("max_hrs[%d],min_hrs[%d],avg_hrs[%d]\n",max_hrs,min_hrs,avg_hrs); - hrsresult.lastesthrs = avg_hrs; + + uint8_t valid_count = hrs_num - 2; + avg_hrs = (sum_hrs - max_hrs - min_hrs) / valid_count; + + // printf("max_hrs[%d],min_hrs[%d],avg_hrs[%d]\n",max_hrs,min_hrs,avg_hrs); } } + uint8_t hx3695_get_hrs(void) { - return hrs_result; + return avg_hrs; } uint8_t hx3695_get_spo2(void) @@ -2781,7 +2788,7 @@ void hx3695_unwearstatus_update(void) { wear_status = 0; hx3695_wearstatus_update(); - hrs_result = 0; + avg_hrs = 0; } } @@ -3033,7 +3040,7 @@ void hx3695_hrs_ppg_Int_handle(void) // } // PRINT("hrs : %d , wear_status : %d \n",hrsresult.lastesthrs,wear_status); - hrs_result = hrsresult.lastesthrs; + avg_hrs = hrsresult.lastesthrs; msg_count++; if(msg_count >= 3) @@ -3042,7 +3049,7 @@ void hx3695_hrs_ppg_Int_handle(void) #ifdef SUPPORT_PPG_BLE_SERVICE if(uapi_dev_runtime_get_hrs_ble_status()) { - ble_ppgtest_server_send_input_report(&hrs_result,1); + ble_ppgtest_server_send_input_report(&avg_hrs,1); } #endif @@ -3060,7 +3067,7 @@ void hx3695_hrs_ppg_Int_handle(void) if(uapi_dev_runtime_get_train_status()) { hx3695_wearstatus_update(); - // hrs_result = hrsresult.lastesthrs; + // avg_hrs = hrsresult.lastesthrs; // do_cywee_service_check_msg(CYWEE_SERVICE_CMD_HRS_CHANGE,&cywee_data); } } @@ -3897,6 +3904,15 @@ void hx3695_control(char *mode,uint8_t enable) hx3695_wearstatus_update(); uapi_dev_runtime_set_hrs_passivity(0);//清除被动检测runtime } + + hrs_num = 0; + sum_hrs = 0; + memset(hrs_data,0,7); + + left = 0; + right = 0; + avg_hrs = 0; + wear_cnt = 0; #endif }else if(md == HRV_MODE) { diff --git a/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c b/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c index 5bb029172..23a53cacc 100644 --- a/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c +++ b/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c @@ -19,6 +19,8 @@ #ifdef SUPPORT_PPG_BLE_SERVICE #include "ppgBleService.h" #endif + +#define HRS_WINDOW_SIZE 5 //============================================================================ // Static Global Variable //============================================================================ @@ -85,7 +87,6 @@ static osTimerId_t g_pah8009_timer = NULL; static uint8_t time_cnt = 0; static uint8_t wear_cnt = 0; -static uint8_t wear_cnt = 0; static int history_wear_status = -1; @@ -96,7 +97,7 @@ static uint8_t hrs_num = 0; static int32_t sum_hrs = 0; static int8_t hrs_data[7] = {0}; static uint8_t left = 0; -static uint8_t right = -1; +static uint8_t right = 0; static uint8_t avg_hrs = 0; static uint8_t timeout = 0; @@ -394,7 +395,7 @@ void pah_sensor_stop(void) memset(hrs_data,0,7); left = 0; - right = -1; + right = 0; avg_hrs = 0; wear_cnt = 0; } @@ -488,40 +489,48 @@ void hr_algorithm_disable(void) static void get_avg_hrs(uint8_t hrs) { - int32_t min_hrs = 0; - int32_t max_hrs = 0; - if(hrs_num == 5) - { + + + if (hrs_num >= HRS_WINDOW_SIZE) { sum_hrs -= hrs_data[left]; - hrs_data[left] = 0; - left++; - left = left % 5; + left = (left + 1) % HRS_WINDOW_SIZE; hrs_num--; } + hrs_data[right] = hrs; + sum_hrs += hrs; + right = (right + 1) % HRS_WINDOW_SIZE; hrs_num++; - right++; - right = right % 5; - hrs_data[right] = hrs; - sum_hrs += hrs_data[right]; - if(hrs_num > 2) + if (hrs_num > 2) { - min_hrs = hrs_data[0]; - max_hrs = hrs_data[0]; - for (int i = 0;i < hrs_num; i++) - { - if (hrs_data[i] < min_hrs) - min_hrs = hrs_data[i]; - if (hrs_data[i] > max_hrs) - max_hrs = hrs_data[i]; + + uint8_t first_idx = left; + int32_t min_hrs = hrs_data[first_idx]; + int32_t max_hrs = hrs_data[first_idx]; + + + for (uint8_t i = 0; i < hrs_num; i++) { + uint8_t current_idx = (left + i) % HRS_WINDOW_SIZE; + uint8_t current_hrs = hrs_data[current_idx]; + + if (current_hrs < min_hrs) { + min_hrs = current_hrs; + } + if (current_hrs > max_hrs) { + max_hrs = current_hrs; + } } - avg_hrs = (sum_hrs - max_hrs - min_hrs) / (hrs_num - 2); + + uint8_t valid_count = hrs_num - 2; + avg_hrs = (sum_hrs - max_hrs - min_hrs) / valid_count; + // printf("max_hrs[%d],min_hrs[%d],avg_hrs[%d]\n",max_hrs,min_hrs,avg_hrs); } } + void hr_alg_task(void) { if(Check_alg_enable()) @@ -581,18 +590,24 @@ void hr_alg_task(void) #ifdef SUPPORT_PPG_SERVICE time_cnt++; - if(time_cnt > 13) - { -#ifdef SUPPORT_CYWEE_SERVICE - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CHECK_ACC, NULL); // 检查gsensor是否停止 -#endif - } +// if(time_cnt > 15) +// { +// #ifdef SUPPORT_CYWEE_SERVICE +// do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CHECK_ACC, NULL); // 检查gsensor是否停止 +// #endif +// } if(time_cnt >= 20) { + time_cnt = 0; // ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); - +#ifdef SUPPORT_CYWEE_SERVICE + // if(uapi_dev_runtime_get_train_status()) + { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CHECK_ACC, NULL); // 检查gsensor是否停止 + } +#endif uint8_t data = (uint8_t)hr; if(data > 30 && data < 220) @@ -603,7 +618,6 @@ void hr_alg_task(void) // data = cywee_wear_status; // func(PPG_MSG_TYPE_WEARSTAT_UPDATE, &data, 1); - time_cnt = 0; #ifdef SUPPORT_PPG_BLE_SERVICE if(uapi_dev_runtime_get_hrs_ble_status()) @@ -612,12 +626,6 @@ void hr_alg_task(void) } #endif -#ifdef SUPPORT_CYWEE_SERVICE - // if(uapi_dev_runtime_get_train_status()) - { - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CHECK_ACC, NULL); // 检查gsensor是否停止 - } -#endif } @@ -942,6 +950,17 @@ void spo2_alg_task(void) #ifdef SUPPORT_PPG_SERVICE time_cnt++; + if(time_cnt >= 20) + { + time_cnt = 0; + // ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); +#ifdef SUPPORT_CYWEE_SERVICE + // if(uapi_dev_runtime_get_train_status()) + { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CHECK_ACC, NULL); // 检查gsensor是否停止 + } +#endif + } // ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); // if(func != NULL && time_cnt >= 25) @@ -1499,9 +1518,10 @@ static void process(uint64_t timestamp) ppg_mems_data.duration = duration; ppg_mems_data.ppg_data = ppg_data ; - ppg_mems_data.touch_flag = touch_flag ; + + ppg_mems_data.touch_flag = history_wear_status ; ppg_mems_data.ppg_frame_count = _main.ppg_frame_count; //SD-revise-20200320 - + pah_push(&ppg_mems_data); #ifdef PPG_MEMS_Synchronize @@ -1523,13 +1543,13 @@ static void process(uint64_t timestamp) if (_main.is_Auto_mode || _main.touch_is_enabled)//SD-reivse-20191205 { - if ( _main.touch_last_is_touched != touch_flag) + if ( _main.touch_last_is_touched != history_wear_status) { - _main.touch_last_is_touched = touch_flag; + _main.touch_last_is_touched = history_wear_status; - report_touch_data(timestamp, &touch_flag); + report_touch_data(timestamp, &history_wear_status); - bool is_touched = (touch_flag >= 1); + bool is_touched = (history_wear_status >= 1); if (_main.is_Auto_mode && is_touched)//SD-revise-20191205 { @@ -1758,9 +1778,8 @@ void pah8009_int_handler(void) void pah8009_check_int(void) { - if(work_mode != 1) + if(work_mode > 3 || work_mode < 1) { - // printf("work_mode != 1\n"); return; } -- 2.17.1