优化272 心率活体检测处理
authorpenglei <1624952103@qq.com>
Thu, 20 Nov 2025 10:20:46 +0000 (18:20 +0800)
committerpenglei <1624952103@qq.com>
Thu, 20 Nov 2025 10:20:46 +0000 (18:20 +0800)
code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c

index 6e586bf..bf5f5c2 100644 (file)
@@ -56,9 +56,20 @@ static uint8_t spo2_ret = 0;
 static uint8_t hrv_ret = 0;\r
 static int32_t factory_data = 0;\r
 static uint8_t hx3695_chip_id = 0;\r
+static uint8_t living_wear_cnt = 0;\r
+static uint8_t living_status = 0;\r
 #ifdef SUPPORT_CYWEE_SERVICE\r
 static gsenson_t gsensordata[32];\r
 #endif\r
+\r
+#define HRS_WINDOW_SIZE 5\r
+static uint8_t hrs_num = 0;\r
+static int32_t sum_hrs = 0;\r
+static int32_t hrs_data[7] = {0};\r
+static uint8_t left = 0;\r
+static uint8_t right = 0;\r
+static uint8_t avg_hrs = 0;\r
+\r
 // static uint8_t his_wear = 2;\r
 // static uint8_t wear_cnt = 0;\r
 \r
@@ -493,11 +504,18 @@ bool hx3695_check_wear(ppg_sensor_data_t *ppg_sensor_dat)
 \r
         if(wear_status_pre != wear_status)\r
         {\r
-            // printf("wear_status:%d\n",wear_status);\r
-            wear_status_pre = wear_status;\r
+            if(uapi_dev_runtime_get_train_status() && !wear_status)\r
+                avg_hrs = 0;\r
+\r
+            if(living_status != 2)\r
+            {\r
+                wear_status_pre = wear_status;\r
 #ifdef SUPPORT_CYWEE_SERVICE\r
-            cywee_wear_status_update(&wear_status);\r
+                cywee_wear_status_update(&wear_status);\r
 #endif\r
+            }\r
+            // printf("wear_status:%d\n",wear_status);\r
+\r
             // if(wear_status == MSG_NO_WEAR)\r
             // {\r
             //     hx3695_wear_low_power(ppg_sensor_dat);                 \r
@@ -1232,16 +1250,6 @@ void nrf_gpioint_handle(void)
     hx3695_agc_Int_handle(&ppg_sensor_data);\r
 }\r
 \r
-\r
-\r
-#define HRS_WINDOW_SIZE 5\r
-static uint8_t hrs_num = 0;\r
-static int32_t sum_hrs = 0;\r
-static int32_t hrs_data[7] = {0};\r
-static uint8_t left = 0;\r
-static uint8_t right = 0;\r
-static uint8_t avg_hrs = 0;\r
-\r
 static void get_avg_hrs(uint8_t hrs)\r
 {\r
 \r
@@ -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);\r
                        hrs_result = tyhx_hrs_alg_get_results();\r
                        DEBUG_PRINTF("HRS: %d %d\r\n",hrs_result.data_cnt, hrs_result.hr_result);\r
-                       // printf("hr:%d, living:%d\n", hrs_result.hr_result,hrs_result.living_status);\r
+                       // printf("hr:%d, living:%d, wear_status:%d\n", hrs_result.hr_result,hrs_result.living_status,wear_status);\r
             if(hrs_result.living_status == MSG_LIVING_TRUE)\r
             {\r
-                get_avg_hrs(hrs_result.hr_result);\r
+                living_wear_cnt = 0;\r
+\r
+                if(hrs_result.hr_result >= 30 && hrs_result.hr_result <= 210)\r
+                    get_avg_hrs(hrs_result.hr_result);\r
+\r
+                living_status = 1;\r
             }\r
             else if(hrs_result.living_status == MSG_LIVING_FAIL)\r
             {\r
-                avg_hrs = 0;\r
+                living_wear_cnt++;\r
+                if(living_wear_cnt >= 5)\r
+                {\r
+                    avg_hrs = 0;\r
+                    living_status = 2;\r
+                    wear_status = 0;\r
+                    wear_status_pre = 0;\r
+                    hx3695_unwearstatus_update();\r
+                    living_wear_cnt = 0;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                living_wear_cnt = 0;\r
+                living_status = 0;\r
             }\r
 \r
                        break;\r
@@ -1487,25 +1514,10 @@ void hx3695_wearstatus_update(void)
   //脱腕上报未佩戴信息\r
 void hx3695_unwearstatus_update(void)\r
 {\r
-  // hx3695_msg_callback_t func =  hx3695_get_send_msg_callback_func();\r
-  // if(func != NULL && !uapi_dev_runtime_get_train_status())\r
-  // {\r
-  //   hrsresult.lastesthrs = 0;\r
-  //   hrsresult.wearstatus = 0;\r
-  //   //为了主界面脱腕灵敏;需要增加未佩戴\r
-  //   func(HX3695_MSG_TYPE_HRS_UPDATE, &hrsresult, sizeof(FT_CUSTOM_RESULTS_t));\r
-  //   func(HX3695_MSG_TYPE_WEARSTAT_UPDATE, &hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
-  //   func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
-  //   func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
-  // }\r
-\r
-  if(uapi_dev_runtime_get_train_status())\r
-  {\r
-      wear_result = 0;\r
-      hx3695_wearstatus_update();\r
-      avg_hrs = 0;\r
-\r
-  }\r
+    uint8_t wear = 2;\r
+#ifdef SUPPORT_CYWEE_SERVICE\r
+    cywee_wear_status_update(&wear);\r
+#endif\r
 }         \r
 \r
 void wear_mode_timeout_handler(void * p_context)\r
@@ -1584,6 +1596,8 @@ void hx3695_control(char *mode,uint8_t enable)
             left = 0;\r
             right = 0;\r
             avg_hrs = 0;\r
+            living_wear_cnt = 0;\r
+            living_status = 0;\r
             // wear_cnt = 0;\r
 #endif\r
         }else  if(md == HRV_MODE)\r