Merge #1462 into sdk602patch0911 from refs/changes/1462/head
author彭磊 <1624952103@qq.com>
Tue, 26 Nov 2024 14:09:48 +0000 (14:09 +0000)
committer袁清梦 <3449750381@qq.com>
Tue, 26 Nov 2024 14:09:48 +0000 (14:09 +0000)
Code review from 彭磊

* refs/changes/1462/head: (7 commits squashed)

  - 优化电量跳电

  - Merge branch &#39;sdk602patch0911&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911

  - 优化睡眠清除历史数据

  - Merge branch &#39;sdk602patch0911&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911

  - Merge branch &#39;sdk602patch0911&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911

  - 优化电池跳电,调整心率检测佩戴阈值,调整采样率,优化计算流程

  - 优化电池跳电,调整心率检测佩戴阈值,调整采样率,优化计算流程(补)

Signed-off-by: aliyun6865282430 <1624952103@qq.com>
Reviewed-by: Caisking <3449750381@qq.com>
Reviewed-by: 罗正 <1732036298@qq.com>
Reviewed-by: aliyun8003852482 <1224667075@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Reviewed-by: aliyun6865282430 <1624952103@qq.com>
Merged-by: Caisking <3449750381@qq.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1462
code/sdk/application/battery/service/battery_driver.cpp
code/sdk/application/battery/service/battery_service.cpp
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c

index abe7448..d2cfbbd 100644 (file)
@@ -69,6 +69,7 @@ typedef enum {
 
 #include "debug_print.h"
 #include "custom_utils.h"
+#include <math.h>
 
 #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;
index 7f591b6..4110b63 100644 (file)
@@ -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;
 }
 
 
index abafaf5..a6a9d42 100644 (file)
@@ -182,7 +182,7 @@ void clean_sleep_data(void)
     wake_up_timestamp = 0;
     abs_static_timestampe = 0;
     asleep_timestampe = 0;
-    memset(&sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T));
+    memset(sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T));
     memset(time_file_path, 0, sizeof(time_file_path));
     memset(status_file_path, 0, sizeof(status_file_path));
     memset(dir_path, 0, sizeof(dir_path));
index 8bc22fe..a4f63ce 100644 (file)
@@ -43,7 +43,7 @@ int16_t gsen_fifo_x[64]={0};
 int16_t gsen_fifo_y[64]={0};\r
 int16_t gsen_fifo_z[64]={0};\r
 \r
-gsenson_t gsensordata[9];\r
+gsenson_t gsensordata[32];\r
 \r
 static uint8_t msg_count = 0;\r
 \r
@@ -107,8 +107,8 @@ const uint8_t gsen_lv_val = 0;
 uint8_t read_fifo_first_flg = 0;\r
 \r
 //HRS_INFRARED_THRES\r
-const int32_t  hrs_ir_unwear_thres = 8000;\r
-const int32_t  hrs_ir_wear_thres = 10000;\r
+const int32_t  hrs_ir_unwear_thres = 10000;\r
+const int32_t  hrs_ir_wear_thres = 15000;\r
 //HRV_INFRARED_THRES\r
 const int32_t  hrv_ir_unwear_thres = 8000;      //demo143b  25000\r
 const int32_t  hrv_ir_wear_thres = 10000;\r
@@ -118,7 +118,7 @@ const int32_t  spo2_ir_wear_thres = 10000;
 const uint8_t  spo2_ir_wear_offset = 15;\r
 //CHECK_WEAR_MODE_THRES\r
 const int32_t  check_mode_unwear_thre = 20000;\r
-const int32_t  check_mode_wear_thre = 20000;\r
+const int32_t  check_mode_wear_thre = 22000;\r
 \r
 \r
 uint8_t alg_ram[11 * 1024] __attribute__((aligned(4)));\r
@@ -538,7 +538,7 @@ void hx3695_data_reset(void)
 void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt en\r
 {\r
     uint16_t sample_rate = 25;                  /*config the data rate of chip alps2_fm ,uint is Hz*/\r
-    uint32_t prf_clk_num = 32000/sample_rate*24/25;   /*period in clk num, num = Fclk/fs */\r
+    uint32_t prf_clk_num = 32000/sample_rate;   /*period in clk num, num = Fclk/fs */\r
          \r
        uint16_t fifo_watermark= 81 ;\r
     uint8_t adc_rst_post_num=0;       /* 00=16,01=32,10=64,11=128*/      \r
@@ -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\r
 {\r
      uint16_t sample_rate = 25;                  /*config the data rate of chip alps2_fm ,uint is Hz*/\r
-    uint32_t prf_clk_num = 32000/sample_rate*24/25;   /*period in clk num, num = Fclk/fs */\r
+    uint32_t prf_clk_num = 32000/sample_rate;   /*period in clk num, num = Fclk/fs */\r
          \r
        uint16_t fifo_watermark= 250 ;\r
     uint8_t adc_rst_post_num=0;       /* 00=16,01=32,10=64,11=128*/      \r
@@ -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\r
 {\r
    uint16_t sample_rate = 125;                  /*config the data rate of chip alps2_fm ,uint is Hz*/\r
-    uint32_t prf_clk_num = 32000/sample_rate*24/25;  /*period in clk num, num = Fclk/fs */\r
+    uint32_t prf_clk_num = 32000/sample_rate;  /*period in clk num, num = Fclk/fs */\r
          \r
     uint8_t adc_rst_post_num=0;       /* 00=16,01=32,10=64,11=128*/      \r
          uint8_t samp_delay_leden_num = 0; /* 00=8,01=16,10=32,11=64*/ \r
@@ -1809,7 +1809,7 @@ void hx3695_hrv_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion r
 void hx3695_check_touch_init(void) //\r
 {     \r
          uint16_t sample_rate = 5;                  /*config the data rate of chip alps2_fm ,uint is Hz*/\r
-    uint32_t prf_clk_num = 32000/sample_rate*24/25;   /*period in clk num, num = Fclk/fs */\r
+    uint32_t prf_clk_num = 32000/sample_rate;   /*period in clk num, num = Fclk/fs */\r
          \r
     uint16_t fifo_watermark= 250 ;\r
     uint8_t adc_rst_post_num= 0;       /* 00=16,01=32,10=64,11=128*/      \r
@@ -2839,10 +2839,10 @@ void hx3695_hrs_ppg_Int_handle(void)
     //PRINT("*count : %d \r\n",*count);\r
 \r
     //count7-9 为捕捉到的绿光值正常数据数量范围,不在此范围,心率数据不准,直接返回.\r
-    if(*count < 7 || *count > 9) \r
-    {\r
-        return;\r
-    }\r
+    // if(*count < 7 || *count > 9) \r
+    // {\r
+    //     return;\r
+    // }\r
     memset(gsensordata,0.0f,sizeof(gsenson_t) * *count);\r
 \r
     gsensor_get_n_data(*count,gsensordata);  \r
index 5f41645..09e9a46 100644 (file)
@@ -182,20 +182,21 @@ hx3695_wear_msg_code_t check_touch_alg(int32_t ir_data)
     // uint32_t tm;\r
     // uapi_get_timestampe_ss(&tm);\r
     // CWM_OS_dbgPrintf("ir_data : %d tm : %d\r\n",ir_data,tm);\r
-    if(ir_data > 60000)\r
-    {\r
-        touch_cnt = 0;\r
-        if(notouch_cnt>=2)\r
-        {\r
-            hx3695_wear_status = MSG_NO_WEAR;\r
-            notouch_cnt=0;\r
-        }\r
-        else\r
-        {\r
-            notouch_cnt++;\r
-        }\r
-    }\r
-    else if(ir_data>check_mode_wear_thre && ir_data < 60000)\r
+    // if(ir_data > 60000)\r
+    // {\r
+    //     touch_cnt = 0;\r
+    //     if(notouch_cnt>=2)\r
+    //     {\r
+    //         hx3695_wear_status = MSG_NO_WEAR;\r
+    //         notouch_cnt=0;\r
+    //     }\r
+    //     else\r
+    //     {\r
+    //         notouch_cnt++;\r
+    //     }\r
+    // }\r
+    // else\r
+     if(ir_data>check_mode_wear_thre)\r
     {\r
         notouch_cnt = 0;\r
         if(touch_cnt>=2)\r
index fe82912..04fd3f8 100644 (file)
@@ -442,7 +442,7 @@ HRS_CAL_SET_T   PPG_hrs_agc(void)
 void hx3695_hrs_cal_init(void)\r
 {\r
     uint16_t sample_rate = 200;     //200                  /*config the data rate of chip alps2_fm ,uint is Hz*/\r
-    uint32_t prf_clk_num = 32000/sample_rate*24/25;        /*period in clk num, num = Fclk/fs */\r
+    uint32_t prf_clk_num = 32000/sample_rate;        /*period in clk num, num = Fclk/fs */\r
                uint8_t data_avg_num = 0;\r
     hx3695_write_reg(0X2a, (uint8_t)prf_clk_num);    // prf bit<7:0>\r
     hx3695_write_reg(0X2b, (uint8_t)(prf_clk_num>>8)); // prf bit<15:8>\r
@@ -563,7 +563,7 @@ void hx3695_hrs_low_power(void)
 {\r
     uint16_t sample_rate = 5;                       /*config the data rate of chip alps2_fm ,uint is Hz*/\r
     uint8_t data_avg_num = 0;         /* 0 = 1 ; 1 = 2; 2 =4 ; 3 =8 ; 4 =16 ;*/\r
-    uint32_t prf_clk_num = 32000/sample_rate*24/25;       /*period in clk num, num = Fclk/fs */\r
+    uint32_t prf_clk_num = 32000/sample_rate;       /*period in clk num, num = Fclk/fs */\r
     \r
     uint8_t phase2_offset_idac = 0; /* 0~127 = 0 ~ 32ua , step = 0.25ua */\r
          uint8_t phase5_offset_idac = 0; /* 0~127 = 0 ~ 32ua , step = 0.25ua */\r
@@ -902,7 +902,7 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat)
     int32_t Ir_src_data;\r
     bool recal = false;\r
     uint8_t size = 0;\r
-         uint16_t  data_count = 0;\r
+         uint8_t  data_count = 0;\r
     uint8_t size_byte = 0;\r
     int32_t *PPG_buf =  &(s_dat->green_data[0]);\r
     int32_t *ir_buf  =  &(s_dat->ir_data[0]);  \r
@@ -919,7 +919,11 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat)
     }  \r
 //    TYHX_LOG("ppg_state: %d ,hrs_cal_state:  %d\r\n",s_ppg_state,hrs_cal_state);             \r
                    data_count = hx3695_read_fifo_data(s_buf,hrs_phase_num,1); \r
-                   //SEGGER_RTT_printf(0,"ppg data size: %d %d\r\n", data_count,hrs_phase_num);\r
+\r
+        if(data_count > 20)\r
+          return 0;\r
+\r
+                   // PRINT("ppg data size: %d %d\r\n", data_count,hrs_phase_num);\r
 //                             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));\r
         s_dat->count =  data_count; \r
 \r
@@ -935,7 +939,7 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat)
             PPG_buf[i] = PPG_src_data * 2;\r
             ir_buf[i] = Ir_src_data;        //Ir_src_data;\r
 //                                     SEGGER_RTT_printf(0,"PPG_data:  %d , PPG_src_data2: %d\r\n", PPG_src_data,PPG_src_data2);\r
-                       //my_printf("hx3695 Ir_src_data %d \r\n", Ir_src_data);\r
+                       // PRINT("hx3695 Ir_src_data %d \r\n", Ir_src_data);\r
             hx3695_hrs_wear_mode_check(HRS_MODE,Ir_src_data); \r
 \r
         }\r