From 361b139d4f538b0fbb03373718c787e070de96fe Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Thu, 20 Nov 2025 18:20:46 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96272=20=E5=BF=83=E7=8E=87?= =?utf8?q?=E6=B4=BB=E4=BD=93=E6=A3=80=E6=B5=8B=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c | 84 ++++++++++++--------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c index 6e586bf12..bf5f5c2a9 100644 --- a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c +++ b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c @@ -56,9 +56,20 @@ static uint8_t spo2_ret = 0; static uint8_t hrv_ret = 0; static int32_t factory_data = 0; static uint8_t hx3695_chip_id = 0; +static uint8_t living_wear_cnt = 0; +static uint8_t living_status = 0; #ifdef SUPPORT_CYWEE_SERVICE static gsenson_t gsensordata[32]; #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 = 0; +static uint8_t avg_hrs = 0; + // static uint8_t his_wear = 2; // static uint8_t wear_cnt = 0; @@ -493,11 +504,18 @@ bool hx3695_check_wear(ppg_sensor_data_t *ppg_sensor_dat) if(wear_status_pre != wear_status) { - // printf("wear_status:%d\n",wear_status); - wear_status_pre = wear_status; + if(uapi_dev_runtime_get_train_status() && !wear_status) + avg_hrs = 0; + + if(living_status != 2) + { + wear_status_pre = wear_status; #ifdef SUPPORT_CYWEE_SERVICE - cywee_wear_status_update(&wear_status); + cywee_wear_status_update(&wear_status); #endif + } + // printf("wear_status:%d\n",wear_status); + // if(wear_status == MSG_NO_WEAR) // { // hx3695_wear_low_power(ppg_sensor_dat); @@ -1232,16 +1250,6 @@ void nrf_gpioint_handle(void) hx3695_agc_Int_handle(&ppg_sensor_data); } - - -#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 = 0; -static uint8_t avg_hrs = 0; - static void get_avg_hrs(uint8_t hrs) { @@ -1375,14 +1383,33 @@ void hx3695_alg_send_data(ppg_sensor_data_t *ppg_sensor_dat, WORK_MODE_T mode, u //tyhx_hrs_alg_send_data(ppg_sensor_dat->led_data[0].data_val,data_count, gsen_data_x_fifo, gsen_data_y_fifo, gsen_data_z_fifo); hrs_result = tyhx_hrs_alg_get_results(); DEBUG_PRINTF("HRS: %d %d\r\n",hrs_result.data_cnt, hrs_result.hr_result); - // printf("hr:%d, living:%d\n", hrs_result.hr_result,hrs_result.living_status); + // printf("hr:%d, living:%d, wear_status:%d\n", hrs_result.hr_result,hrs_result.living_status,wear_status); if(hrs_result.living_status == MSG_LIVING_TRUE) { - get_avg_hrs(hrs_result.hr_result); + living_wear_cnt = 0; + + if(hrs_result.hr_result >= 30 && hrs_result.hr_result <= 210) + get_avg_hrs(hrs_result.hr_result); + + living_status = 1; } else if(hrs_result.living_status == MSG_LIVING_FAIL) { - avg_hrs = 0; + living_wear_cnt++; + if(living_wear_cnt >= 5) + { + avg_hrs = 0; + living_status = 2; + wear_status = 0; + wear_status_pre = 0; + hx3695_unwearstatus_update(); + living_wear_cnt = 0; + } + } + else + { + living_wear_cnt = 0; + living_status = 0; } break; @@ -1487,25 +1514,10 @@ void hx3695_wearstatus_update(void) //脱腕上报未佩戴信息 void hx3695_unwearstatus_update(void) { - // hx3695_msg_callback_t func = hx3695_get_send_msg_callback_func(); - // if(func != NULL && !uapi_dev_runtime_get_train_status()) - // { - // hrsresult.lastesthrs = 0; - // hrsresult.wearstatus = 0; - // //为了主界面脱腕灵敏;需要增加未佩戴 - // func(HX3695_MSG_TYPE_HRS_UPDATE, &hrsresult, sizeof(FT_CUSTOM_RESULTS_t)); - // func(HX3695_MSG_TYPE_WEARSTAT_UPDATE, &hrsresult,sizeof(FT_CUSTOM_RESULTS_t)); - // func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t)); - // func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t)); - // } - - if(uapi_dev_runtime_get_train_status()) - { - wear_result = 0; - hx3695_wearstatus_update(); - avg_hrs = 0; - - } + uint8_t wear = 2; +#ifdef SUPPORT_CYWEE_SERVICE + cywee_wear_status_update(&wear); +#endif } void wear_mode_timeout_handler(void * p_context) @@ -1584,6 +1596,8 @@ void hx3695_control(char *mode,uint8_t enable) left = 0; right = 0; avg_hrs = 0; + living_wear_cnt = 0; + living_status = 0; // wear_cnt = 0; #endif }else if(md == HRV_MODE) -- 2.17.1