From 327fb8d7fc1c1582951de118e09c104d659f0eb0 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 26 Nov 2024 17:38:37 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E7=94=B5=E6=B1=A0=E8=B7=B3?= =?utf8?q?=E7=94=B5=EF=BC=8C=E8=B0=83=E6=95=B4=E5=BF=83=E7=8E=87=E6=A3=80?= =?utf8?q?=E6=B5=8B=E4=BD=A9=E6=88=B4=E9=98=88=E5=80=BC=EF=BC=8C=E8=B0=83?= =?utf8?q?=E6=95=B4=E9=87=87=E6=A0=B7=E7=8E=87=EF=BC=8C=E4=BC=98=E5=8C=96?= =?utf8?q?=E8=AE=A1=E7=AE=97=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../battery/service/battery_driver.cpp | 13 ++++++--- .../battery/service/battery_service.cpp | 5 +++- .../drivers/peripheral/ppg/hx3695/hx3695.c | 22 +++++++------- .../ppg/hx3695/hx3695_check_touch.c | 29 ++++++++++--------- .../peripheral/ppg/hx3695/hx3695_hrs_agc.c | 10 +++---- 5 files changed, 44 insertions(+), 35 deletions(-) diff --git a/code/sdk/application/battery/service/battery_driver.cpp b/code/sdk/application/battery/service/battery_driver.cpp index abe74488f..d2cfbbd9d 100644 --- a/code/sdk/application/battery/service/battery_driver.cpp +++ b/code/sdk/application/battery/service/battery_driver.cpp @@ -69,6 +69,7 @@ typedef enum { #include "debug_print.h" #include "custom_utils.h" +#include #define HAL_ADC_SAMPLE_NUMBER_CONFIG_0 10 /* Channel with buffer manual sample average number. */ #define HAL_ADC_SAMPLE_NUMBER_CONFIG_1 10 /* Channel without buffer manual sample average number. */ @@ -430,13 +431,15 @@ static int battery_get_percent_by_voltage(float voltage) if(get_charge_stat()) { - if(history_percent > percent) + if(history_percent > percent && abs(history_percent - percent) < 10) + // if(history_percent > percent) { percent = history_percent; break; } //电量均匀增加 - else if(percent > history_percent && history_percent) + else if(percent > history_percent && history_percent && abs(history_percent - percent) < 10) + // else if(percent > history_percent && history_percent) { history_percent++; percent = history_percent; @@ -446,13 +449,15 @@ static int battery_get_percent_by_voltage(float voltage) } else { - if(history_percent < percent && history_percent != 0) + if(history_percent < percent && history_percent != 0 && abs(history_percent - percent) < 10) + // if(history_percent < percent && history_percent != 0) { percent = history_percent; break; } //电量均匀减少 - else if(history_percent > percent) + else if(history_percent > percent && abs(history_percent - percent) < 10) + // else if(history_percent > percent) { history_percent--; percent = history_percent; diff --git a/code/sdk/application/battery/service/battery_service.cpp b/code/sdk/application/battery/service/battery_service.cpp index 7f591b6da..4110b636f 100644 --- a/code/sdk/application/battery/service/battery_service.cpp +++ b/code/sdk/application/battery/service/battery_service.cpp @@ -172,7 +172,10 @@ uint8_t battery_get_percent_onstart(void) uint16_t len = 1; uapi_get_file_data("/user/userdata/battery.bin",&percent,&len); PRINT("battery_get_percent_onstart : %d",percent); - return percent; + if(percent <= 100 && percent >= 0) + return percent; + else + return 0; } diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 8bc22fe68..f8bc4ec94 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -107,8 +107,8 @@ const uint8_t gsen_lv_val = 0; uint8_t read_fifo_first_flg = 0; //HRS_INFRARED_THRES -const int32_t hrs_ir_unwear_thres = 8000; -const int32_t hrs_ir_wear_thres = 10000; +const int32_t hrs_ir_unwear_thres = 10000; +const int32_t hrs_ir_wear_thres = 15000; //HRV_INFRARED_THRES const int32_t hrv_ir_unwear_thres = 8000; //demo143b 25000 const int32_t hrv_ir_wear_thres = 10000; @@ -118,7 +118,7 @@ const int32_t spo2_ir_wear_thres = 10000; const uint8_t spo2_ir_wear_offset = 15; //CHECK_WEAR_MODE_THRES const int32_t check_mode_unwear_thre = 20000; -const int32_t check_mode_wear_thre = 20000; +const int32_t check_mode_wear_thre = 22000; uint8_t alg_ram[11 * 1024] __attribute__((aligned(4))); @@ -538,7 +538,7 @@ void hx3695_data_reset(void) void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt en { uint16_t sample_rate = 25; /*config the data rate of chip alps2_fm ,uint is Hz*/ - uint32_t prf_clk_num = 32000/sample_rate*24/25; /*period in clk num, num = Fclk/fs */ + uint32_t prf_clk_num = 32000/sample_rate; /*period in clk num, num = Fclk/fs */ uint16_t fifo_watermark= 81 ; uint8_t adc_rst_post_num=0; /* 00=16,01=32,10=64,11=128*/ @@ -952,7 +952,7 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion ready interupt en { uint16_t sample_rate = 25; /*config the data rate of chip alps2_fm ,uint is Hz*/ - uint32_t prf_clk_num = 32000/sample_rate*24/25; /*period in clk num, num = Fclk/fs */ + uint32_t prf_clk_num = 32000/sample_rate; /*period in clk num, num = Fclk/fs */ uint16_t fifo_watermark= 250 ; uint8_t adc_rst_post_num=0; /* 00=16,01=32,10=64,11=128*/ @@ -1381,7 +1381,7 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion void hx3695_hrv_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion ready interupt en { uint16_t sample_rate = 125; /*config the data rate of chip alps2_fm ,uint is Hz*/ - uint32_t prf_clk_num = 32000/sample_rate*24/25; /*period in clk num, num = Fclk/fs */ + uint32_t prf_clk_num = 32000/sample_rate; /*period in clk num, num = Fclk/fs */ uint8_t adc_rst_post_num=0; /* 00=16,01=32,10=64,11=128*/ uint8_t samp_delay_leden_num = 0; /* 00=8,01=16,10=32,11=64*/ @@ -1809,7 +1809,7 @@ void hx3695_hrv_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion r void hx3695_check_touch_init(void) // { uint16_t sample_rate = 5; /*config the data rate of chip alps2_fm ,uint is Hz*/ - uint32_t prf_clk_num = 32000/sample_rate*24/25; /*period in clk num, num = Fclk/fs */ + uint32_t prf_clk_num = 32000/sample_rate; /*period in clk num, num = Fclk/fs */ uint16_t fifo_watermark= 250 ; uint8_t adc_rst_post_num= 0; /* 00=16,01=32,10=64,11=128*/ @@ -2839,10 +2839,10 @@ void hx3695_hrs_ppg_Int_handle(void) //PRINT("*count : %d \r\n",*count); //count7-9 为捕捉到的绿光值正常数据数量范围,不在此范围,心率数据不准,直接返回. - if(*count < 7 || *count > 9) - { - return; - } + // if(*count < 7 || *count > 9) + // { + // return; + // } memset(gsensordata,0.0f,sizeof(gsenson_t) * *count); gsensor_get_n_data(*count,gsensordata); diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c index 5f41645a8..09e9a466d 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c @@ -182,20 +182,21 @@ hx3695_wear_msg_code_t check_touch_alg(int32_t ir_data) // uint32_t tm; // uapi_get_timestampe_ss(&tm); // CWM_OS_dbgPrintf("ir_data : %d tm : %d\r\n",ir_data,tm); - if(ir_data > 60000) - { - touch_cnt = 0; - if(notouch_cnt>=2) - { - hx3695_wear_status = MSG_NO_WEAR; - notouch_cnt=0; - } - else - { - notouch_cnt++; - } - } - else if(ir_data>check_mode_wear_thre && ir_data < 60000) + // if(ir_data > 60000) + // { + // touch_cnt = 0; + // if(notouch_cnt>=2) + // { + // hx3695_wear_status = MSG_NO_WEAR; + // notouch_cnt=0; + // } + // else + // { + // notouch_cnt++; + // } + // } + // else + if(ir_data>check_mode_wear_thre) { notouch_cnt = 0; if(touch_cnt>=2) diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c index fe829129e..b229739c3 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c @@ -442,7 +442,7 @@ HRS_CAL_SET_T PPG_hrs_agc(void) void hx3695_hrs_cal_init(void) { uint16_t sample_rate = 200; //200 /*config the data rate of chip alps2_fm ,uint is Hz*/ - uint32_t prf_clk_num = 32000/sample_rate*24/25; /*period in clk num, num = Fclk/fs */ + uint32_t prf_clk_num = 32000/sample_rate; /*period in clk num, num = Fclk/fs */ uint8_t data_avg_num = 0; hx3695_write_reg(0X2a, (uint8_t)prf_clk_num); // prf bit<7:0> hx3695_write_reg(0X2b, (uint8_t)(prf_clk_num>>8)); // prf bit<15:8> @@ -563,7 +563,7 @@ void hx3695_hrs_low_power(void) { uint16_t sample_rate = 5; /*config the data rate of chip alps2_fm ,uint is Hz*/ uint8_t data_avg_num = 0; /* 0 = 1 ; 1 = 2; 2 =4 ; 3 =8 ; 4 =16 ;*/ - uint32_t prf_clk_num = 32000/sample_rate*24/25; /*period in clk num, num = Fclk/fs */ + uint32_t prf_clk_num = 32000/sample_rate; /*period in clk num, num = Fclk/fs */ uint8_t phase2_offset_idac = 0; /* 0~127 = 0 ~ 32ua , step = 0.25ua */ uint8_t phase5_offset_idac = 0; /* 0~127 = 0 ~ 32ua , step = 0.25ua */ @@ -902,7 +902,7 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat) int32_t Ir_src_data; bool recal = false; uint8_t size = 0; - uint16_t data_count = 0; + uint8_t data_count = 0; uint8_t size_byte = 0; int32_t *PPG_buf = &(s_dat->green_data[0]); int32_t *ir_buf = &(s_dat->ir_data[0]); @@ -919,7 +919,7 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat) } // TYHX_LOG("ppg_state: %d ,hrs_cal_state: %d\r\n",s_ppg_state,hrs_cal_state); data_count = hx3695_read_fifo_data(s_buf,hrs_phase_num,1); - //SEGGER_RTT_printf(0,"ppg data size: %d %d\r\n", data_count,hrs_phase_num); + // PRINT("ppg data size: %d %d\r\n", data_count,hrs_phase_num); // SEGGER_RTT_printf(0,"af_hx3695_read_fifo_data:::%d %d %d\r\n", hx3695_read_reg(0X2a),hx3695_read_reg(0X2b),hx3695_read_reg(0X2c)); s_dat->count = data_count; @@ -935,7 +935,7 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat) PPG_buf[i] = PPG_src_data * 2; ir_buf[i] = Ir_src_data; //Ir_src_data; // SEGGER_RTT_printf(0,"PPG_data: %d , PPG_src_data2: %d\r\n", PPG_src_data,PPG_src_data2); - //my_printf("hx3695 Ir_src_data %d \r\n", Ir_src_data); + // PRINT("hx3695 Ir_src_data %d \r\n", Ir_src_data); hx3695_hrs_wear_mode_check(HRS_MODE,Ir_src_data); } -- 2.17.1