From 6c412d67219f0e415e4e3f8672e8e00e5f7cdd3c Mon Sep 17 00:00:00 2001 From: 1624952103 Date: Thu, 12 Feb 2026 18:03:16 +0800 Subject: [PATCH] =?utf8?q?=E6=8F=90=E9=AB=98ppg=E4=BC=98=E5=85=88=E7=BA=A7?= =?utf8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E5=BF=83=E7=8E=87=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c | 81 ++++++++++++------- .../drivers/ppg/service/ppg_service.cpp | 2 +- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c index ebdb54683..26553a29b 100644 --- a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c +++ b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c @@ -69,7 +69,7 @@ static uint8_t living_status = 0; static gsenson_t gsensordata[32]; #endif -#define HRS_WINDOW_SIZE 5 +#define HRS_WINDOW_SIZE 7 static uint8_t hrs_num = 0; static int32_t sum_hrs = 0; static int32_t hrs_data[7] = {0}; @@ -81,6 +81,8 @@ static uint8_t time_cnt = 0; // static uint8_t wear_cnt = 0; static uint32_t last_system_time = 0; +static uint8_t last_hrs = 0; + uint8_t alg_ram[11 * 1024] __attribute__((aligned(4))); @@ -1364,6 +1366,19 @@ static void get_avg_hrs(uint8_t hrs) uint8_t valid_count = hrs_num - 2; avg_hrs = (sum_hrs - max_hrs - min_hrs) / valid_count; + + if (last_hrs >= 30 && last_hrs <= 210) + { + int16_t diff = avg_hrs - last_hrs; + if (abs(diff) > 10) + { + if (diff > 0) + avg_hrs = last_hrs + 5; + else + avg_hrs = last_hrs - 5; + } + } + last_hrs = avg_hrs; // printf("max_hrs[%d],min_hrs[%d],avg_hrs[%d]\n",max_hrs,min_hrs,avg_hrs); } } @@ -1460,52 +1475,58 @@ void hx3695_alg_send_data(ppg_sensor_data_t *ppg_sensor_dat, WORK_MODE_T mode, u DEBUG_PRINTF("HRS: %d %d\r\n",hrs_result.data_cnt, hrs_result.hr_result); // printf("hr:%d, living:%d, wear_status:%d\n", hrs_result.hr_result,hrs_result.living_status,wear_status); - if(uapi_dev_runtime_get_train_status()) - { - if(hrs_result.hr_result >= 30 && hrs_result.hr_result <= 210) - get_avg_hrs(hrs_result.hr_result); - } - else + time_cnt++; + + if(time_cnt >= 3) { - if(hrs_result.living_status == MSG_LIVING_TRUE) + time_cnt = 0; + if(uapi_dev_runtime_get_train_status()) { - 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; - #ifdef SUPPORT_CYWEE_SERVICE - cywee_wear_status_update(&living_status); - #endif } - else if(hrs_result.living_status == MSG_LIVING_FAIL) + else { - living_wear_cnt++; - if(living_wear_cnt >= 5) + if(hrs_result.living_status == MSG_LIVING_TRUE) { - avg_hrs = 0; - living_status = 2; - wear_status = 0; - wear_status_pre = 0; - // hx3695_unwearstatus_update(); + 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; #ifdef SUPPORT_CYWEE_SERVICE cywee_wear_status_update(&living_status); #endif + } + else if(hrs_result.living_status == MSG_LIVING_FAIL) + { + living_wear_cnt++; + if(living_wear_cnt >= 5) + { + avg_hrs = 0; + living_status = 2; + wear_status = 0; + wear_status_pre = 0; + // hx3695_unwearstatus_update(); + + #ifdef SUPPORT_CYWEE_SERVICE + cywee_wear_status_update(&living_status); + #endif + living_wear_cnt = 0; + } + } + else + { living_wear_cnt = 0; + living_status = 0; } } - else - { - living_wear_cnt = 0; - living_status = 0; - } } - time_cnt++; + // time_cnt++; // if(time_cnt >= 3) { - time_cnt = 0; + // time_cnt = 0; #ifdef SUPPORT_PPG_BLE_SERVICE #if 0 diff --git a/code/sdk/zhihui/drivers/ppg/service/ppg_service.cpp b/code/sdk/zhihui/drivers/ppg/service/ppg_service.cpp index cf3beb626..07c93b3a1 100644 --- a/code/sdk/zhihui/drivers/ppg/service/ppg_service.cpp +++ b/code/sdk/zhihui/drivers/ppg/service/ppg_service.cpp @@ -229,7 +229,7 @@ errcode_t uapi_ppg_service_init(void) taskcfg.create_queue_handle = create_ppg_queue; taskcfg.attr.name="ppg_service"; - taskcfg.attr.priority = osPriorityAboveNormal2; + taskcfg.attr.priority = osPriorityAboveNormal3; taskcfg.attr.stack_size = PPG_SERVICE_TASK_SIZE; taskcfg.func = ppg_service_check_task; -- 2.17.1