hx3918活体调试
authorp15692025051 <846603105@qq.com>
Mon, 14 Aug 2023 09:09:57 +0000 (17:09 +0800)
committerp15692025051 <846603105@qq.com>
Mon, 14 Aug 2023 09:09:57 +0000 (17:09 +0800)
2.sdk/Helios_SDK/components/HX3918/hx3918.c
2.sdk/Helios_SDK/components/HX3918/hx3918_factory_test.c
2.sdk/Helios_SDK/components/HX3918/hx3918_hrs_agc.c
2.sdk/Helios_SDK/components/HX3918/hx3918_hrv_agc.c
2.sdk/Helios_SDK/components/HX3918/hx3918_prox.c
2.sdk/Helios_SDK/components/HX3918/hx3918_prox.h
2.sdk/Helios_SDK/components/HX3918/hx3918_spo2_agc.c
2.sdk/Helios_SDK/services/microPython/ports/quectel/core/source/modGsensor_SC7A20.c
2.sdk/Helios_SDK/services/microPython/ports/quectel/core/source/modHsensor_HX3918.c

index ff0f7bc..d293aa8 100644 (file)
@@ -88,22 +88,22 @@ uint8_t low_vbat_flag =0;
 const uint16_t static_thre_val = 150;
 const uint8_t  gsen_lv_val = 0;
 
+
 //HRS_INFRARED_THRES
-const int32_t  hrs_ir_unwear_thres = 3000;
-const int32_t  hrs_ir_wear_thres = 4000;
+const int32_t  hrs_ir_unwear_thres = 5000;
+const int32_t  hrs_ir_wear_thres = 6000;
 //HRV_INFRARED_THRES
-const int32_t  hrv_ir_unwear_thres = 3000;
-const int32_t  hrv_ir_wear_thres = 4000;
+const int32_t  hrv_ir_unwear_thres = 5000;
+const int32_t  hrv_ir_wear_thres = 6000;
 //SPO2_INFRARED_THRES
-const uint8_t  spo2_check_unwear_oft = 10;
-const int32_t  spo2_ir_wear_thres = 2000;
+const uint8_t  spo2_check_unwear_oft = 4;
+const int32_t  spo2_ir_wear_thres = 12000;
 //CHECK_WEAR_MODE_THRES
-const int32_t  check_mode_unwear_thre = 3000;
-const int32_t  check_mode_wear_thre = 4000;
+const int32_t  check_mode_unwear_thre = 5000;
+const int32_t  check_mode_wear_thre = 6000;
 //const int32_t  check_mode_sar_thre = 6000;
 
-//const int32_t  sar_unwear_thres = 2000;
-//const int32_t  sar_wear_thres = 3000;
+
 
 uint8_t alg_ram[11 * 1024] __attribute__((aligned(4)));
 ppg_sensor_data_t ppg_s_dat;
@@ -473,12 +473,16 @@ void Efuse_Mode_Check(void)
     REG_48_E = hx3918_read_reg(0x48);
 
     hx3918_write_reg(0X4B,0x20);
-    hx3918_write_reg(0x45,(REG_45_E+4));
+    hx3918_write_reg(0x45,REG_45_E);
     hx3918_write_reg(0x46,REG_46_E);
     hx3918_write_reg(0x47,REG_47_E);
     hx3918_write_reg(0x48,REG_48_E);
-
     hx3918_write_reg(0X4B,0x00);
+    
+    hx3918_write_reg(0x4d, 0x20);
+    hx3918_write_reg(0x4e, 0x00);
+    hx3918_write_reg(0x4C, 0x00);
+     
 }
 
 bool hx3918_init(WORK_MODE_T mode)
@@ -1153,7 +1157,7 @@ void hx3918_wear_ppg_Int_handle(void)
     if((count)&&(hrsresult.wearstatus == 0))
     {
         //HX3918_LOG("count = %d, ir = %d\r\n",count,ppg_s_dat.s_buf[count-1]);
-        hx3918_auto_cali_backgroud(ppg_s_dat.s_buf[count-1]);
+        //hx3918_auto_cali_backgroud(ppg_s_dat.s_buf[count-1]);
                
     }
        //hx3918_ai_tune_nv(lp[0],bl[0]);
index 76478c3..6bb7142 100644 (file)
@@ -336,9 +336,10 @@ bool hx3918_chip_check_id(void)
     }
     return false;
 }
+factory_result_t factory_reslts = {0,0,0};
 factory_result_t hx3918_factroy_test(uint32_t  test_mode)
 {
-    factory_result_t factory_reslts = {0,0,0};
+    
     int32_t green_buffer[4] = {0,0,0,0};
     int32_t red_buffer[4] = {0,0,0,0};
     int32_t ir_buffer[4] = {0,0,0,0};
index 60d6afd..6ffa92c 100644 (file)
@@ -253,8 +253,8 @@ hx3918_hrs_wear_msg_code_t hx3918_hrs_wear_mode_check(int32_t infrared_data)
     //AGC_LOG("hrs wearstates: hrs_wear_status_pre=%d,hrs_wear_status=%d\r\n",\
     //hrs_wear_status_pre,hrs_wear_status);
 
-       //hrs_wear_status = hx3918_get_wear_result(hrs_wear_status);
-       TYHX_LOG("[hx3918_hrs_wear_mode_check end] final result = %d\r\n",hrs_wear_status);
+       hrs_wear_status = hx3918_get_wear_result(hrs_wear_status);
+       HX3918_LOG("[hx3918_hrs_wear_mode_check end] final result = %d\r\n",hrs_wear_status);
     if(hrs_wear_status_pre != hrs_wear_status)
     {
         hrs_wear_status_pre = hrs_wear_status;
@@ -444,9 +444,7 @@ void hx3918_hrs_cal_off(void) // 20200615 ericy afe cali offline
     hx3918_delay(5);
     hx3918_write_reg(0X4d, 0X00);  //release
     hx3918_delay(5);             //Delay for reset time
-       #if DEBUG_PPG_ONLY
-        hx3918_prox_init();
-    #endif
+    hx3918_prox_init();
     read_fifo_first_flg = 1;
 }
 
@@ -502,9 +500,7 @@ void hx3918_hrs_low_power(void)
     hx3918_delay(5);
 
     calReg.led_cur = 0;
-       #if DEBUG_PPG_ONLY
-        hx3918_prox_init();
-    #endif
+       hx3918_prox_init();
     read_fifo_first_flg = 1;
     AGC_LOG(" chip go to low power mode  \r\n" );
 
@@ -690,7 +686,7 @@ uint8_t hx3918_hrs_read(ppg_sensor_data_t * s_dat)
 
     data_count = hx3918_read_fifo_data(s_buf,2,1);
     s_dat->count =  data_count;
-       TYHX_LOG("\r\n hrs  ir data:    ");
+       HX3918_LOG("hx3918_hrs_read data_count:%d\r\n   ",data_count);
     for (uint8_t i=0; i<data_count; i++)
     {
         PPG_src_data = s_buf[i*2+1];
@@ -698,7 +694,7 @@ uint8_t hx3918_hrs_read(ppg_sensor_data_t * s_dat)
         PPG_buf[i] = 2*PPG_src_data;
         ir_buf[i] = Ir_src_data;
                TYHX_LOG("%d    ",ir_buf[i]);
-        //DEBUG_PRINTF("ppg data size: %d\r\n", Ir_src_data);
+        HX3918_LOG("hx3918_hrs_read:ppg data size: %d\r\n", Ir_src_data);
         hx3918_hrs_wear_mode_check(Ir_src_data);
         
         //DEBUG_PRINTF("%d/%d %d %d\r\n",1+i,data_count,PPG_buf[i],ir_buf[i]);
index 1c4964c..9d39fac 100644 (file)
@@ -279,7 +279,7 @@ hx3918_hrv_wear_msg_code_t hx3918_hrv_wear_mode_check(int32_t infrared_data)
     {
         hrv_wear_status_pre = hrv_wear_status;         
                //TYHX_LOG("[hx3918_hrv_wear_mode_check start] ir wear result = %d\r\n",hrv_wear_status);
-               //hrv_wear_status = hx3918_get_wear_result(hrv_wear_status);
+               hrv_wear_status = hx3918_get_wear_result(hrv_wear_status);
                TYHX_LOG("[hx3918_hrv_wear_mode_check end] final result = %d\r\n",hrv_wear_status);
         if(hrv_wear_status_pre == MSG_HRV_NO_WEAR)
         {
@@ -440,7 +440,7 @@ HRV_CAL_SET_T PPG_hrv_agc(void)
 
 void hx3918_hrv_cal_init(void) // 20200615 ericy afe cali online
 {
-    uint16_t sample_rate = 100;                      /*config the data rate of chip alps2_fm ,uint is Hz*/
+    uint16_t sample_rate = 125;                      /*config the data rate of chip alps2_fm ,uint is Hz*/
     uint32_t prf_clk_num = 32000/sample_rate;        /*period in clk num, num = Fclk/fs */
     uint8_t ps1_cp_avg_num_sel= 0;
     uint8_t ps0_cp_avg_num_sel= 0;
@@ -491,9 +491,7 @@ void hx3918_hrv_cal_off(void) // 20200615 ericy afe cali offline
     hx3918_delay(5);
     hx3918_write_reg(0X4d, 0X00);  //release
     hx3918_delay(5);             //Delay for reset time
-    #if DEBUG_PPG_ONLY
-        hx3918_prox_init();
-    #endif
+    hx3918_prox_init();
     read_fifo_first_flg = 1;
 }
 
@@ -703,9 +701,7 @@ void hx3918_hrv_low_power(void)
     hx3918_write_reg(0X4d, 0X00);  //release
     hx3918_delay(5);
     calReg.led_cur = 0;
-       #if DEBUG_PPG_ONLY
-        hx3918_prox_init();
-    #endif
+       hx3918_prox_init();
 //             hx3918_ppg_timer_cfg(false);
 //    hx3918_agc_timer_cfg(false);
 //             hx3918_gpioint_cfg(true);
index 7fc00e6..a2800ff 100644 (file)
@@ -55,28 +55,26 @@ hx_set_wear_detect_mode(SLEEP_WEAR_MODE)    //
 //#define DIGITAL_DIFF     //Êý×Ö²î·Ö
 
 #ifdef ANALOG_DIFF
-//#define INDEPENDDENT_CH  // ¶ÀÁ¢Í¨µÀºê¶¨Òå, ¾ÍÊÇÒ»¸öPAD¶ÔÓ¦Ò»¸öCH
-#define DIFFERENCE_CH      //²î·ÖͨµÀ¶¨Òå, Á½¸öPAD×÷Ϊһ¸öCHµÄ²î·ÖÕý¶ËºÍ¸º¶Ë, °¤×Ÿ첲µÄÅå´÷ΪÕý¶Ë
+#define INDEPENDDENT_CH  // ¶ÀÁ¢Í¨µÀºê¶¨Òå, ¾ÍÊÇÒ»¸öPAD¶ÔÓ¦Ò»¸öCH
+//#define DIFFERENCE_CH      //²î·ÖͨµÀ¶¨Òå, Á½¸öPAD×÷Ϊһ¸öCHµÄ²î·ÖÕý¶ËºÍ¸º¶Ë, °¤×Ÿ첲µÄÅå´÷ΪÕý¶Ë
 #endif
 
+//#define HRS_VDD_ALWAYS_ON   //HRS Ä£¿é³¤¹©µç
+
 extern uint8_t hx3918_chip_id;   // Ð¾Æ¬ID, Ó¦¸ÃµÈÓÚ0x27
 int16_t nv_wear_offset[2] = {0};    // Ð¾Æ¬²ú²âУ׼µÄÁ½¸öͨµÀµÄOFFSETÖµ, Öµ¼Ç¼ÔÚfashÀïÃæ
-int16_t nv_base_data[2] = {0}; // Ð¾Æ¬²ú²âУ׼µÄÁ½¸öͨµÀµÄ¶Ô¿ÕLPÖµ, Öµ¼Ç¼ÔÚflashÀïÃæ
-uint32_t ai_tune_cnt[2] = {0}; //ai_tune_cnt[0] ¼Ç¼nv_base ×ÔѧϰÏòϸüеĴÎÊý,
-//extern uint16_t sendcnt;     // À¶ÑÀÊý¾Ý²É¼¯¼ÆÊý, Õâ¸öÊDzÉÊýÓõÄ, ¿ÉÒÔ²»ÓÃ
+int16_t nv_base_data[2] = {0};     // Ð¾Æ¬²ú²âУ׼µÄÁ½¸öͨµÀµÄ¶Ô¿ÕLPÖµ, Öµ¼Ç¼ÔÚflashÀïÃæ
+//extern uint16_t sendcnt;    // À¶ÑÀÊý¾Ý²É¼¯¼ÆÊý, Õâ¸öÊDzÉÊýÓõÄ, ¿ÉÒÔ²»ÓÃ
 int16_t gdiff[2] = {0};      // gdiff[0], gdiff[1] ·Ö±ð±£´æCH0, CH1µÄ½á¹û
 int16_t lp[2] = {0};
 int16_t bl[2] = {0};
 
-//flash ¶Áд±äÁ¿, ÒÀ´Î¼Ç¼nv_wear_offset[0],nv_wear_offset[1],nv_base_data[0],nv_base_data[1],ai_tune_cnt[0],ai_tune_cnt[1]
-uint32_t fds_read[6] = {0}; //¶Á³öflash ´æ´¢Êý¾ÝµÄ±äÁ¿;
-uint32_t fds_write[6] = {0}; //дflashµÄ±äÁ¿, flashÀïÃæ·Ö±ð¼Ç¼
+//flash ¶Áд±äÁ¿, ÒÀ´Î¼Ç¼nv_wear_offset[0],nv_wear_offset[1],nv_base_data[0],nv_base_data[1]
+uint32_t fds_read[4] = {0}; //¶Á³öflash ´æ´¢Êý¾ÝµÄ±äÁ¿;
+uint32_t fds_write[4] = {0}; //дflashµÄ±äÁ¿, flashÀïÃæ·Ö±ð¼Ç¼
 
 
 
-//prox_work_mode = RELATIVE_MODE,  Ïà¶Ôֵģʽ, ²âÁ¿½á¹û = LP-BL
-//prox_work_mode = ABSOLUTE_MODE, ¾ø¶Ôֵģʽ, ²âÁ¿½á¹û = LP - NV_BASE;
-uint8_t  prox_work_mode = RELATIVE_MODE;
 uint8_t  is_factory_mode = 0;    // ²ú²âģʽ, ÓÃÀ´¶ÁÈ¡Õû»ú¶Ô¿ÕʱOFFSETºÍ¶Ô¿ÕµÄnv_baseÖµ;
 uint8_t wear_detect_mode = NORMAL_WEAR_MODE;
 
@@ -219,9 +217,9 @@ uint16_t  hx3918_read_offset(uint8_t chx_offset)
         mid =(writeoffset+recordoffset)/2;
         lp = readlp_after_writeoffset(mid,chx_offset);
 
-        if(hx_abs(lp)>1300)
+        if(hx_abs(lp)>READ_DEVATION)
         {
-            if(lp>1300)
+            if(lp>READ_DEVATION)
             {
                 writeoffset = mid+1;
             }
@@ -321,12 +319,22 @@ bool hx3918_prox_reg_init(void)
     write_ok &= hx3918_write_reg(0x53,0x00);    //default??
 
 
-#ifdef INDEPENDDENT_CH //ÓÉʵ¼ÊÓ²¼þ¾ö¶¨, Òª¿´µç·ͼ
-    write_ok &= hx3918_write_reg(0x55,0x0C);   //CS1->CH0
-    write_ok &= hx3918_write_reg(0x57,0x30);   //CS2->CH1
-#elif defined(DIFFERENCE_CH) //ÓÉʵ¼ÊÓ²¼þ¾ö¶¨, Òª¿´µç·ͼ
-    write_ok &= hx3918_write_reg(0x55,0x2c);   //CS1->CH0[P],CS2->CH0[N]
-    write_ok &= hx3918_write_reg(0x57,0x30);   //CS2->CH1
+#ifdef INDEPENDDENT_CH //
+//    write_ok &= hx3918_write_reg(0x55,0x0C);   //CS1->CH0
+                 write_ok &= hx3918_write_reg(0x55,0x03);   //CS0->CH0
+               
+               
+//    write_ok &= hx3918_write_reg(0x57,0x30);   //CS2->CH1    
+//             write_ok &= hx3918_write_reg(0x57,0x03);   //CS0->CH1
+                 write_ok &= hx3918_write_reg(0x57,0x0c);   //CS1->CH1
+               
+#elif defined(DIFFERENCE_CH) //?????????????¡§, ???????¡¤??
+//    write_ok &= hx3918_write_reg(0x55,0x2c);   //CS1->CH0[P],CS2->CH0[N]
+//             write_ok &= hx3918_write_reg(0x55,0x0e);   //CS1->CH0[P],CS0->CH0[N]
+               write_ok &= hx3918_write_reg(0x55,0x0B);   //CS0->CH0[P],CS1->CH0[N]
+//    write_ok &= hx3918_write_reg(0x57,0x30);   //CS2->CH1
+//              write_ok &= hx3918_write_reg(0x57,0x03);   //CS0->CH1
+               write_ok &= hx3918_write_reg(0x57,0x0c);   //CS1->CH1
 #endif
     write_ok &= hx3918_write_reg(0x56,0x00);   //default
     write_ok &= hx3918_write_reg(0x58,0x00);   //default
@@ -354,39 +362,37 @@ bool hx3918_prox_reg_init(void)
 
     write_ok &= hx3918_write_reg(0x7A,0x07);   //²¹³¥µçÈÝУ׼´¥·¢ÉèÖÃ=16384
 
-#ifdef INDEPENDDENT_CH
-
-    prox_work_mode = RELATIVE_MODE;
 
-#endif
-    if (prox_work_mode == RELATIVE_MODE)
+    if(is_factory_mode)
     {
-        TYHX_LOG("RELATIVE_MODE\r\n");
-        write_ok &= hx3918_write_reg(0x70,0xaa);
-        write_ok &= hx3918_write_reg(0x72,0x40);
+       TYHX_LOG("is_factory_mode\r\n");
+
+        write_ok &= hx3918_write_reg(0x70,0x66);
+        write_ok &= hx3918_write_reg(0x72,0x20);
         write_ok &= hx3918_write_reg(0x73,0x04);
         write_ok &= hx3918_write_reg(0x90,0x77);
         write_ok &= hx3918_write_reg(0x8F,0x00);
         write_ok &= hx3918_write_reg(0x95,0x00);
         hx3918_config_thres(CH0,CH0_HIGH_DIFF, CH0_LOW_DIFF,0); // wear0
         hx3918_config_thres(CH1,CH1_HIGH_DIFF, CH1_LOW_DIFF,0); // wear0
+        
     }
     else
     {
-        TYHX_LOG("ABSOLUTE_MODE\r\n");
-        write_ok &= hx3918_write_reg(0x70,0x22);
+        write_ok &= hx3918_write_reg(0x70,0x66);
         write_ok &= hx3918_write_reg(0x72,0x20);
         write_ok &= hx3918_write_reg(0x73,0x02);
-        write_ok &= hx3918_write_reg(0x90,0x07);
+        write_ok &= hx3918_write_reg(0x90,0x77);//0x07
         write_ok &= hx3918_write_reg(0x8F,0x07);
-        write_ok &= hx3918_write_reg(0x95,0x0a);
+        write_ok &= hx3918_write_reg(0x95,0x00);//0x0a
         hx3918_write_offset(nv_wear_offset[0], CH0_OFFSET);
         hx3918_write_offset(nv_wear_offset[1], CH1_OFFSET);
         hx3918_config_thres(CH0,CH0_HIGH_DIFF, CH0_LOW_DIFF,nv_base_data[0]); // wear0
         hx3918_config_thres(CH1,CH1_HIGH_DIFF, CH1_LOW_DIFF,nv_base_data[1]); // wear0
         hx3918_write_reg(0x7A,0x17);
     }
-    write_ok &= hx3918_write_reg(0x6a,0x03); //CH0, CH1 enable
+    
+       write_ok &= hx3918_write_reg(0x6a,0x03); //CH0, CH1 enable
 #endif
     hx3918_delay(50);
     return write_ok;
@@ -402,54 +408,60 @@ bool hx3918_prox_reg_init(void)
 */
 uint8_t hx3918_report_prox_status(void)
 {
-
-
+    static int16_t lp_old[2] = {0};
+    static int16_t bl_old[2] = {0};
+    uint8_t ret = 0; 
     lp[0] = hx3918_read_diff_lp(LP0);
     bl[0] = hx3918_read_raw_bl(BL0);
 
     lp[1] = hx3918_read_diff_lp(LP1);
     bl[1] = hx3918_read_raw_bl(BL1);
 
-    if (prox_work_mode == RELATIVE_MODE)
-    {
-        gdiff[0] = lp[0]- bl[0];
-        gdiff[1] = lp[1]- bl[1];
-    }
+   
+    gdiff[0] = lp[0]- bl[0];
+    gdiff[1] = lp[1]- bl[1];
+   
+   
+    HX3918_LOG("result =       %d      %d      %d      %d      %d      %d\r\n",lp[0],bl[0],lp[1],bl[1],gdiff[0],gdiff[1]);
+    if(gdiff[0]>100)
+        ret = 1;
     else
     {
-        gdiff[0] = lp[0]- nv_base_data[0];
-        gdiff[1] = lp[1]- nv_base_data[1];
-    }
-    //sendDataToClient(lp[0],bl[0],lp[1],bl[1]);
-    if(prox_work_mode==ABSOLUTE_MODE)
-    {
-        TYHX_LOG("[absolute mode]      %d      %d      %d      %d      %d      %d\r\n",lp[0],bl[0],lp[1],bl[1],gdiff[0],nv_base_data[0]);
-    }
-    else
-    {
-        TYHX_LOG("[relatvie mode]      %d      %d      %d      %d      %d      %d\r\n",lp[0],bl[0],lp[1],bl[1],gdiff[0],nv_base_data[0]);
-    }
-
-#ifdef TEMP_COMPENSATION   //ζȲ¹³¥
-    //Õâ¸öÊÇÓ¦¶Ô¸ßλ·¾³ÒªÇó, ²»Óôò¿ª, Òª¿´¿´¾ßÌåÇé¿ö,
-    if(gdiff[1]>20000)
-    {
-        gdiff[0] = gdiff[0]*0.9; // Èç¹ûËæ×ŸßÎÂ,¸ÐÓ¦ÖµÉÏÉý,Ϊ0.9, ¸ÐӦֵϽµ¸ÄΪ1.1
-    }
-#endif
-
-    if(gdiff[0]<WEARTHRES)
-    {
-        if((gdiff[0]>=SLEEPWEARTHRES)&&(wear_detect_mode == SLEEP_WEAR_MODE ))
+        if((lp_old[0] - lp[0]) > 40)
+            ret = 0;
+        else
         {
-            return prox_detect;
+            if(lp[0]>3300)
+                ret = 1;
+            else 
+                ret = 0;
         }
-        return prox_no_detect;
-    }
-    else
-    {
-        return prox_detect;
+        
     }
+    lp_old[0] = lp[0];
+    lp_old[1] = lp[1];
+    bl_old[0] = bl[0];
+    bl_old[1] = bl[1];
+    return ret;
+// #ifdef TEMP_COMPENSATION   //ζȲ¹³¥
+//     //Õâ¸öÊÇÓ¦¶Ô¸ßλ·¾³ÒªÇó, ²»Óôò¿ª, Òª¿´¿´¾ßÌåÇé¿ö,
+//     if(gdiff[1]>20000)
+//     {
+//         gdiff[0] = gdiff[0]*0.9; // Èç¹ûËæ×ŸßÎÂ,¸ÐÓ¦ÖµÉÏÉý,Ϊ0.9, ¸ÐӦֵϽµ¸ÄΪ1.1
+//     }
+// #endif
+    // if(gdiff[0]<WEARTHRES)// WEARTHRES=9000/2
+    // {
+    //     if((gdiff[0]>=SLEEPWEARTHRES)&&(wear_detect_mode == SLEEP_WEAR_MODE ))//SLEEPWEARTHRES=9000*0.3
+    //     {
+    //         return prox_detect;
+    //     }
+    //     return prox_no_detect;
+    // }
+    // else
+    // {
+    //     return prox_detect;
+    // }
 
 }
 
@@ -460,39 +472,27 @@ uint8_t hx3918_report_prox_status(void)
 void hx3918_read_nv(void)
 {
 
-    //´Óflash¶ÁÈ¡6¸öÖµ, ·Ö±ðÊÇÒÔǰ±£´æµÄÖµ; Õâ¸öº¯ÊýÓû§ÐèÒª×Ô¼ºÍê³É, flash´æ´¢µÄλÖò»Äܱ»Óû§²Ù×÷ɾµô
-    //flash_fds_data_get(6);
-    nv_wear_offset[0] = fds_read[0];
-    nv_wear_offset[1] = fds_read[1];
-    nv_base_data[0] = fds_read[2];
-    nv_base_data[1] = fds_read[3];
-    ai_tune_cnt[0] =  fds_read[4];
-    ai_tune_cnt[1] =  fds_read[5];
+    //´Óflash¶ÁÈ¡4¸öÖµ, ·Ö±ðÊÇÒÔǰ±£´æµÄÖµ; Õâ¸öº¯ÊýÓû§ÐèÒª×Ô¼ºÍê³É, flash´æ´¢µÄλÖò»Äܱ»Óû§²Ù×÷ɾµô
+    //flash_fds_data_get(4);
+    nv_wear_offset[0] = 468;
+    nv_wear_offset[1] = 82;
+    nv_base_data[0] = -382;
+    nv_base_data[1] = -389;
 
-    TYHX_LOG("[hx3918_read_nv]\r\n");
-    TYHX_LOG("OFF[0]:  %d,  OFF[1]:%d\r\n",nv_wear_offset[0],nv_wear_offset[1]);
-    TYHX_LOG("BASE[0]: %d, BASE[1]:%d\r\n",nv_base_data[0],nv_base_data[1]);
-    TYHX_LOG("ai_tune_cnt[0]:  %d, ai_tune_cnt[1]:%d\r\n",ai_tune_cnt[0],ai_tune_cnt[1]);
-
-    //Èç¹ûflash¼Ç¼µÄÖµ´óÓÚÉÏÏÞ, ÔòÈÿ¿½ü¸ÐÓ¦½øÈëÏà¶Ôֵģʽ
+       //Èç¹ûflash¼Ç¼µÄÖµ´óÓÚÉÏÏÞ, ÔòÈÿ¿½ü¸ÐÓ¦½øÈëÏà¶Ôֵģʽ
     if(nv_wear_offset[0] > 1020)
     {
-        nv_wear_offset[0] = 0xffff;
+        nv_wear_offset[0] = 0;
         nv_base_data[0] = 0;
+               nv_wear_offset[1] = 0;
+        nv_base_data[1] = 0;
     }
+       TYHX_LOG("[hx3918_read_nv]\r\n");
+    TYHX_LOG("OFF[0]:  %d,  OFF[1]:%d\r\n",nv_wear_offset[0],nv_wear_offset[1]);
+    TYHX_LOG("BASE[0]: %d, BASE[1]:%d\r\n",nv_base_data[0],nv_base_data[1]);
 
-    if (nv_wear_offset[0] == 0 && nv_base_data[0] == 0)
-    {
-        nv_wear_offset[0] = 0xFFFF;
-    }
-    if (nv_wear_offset[0] == 0xFFFF || is_factory_mode == 1 )
-    {
-        prox_work_mode = RELATIVE_MODE;//Ïà¶Ôֵģʽ
-    }
-    else
-    {
-        prox_work_mode = ABSOLUTE_MODE;//¾ø¶Ôֵģʽ
-    }
+
+    
 }
 
 /**
@@ -562,7 +562,7 @@ bool hx3918_prox_factory_init(void)
 
     hx3918_power_restart();
     //i2c_hrs_init();
-    prox_work_mode = RELATIVE_MODE;
+
     hx3918_ppg_on();
     hx3918_prox_reg_init();
     for (i = 0; i<5; i++)
@@ -607,12 +607,12 @@ void hx3918_prox_factory_hanging_cali(void)
     lp[0] = hx3918_read_diff_lp(LP0);
     lp[1] = hx3918_read_diff_lp(LP1);
 
-    TYHX_LOG("offset0,offset1= %d  %d\r\n", offset0,offset1);
+    HX3918_LOG("offset0,offset1=       %d  %d\r\n", offset0,offset1);
 
 #ifdef INDEPENDDENT_CH
     if((offset0-offset1)<100)
     {
-        TYHX_LOG("ERR,  resize cap of ch0\r\n");
+        HX3918_LOG("ERR,  resize cap of ch0\r\n");
     }
 
 #endif
@@ -620,15 +620,21 @@ void hx3918_prox_factory_hanging_cali(void)
     nv_wear_offset[1] = offset1;
     nv_base_data[0] = lp[0];
     nv_base_data[1] = lp[1];
-    TYHX_LOG("base0,base1=      %d  %d\r\n", lp[0],lp[1]);
+    HX3918_LOG("base0,base1=    %d  %d\r\n", lp[0],lp[1]);
 
 #ifdef DIFFERENCE_CH
     //½«²î·ÖÊý¾Ý¶Áµ½µÄOFFSET, NV_BASE¼Ç¼µ½FLASHÀïÃæ, Ð£×¼´æ´¢°Ñ×ÔѧϰµÄ¼Ç¼ҲÐèÒªÇåµôÖØÐ¼ÆËã
-    ai_tune_cnt[0] = 0;
-    ai_tune_cnt[1] = 0;
-    hx3918_factory_cali_save_nv();
+
+    if((offset0 == 510) &&(offset1 == 510))
+    {
+        TYHX_LOG("ERR,  read offset err, please redo it !!!\r\n");
+    }
+    else
+    {
+        hx3918_factory_cali_save_nv();
+    }
 #endif
-       hx3918_ppg_off();
+    hx3918_ppg_off();
     is_factory_mode = 0;
 
 }
@@ -646,15 +652,14 @@ void hx3918_factory_cali_save_nv(void)
     fds_write[2] = nv_base_data[0];
     fds_write[3] = nv_base_data[1];
 
-    fds_write[4] = ai_tune_cnt[0];
-    fds_write[5] = ai_tune_cnt[1];
 
     TYHX_LOG("[hx3918_factory_cali_save_nv]");
-    for(int i=0; i<6; i++)
+    for(int i=0; i<4; i++)
     {
         TYHX_LOG("%d   ",fds_write[i]);
     }
-    //flash_fds_data_write(6);
+       //Óû§ÐèÒªflash±£´æ
+    //flash_fds_data_write(4);
 }
 
 /**
@@ -664,9 +669,13 @@ void hx3918_factory_cali_save_nv(void)
 bool hx3918_get_wear_result(uint8_t ppg_wear)
 {
     uint8_t prox_result;
+    // hx3918_prox_factory_hanging_cali();
+    // return true;
     if(ppg_wear == 0)
     {
-        prox_result = hx3918_report_prox_status();
+#ifdef DEBUG_PPG_ONLY
+        return false;
+#endif
         return false;
     }
     else
@@ -674,7 +683,10 @@ bool hx3918_get_wear_result(uint8_t ppg_wear)
 #ifdef DEBUG_PPG_ONLY
         return true;
 #endif
-        prox_result = hx3918_report_prox_status();
+
+       prox_result = hx3918_report_prox_status();
+       //hx3918_prox_factory_hanging_cali();
+        HX3918_LOG("hx3918_get_wear_result:prox_result:%d",prox_result);
         if(prox_result == 0)
         {
             return false;
@@ -686,142 +698,6 @@ bool hx3918_get_wear_result(uint8_t ppg_wear)
     }
 }
 
-/**
- * HX3918 ×ÔÎÒУ׼ºǫִ́ÐгÌÐò, Åöµ½ÒòΪż·¢ÐÔµÄÒòÄÚ²¿½á¹¹µÈ±ä»¯ÒýÆð¿¿½ü¸ÐÓ¦µÄ¶Ô¿Õ»ù×¼Öµ·¢Éú´óµÄ±ä»¯,
- *       ÊÖ±í¶ÔÔÚ·ÇÅå´÷ʱ, ¿ÉÖ´ÐÐÒ»´Î¿¿½ü¸ÐÓ¦µÄ×ÔÎÒУ׼.
-                 ´¥·¢Ìõ¼þ, µ±IR¼ì²âΪ¶Ô¿Õ, ÇÒµ±Ç°LPµÍÓÚ-3000, ´¥·¢ºǫ́У׼. Õâ¸ö³ÌÐòÔÚ¼ì²âÅå´÷µÄº¯ÊýÖб»µ÷ÓÃ
-* @param irval ÔÚÅå´÷¼ì²âģʽʱ²âÊÔµ½µÄÖµ
-*/
-void hx3918_auto_cali_backgroud(int32_t irval)
-{
-    uint8_t prox_result;
-
-    if(irval>HX3918_IR_AIR)
-        return;
-    prox_result = hx3918_report_prox_status();
-
-    if(prox_result == prox_no_detect)
-    {
-        if((nv_base_data[0]<AUTOCALITHRES)&&(lp[0]<AUTOCALITHRES))
-        {
-            hx3918_prox_factory_hanging_cali();
-            TYHX_LOG("hi, auto cali\r\n");
-        }
-    }
-}
-
-
-#define FILTERLEN 8 // Õâ¸öÖµ±ØÐë´óÓÚµÈÓÚ4
-/**
-*  ÖÐλֵƽ¾ùÂ˲¨
-* @param pData:  Ô­Ê¼µÄLPÂ˲¨Êý¾Ý
-* @param nSize:Êý¾Ý´óС
-* @return:Â˲¨ÊýÖµ
-*/
-
-int16_t  MedianFilter(int16_t* pData,int nSize)
-{
-    int16_t max,min;
-    int sum;
-    if(nSize>=FILTERLEN)
-    {
-        max = pData[0];
-        min = max;
-        sum = 0;
-        for(int i=0; i<nSize; i++)
-        {
-            sum += pData[i];
-            if(pData[i]>max)
-            {
-                max = pData[i];   //Ò»¸öÑ­»·Ö®ºómax¾ÍÊÇ×î´óµÄÖµ
-            }
-
-            if(pData[i]<min)
-            {
-                min = pData[i];   //Ò»¸öÑ­»·Ö®ºómin¾ÍÊÇ×îСµÄÖµ
-            }
-        }
-
-        sum = sum-max-min;       //È¥µô×î´óµÄÖµºÍ×îСµÄÖµ
-        return sum/(nSize-2);    //¶ÔN-2¸öÊýÇ󯽾ùÖµ
-    }
-
-    return 0;
-}
-
-
-/**
- * HX3918 ÏòÏÂУ׼¶Ô¿ÕÖµ, Èç×°ÅäµÈÎÊÌâµ¼ÖµçÈÝÓÐСµÄÏòÏÂÆ¯ÒÆ, »òÕßpad¿ÉÄÜÓÐСµÄÐαäµÈÒýÆðµÄ¸ÐÓ¦Öµ±äС.
-               Í¨¹ýÕâ¸ö³ÌÐò     Ð£×¼¶Ô¿ÕµÄnv_base;  ÊÖ±íÔÚ
-* @param prevlp ÔÚÅå´÷¼ì²âģʽʱ²âÊÔµ½µÄÉÏÒ»¸öLPµÄÖµ
-* @param chargetstate ³äµç״̬ = true, ÎªÁ˽«nv_base×ÔѧϰÏòÉÏÒ»µã, Èç¹û³äµçµÄʱºòÊÖ±íÍâ¿Ç½Ó´¥µ¼Ìå×ÀÃæµÈ,²»½¨Òé´ò¿ªÕâ¸ö
-*/
-void hx3918_ai_tune_nv(int16_t prevlp,int16_t prevbl)
-{
-    int16_t lpresult,blresult;
-    int16_t differ;
-    static uint8_t receivercnt = 0;     //½ÓÊܵ½µÄlpµÄ¼ÆÊý
-    static int16_t lp_filter[FILTERLEN] = {0};
-    static int16_t bl_filter[FILTERLEN] = {0};
-    static bool flashrecordupdate = false;;
-    static uint32_t get_record_time;
-    uint32_t get_new_time;
-
-    if (prox_work_mode == ABSOLUTE_MODE)
-    {
-        for(int ii=0; ii<(FILTERLEN-1); ii++)
-        {
-            lp_filter[ii] = lp_filter[ii+1];
-            bl_filter[ii] = bl_filter[ii+1];
-
-        }
-        lp_filter[FILTERLEN-1] = prevlp;
-        bl_filter[FILTERLEN-1] = prevbl;
-        if(receivercnt<FILTERLEN)
-        {
-            receivercnt++;
-        }
-        if(receivercnt>=FILTERLEN)
-        {
-            lpresult = MedianFilter(lp_filter,FILTERLEN);
-            blresult = MedianFilter(bl_filter,FILTERLEN);
-                       TYHX_LOG("lp =%d, bl = %d, receivercnt=%d\r\n",lpresult,blresult,receivercnt);
-            if((blresult>=ONAIRTHRESLOW) && (blresult<=ONAIRTHRESHIGH)&&(lpresult>=ONAIRTHRESLOW) && (lpresult<=ONAIRTHRESHIGH))
-            {
-                if((hx_abs(blresult -nv_base_data[0] )>=DIFFDETECT) &&(hx_abs(lpresult-blresult)<=100))
-                {
-                    differ = blresult-nv_base_data[0];
-                    TYHX_LOG("detect lp =%d, bl = %d, nv_base=%d\r\n",lpresult,blresult,nv_base_data[0]);
-                    nv_base_data[0] += (differ/2);
-                    hx3918_config_thres(CH0,CH0_HIGH_DIFF, CH0_LOW_DIFF,nv_base_data[0]); // wear0
-                    get_record_time = app_timer_cnt_get();
-                    flashrecordupdate = true;
-                }
-            }
-        }
-        if(flashrecordupdate)//¼ä¸ô2·ÖÖÓÈç¹ûÓÐÐèÒª¼Ç¼flashÒ»´Î, ·ÀÖ¹ÖØ¸´Ð´flash, Õâ¸öʱ¼äÓɸ÷×ÔÆ½Ì¨´¦Àí.
-        {
-            get_new_time = app_timer_cnt_get(); //»»Ëã³ÉÃë;
-            if (get_new_time >= get_record_time)//
-            {
-                get_new_time = ((get_new_time - get_record_time) )>>15;
-            }
-            else
-            {
-                get_new_time = ((get_new_time + 16777216 - get_record_time) ) >>15;
-            }
-            get_new_time *=2;
-            if(get_new_time>=120)//120 Ãë
-            {
-                ai_tune_cnt[0]++;
-                TYHX_LOG("write nv_base=%d, updata cnt = %d\r\n",nv_base_data[0],ai_tune_cnt[0] );
-                hx3918_factory_cali_save_nv();
-                flashrecordupdate = false;
-                get_new_time = 0;
-            }
-        }
-    }
-}
 
 
 
index 9f4eeed..64ab0a1 100644 (file)
 #include <stdint.h>
 
 
+
+
 #define CH0   0
 #define CH1   1
 #define CH2   2
 
 
+
+
 #define CH0_OFFSET   0
 #define CH1_OFFSET   1
 #define CH2_OFFSET   2
 #define hx_min(x,y)  ( (x)>(y)?(y):(x) )
 #define hx_abs(x)    ((x)>0?(x):(-(x)))
 
-#define RELATIVE_MODE  0
-#define ABSOLUTE_MODE  1
+#define RELATIVE_MODE  0  //相对值模式, 检测结果=LP-BL, 无法佩戴着开机时的靠近感应,其他正常
+#define ABSOLUTE_MODE  1  //绝对值模式, 检测结果=LP-NV_BASE 可以佩戴开机
 
 #define PROX_CHIPID         0x27
 
 #define HX3918_IR_AIR       6000                  //小于这个值代表脱腕
 
-#define NORMALWEARDIFF      12000                 //正常佩戴测试到的平均值, 宽松佩戴
+#define NORMALWEARDIFF      1000                 //正常佩戴测试到的平均值, 宽松佩戴
 #define WEARTHRES              NORMALWEARDIFF/2      //普通佩戴阈值
 #define SLEEPWEARTHRES      NORMALWEARDIFF*0.3    //睡眠佩戴阈值
 
-#define AUTOCALITHRES       -3000                 //后台自动校准LP和BL阈值
-#define ONAIRTHRESLOW       -2500                  //对空的LP BL 最小值
-#define ONAIRTHRESHIGH       1300                  //对空的LP BL 最大值
+#define CH0_HIGH_DIFF          NORMALWEARDIFF/8
+#define CH0_LOW_DIFF           NORMALWEARDIFF/10
+#define CH1_HIGH_DIFF          NORMALWEARDIFF/8
+#define CH1_LOW_DIFF           NORMALWEARDIFF/10
+
+
+
+//HX3918 cap 测试电容的满量程设置, 最小
+//#define FULL0625PF  //HX3918 full range cap = 0.625pf //一般不用这个, 这个满量程设置, 说明感应pad很小,
+//#define FULL125PF   //HX3918 full range cap = 1.25pf
+#define FULL25PF      //HX3918 full range cap = 2.5pf, 一般PAD大小默认这个.
+//#define FULL375PF   //HX3918 full range cap = 3.75 pf
+//#define FULL50PF    //HX3918 full range cap = 5.0 pf
+
+//READ_DEVATION ,read offset 的偏差控制, 一个offset = 0.0586pf 按照不同量程, 对应的code, 留10%余量
+#ifdef FULL125PF 
+#define READ_DEVATION        1680
+#elif defined(FULL25PF)
+#define READ_DEVATION        845
+#elif defined(FULL375PF)
+#define READ_DEVATION        560
+#elif defined(FULL375PF)
+#define READ_DEVATION        420
+#endif
 
-#define DIFFDETECT          200                   //BL 和 NV_BASE 比较的差值
 
-#define CH0_HIGH_DIFF          SLEEPWEARTHRES
-#define CH0_LOW_DIFF           SLEEPWEARTHRES*0.7
-#define CH1_HIGH_DIFF          SLEEPWEARTHRES
-#define CH1_LOW_DIFF           SLEEPWEARTHRES*0.7
 
 
 typedef enum
@@ -84,11 +104,13 @@ extern int16_t gdiff[2];
 extern int16_t lp[2];
 extern int16_t bl[2];
 extern int16_t nv_base_data[2];
-extern uint32_t ai_tune_cnt[2];
 extern int16_t nv_wear_offset[2];
 
-extern uint32_t fds_read[6]; //flash 读
-extern uint32_t fds_write[6];//flash 写
+
+#define FDSLEN 4  //flash 存储的长度
+
+extern uint32_t fds_read[FDSLEN]; //flash 读
+extern uint32_t fds_write[FDSLEN];//flash 写
 extern uint8_t wear_detect_mode;
 
 
@@ -105,10 +127,6 @@ bool hx3918_prox_init(void);
 void hx3918_factory_cali_save_nv(void);
 int16_t hx3918_read_diff_lp(uint8_t chx_diff);
 bool hx3918_get_wear_result(uint8_t ppg_wear);
-void hx3918_auto_cali_backgroud(int32_t irval);
-//void hx3918_ai_tune_nv(int16_t prevlp,bool chargetstate);
-void hx3918_ai_tune_nv(int16_t prevlp,int16_t prevbl);
-//void hx3918_ai_tune_nv(int32_t irval,int16_t prevlp,int16_t prevbl);
 bool hx3918_prox_factory_init(void);
 void hx_set_wear_detect_mode(uint8_t current_mode);
 
index 438e173..6e35e7b 100644 (file)
@@ -247,7 +247,7 @@ bool hx3918_spo2_check_wear(int32_t infrared_data)
        
         spo2_wear_status = MSG_SPO2_WEAR;              
                //TYHX_LOG("[hx3918_spo2_check_wear start] ir wear result = %d\r\n",spo2_wear_status);
-               //spo2_wear_status = hx3918_get_wear_result(spo2_wear_status);
+               spo2_wear_status = hx3918_get_wear_result(spo2_wear_status);
                TYHX_LOG("[hx3918_spo2_check_wear end] final result = %d\r\n",spo2_wear_status);
         if(spo2_wear_status_pre != MSG_SPO2_WEAR)
         {
@@ -480,9 +480,7 @@ void hx3918_spo2_cal_off(void) // 20200615 ericy afe cali offline
     hx3918_delay(5);
     hx3918_write_reg(0X4d, 0X00);  //release
     hx3918_delay(5);             //Delay for reset time
-    #if DEBUG_PPG_ONLY
-     hx3918_prox_init();
-    #endif
+    hx3918_prox_init();
     read_fifo_first_flg = 1;
 }
 
@@ -568,9 +566,7 @@ void hx3918_spo2_low_power(void)
     hx3918_delay(5);
     hx3918_write_reg(0X4d, 0X00);  //release
     hx3918_delay(5);
-    #if DEBUG_PPG_ONLY
-        hx3918_prox_init();
-    #endif
+       hx3918_prox_init();
     read_fifo_first_flg = 1;
     AGC_LOG(" chip go to low power mode  \r\n" );
 }
@@ -778,7 +774,8 @@ uint8_t hx3918_spo2_read(ppg_sensor_data_t * s_dat)
         red_buf[i] = Red_src_data-260000;
         ir_buf[i] = Ir_src_data-260000;
         if(spo2_wear_status==MSG_SPO2_WEAR)
-        {        
+        {
+        
                        TYHX_LOG("spo2  unwear data %d\r\n:     ",calReg.ir_idac);
             if(hx3918_spo2_check_unwear())
             {
index f3307f9..9c87f32 100644 (file)
@@ -131,7 +131,7 @@ typedef struct _SC7A20_obj_t
 
 } SC7A20_obj_t;
 STATIC SC7A20_obj_t *g_SC7A20 = NULL;
-
+char is_set_cb = 0;
 unsigned char SL_SC7A20_I2c_Spi_Write(bool sl_spi_iic,unsigned char reg, unsigned char data)
 {
        uint8_t reg_addr = reg;
@@ -228,7 +228,7 @@ unsigned char SL_MCU_SLEEP_ALGO_FUNCTION(void);
 void Gsensor_CALLBACK_OP(uint8_t state)     
 {
       
-       if(g_SC7A20->cb.cb != NULL)
+       if(g_SC7A20->cb.cb != NULL && is_set_cb == 1)
        {
                st_CallBack_Gsensor *Gsensor_cb = malloc(sizeof(st_CallBack_Gsensor));                    
                if(NULL != Gsensor_cb ) {                                                                
@@ -716,7 +716,7 @@ STATIC mp_obj_t mp_SC7A20_register_usr_cb(mp_obj_t self_in, mp_obj_t callback)
                 &mp_type_RuntimeError, MP_ERROR_TEXT("SC7A20 instance needs to be created before callback is called!")));
 
     mp_sched_schedule_callback_register(&self->cb, callback);
-
+       is_set_cb = 1;
        return mp_obj_new_int(0);
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_init_SC7A20_obj, mp_SC7A20_init);//初始化
index 81590a2..fa6e4fc 100644 (file)
 
 #include "helios_debug.h"
 #include "hx3918.h"
+#include "hx3918_factory_test.h"
 #include "autoconf.h"
 extern void sensor_thread_entry(void * argv);
 extern Helios_ThreadAttr ThreadAttr;
 extern Helios_Thread_t sensor_thread_id ;
-#define HX3918_LOG(msg, ...)      custom_log("HX3918", msg, ##__VA_ARGS__)
+//#define HX3918_LOG(msg, ...)      custom_log("HX3918", msg, ##__VA_ARGS__)
 //////////////////////////////////////////////////////////////////////////////
 typedef struct _HX3918_obj_t
 {
@@ -145,17 +146,28 @@ void HX3918_thread_do(void)
                //      hx3918_ppg_timerout_flag = 0;
                // }
                wear_time++;
-               if(wear_time > 3)
+               if(wear_time > 1)
                {
                        wear_time = 0;
+                       //hx3918_prox_factory_hanging_cali();
                        ir_wear = hx3918_get_wear_ppg_Int_handle();
                        cap_wear = hx3918_report_prox_status();
+
                        HX3918_LOG("ir_wear:%d cap_wear%d\n",ir_wear,cap_wear);
+                       if(ir_wear == 1 && cap_wear==1)
+                       {
+                               s_HX3918_wear_status = 1;
+                       }else
+                               s_HX3918_wear_status = 0;
                }
                
                #if CONFIG_SC7A20
                if(ir_wear == 1 || cap_wear==1)
+               {
                        SL_SC7A20_PEDO_KCAL_WRIST_SLEEP_SWAY_L_ALGO();
+                       
+               }
+                       
                #endif
                Helios_msleep(1000);
                
@@ -190,6 +202,7 @@ void HX3918_result_set_heart_rate(unsigned char heart_rate)
 void HX3918_result_set_wear_status(unsigned char wear_status)
 {
    s_HX3918_wear_status = wear_status; 
+   //HX3918_LOG("s_HX3918_wear_status:%d !!!!!!!!!!!!!!!!!\n\n\n",s_HX3918_wear_status);
 }
 void HX3918_result_set_blood_oxygen(unsigned char blood_oxygen)
 {
@@ -366,7 +379,7 @@ void HX3918_test(uint32_t mode)
        s_HX3918_high_blood = 0x0;
        s_HX3918_low_blood = 0x0;
        s_HX3918_HRV = 0;
-       s_HX3918_wear_status = 0;
+       //s_HX3918_wear_status = 0;
        s_HX3918_blood_oxygen = 0x0;
        
        if(hx3918_init(mode) == true)
@@ -402,6 +415,14 @@ STATIC mp_obj_t mp_HX3918_open_hrv(mp_obj_t self_in)
        //HX3918_run_mode = HRV_MODE;
     return mp_obj_new_int(1);
 }
+//打开测试模式
+STATIC mp_obj_t mp_HX3918_open_test(mp_obj_t self_in,mp_obj_t val1)
+{
+       HX3918_obj_t *self = MP_OBJ_TO_PTR(self_in);
+       HX3918_run_mode = mp_obj_get_int(val1);
+    return mp_obj_new_int(1);
+}
+
 void HX3918_close(void)
 {
        if(is_open_HX3918 == 1)
@@ -431,6 +452,7 @@ void HX3918_close(void)
        hx3918_init(WEAR_MODE);//打开佩戴检测
 
 }
+
 //关闭hsensor
 STATIC mp_obj_t mp_HX3918_close(mp_obj_t self_in)
 {
@@ -453,7 +475,7 @@ STATIC mp_obj_t mp_HX3918_get_blood_oxygen(mp_obj_t self_in)
 //获取血压
 STATIC mp_obj_t mp_HX3918_get_blood_pressure(mp_obj_t self_in)
 {
-    mp_obj_t coordinate_list[2] = {s_HX3918_high_blood, s_HX3918_low_blood,};
+    mp_obj_t coordinate_list[2] = {mp_obj_new_int(s_HX3918_high_blood), mp_obj_new_int(s_HX3918_low_blood),};
     return mp_obj_new_list(2, coordinate_list);
 }
 //获取hrv
@@ -461,13 +483,14 @@ STATIC mp_obj_t mp_HX3918_get_hrv(mp_obj_t self_in)
 {
     return mp_obj_new_int(s_HX3918_HRV);
 }
-//hx3918_report_prox_status();获取电容佩戴状态
-//SENSOR_ERROR_T hx3918_check_touch_enable(void);获取红外佩戴状态
+// ir_wear = hx3918_get_wear_ppg_Int_handle();
+//                     cap_wear = hx3918_report_prox_status();
 //获取佩戴状态
 STATIC mp_obj_t mp_HX3918_get_wear(mp_obj_t self_in)
 {
-       
-    return mp_obj_new_int(s_HX3918_wear_status);
+       mp_obj_t coordinate_list[3] = {mp_obj_new_int((int)ir_wear), mp_obj_new_int((int)cap_wear),mp_obj_new_int((int)s_HX3918_wear_status),};
+       return mp_obj_new_list(3, coordinate_list);
+    //return mp_obj_new_int(s_HX3918_wear_status);
 }
 //获取所有数据  心律、血氧、高压、低压、HRV、佩戴状态
 STATIC mp_obj_t mp_HX3918_get_all_data(mp_obj_t self_in)
@@ -477,6 +500,17 @@ STATIC mp_obj_t mp_HX3918_get_all_data(mp_obj_t self_in)
                                                                   mp_obj_new_int((int)s_HX3918_HRV),mp_obj_new_int((int)s_HX3918_wear_status)};
     return mp_obj_new_list(6, coordinate_list);
 }
+
+extern factory_result_t factory_reslts; 
+//FT_LEAK_LIGHT_MODE 产测漏光测试模式;
+//FT_GRAY_CARD_MODE 产测灰卡测试模式;
+//LAB_TEST_MODE 实验室模式。
+STATIC mp_obj_t mp_HX3918_get_test_data(mp_obj_t self_in)
+{
+       mp_obj_t coordinate_list[3] = {mp_obj_new_int((int)factory_reslts.green_data_final),mp_obj_new_int((int)factory_reslts.red_data_final),\
+                                                                  mp_obj_new_int((int)factory_reslts.ir_data_final)};
+       return mp_obj_new_list(3, coordinate_list);
+}
 //设置sleep
 STATIC mp_obj_t mp_HX3918_set_sleep(mp_obj_t self_in)
 {
@@ -490,7 +524,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_activate_HX3918_obj, mp_activate_HX3918);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_blood_oxygen_obj, mp_HX3918_get_blood_oxygen);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_heart_obj, mp_HX3918_get_heart);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_blood_pressure_obj, mp_HX3918_get_blood_pressure);//
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_weart_obj, mp_HX3918_get_wear);//
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_wear_obj, mp_HX3918_get_wear);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_open_heart_obj, mp_HX3918_open_heart);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_open_blood_oxygen_obj, mp_HX3918_open_blood_oxygen);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_open_hrv_obj, mp_HX3918_open_hrv);//
@@ -498,6 +532,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_hrv_obj, mp_HX3918_get_hrv);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_all_data_obj, mp_HX3918_get_all_data);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_close_obj, mp_HX3918_close);//
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_set_sleep_obj, mp_HX3918_set_sleep);//
+STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_HX3918_open_test_obj, mp_HX3918_open_test);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_HX3918_get_test_data_obj, mp_HX3918_get_test_data);//
 
 STATIC const mp_rom_map_elem_t HX3918_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mp_init_HX3918_obj) },
@@ -506,7 +542,7 @@ STATIC const mp_rom_map_elem_t HX3918_locals_dict_table[] = {
        { MP_ROM_QSTR(MP_QSTR_get_blood_oxygen), MP_ROM_PTR(&mp_HX3918_get_blood_oxygen_obj)},
        { MP_ROM_QSTR(MP_QSTR_get_heart), MP_ROM_PTR(&mp_HX3918_get_heart_obj)},
        { MP_ROM_QSTR(MP_QSTR_get_blood_pressure), MP_ROM_PTR(&mp_HX3918_get_blood_pressure_obj)},
-       { MP_ROM_QSTR(MP_QSTR_get_weart), MP_ROM_PTR(&mp_HX3918_get_weart_obj)},
+       { MP_ROM_QSTR(MP_QSTR_get_wear), MP_ROM_PTR(&mp_HX3918_get_wear_obj)},
        { MP_ROM_QSTR(MP_QSTR_open_heart), MP_ROM_PTR(&mp_HX3918_open_heart_obj)},
        { MP_ROM_QSTR(MP_QSTR_open_blood_oxygen), MP_ROM_PTR(&mp_HX3918_open_blood_oxygen_obj)},
        { MP_ROM_QSTR(MP_QSTR_open_hrv), MP_ROM_PTR(&mp_HX3918_open_hrv_obj)},
@@ -514,6 +550,8 @@ STATIC const mp_rom_map_elem_t HX3918_locals_dict_table[] = {
        { MP_ROM_QSTR(MP_QSTR_get_all_data), MP_ROM_PTR(&mp_HX3918_get_all_data_obj)},
        { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_HX3918_close_obj)},
        { MP_ROM_QSTR(MP_QSTR_set_sleep), MP_ROM_PTR(&mp_HX3918_set_sleep_obj)},
+       { MP_ROM_QSTR(MP_QSTR_open_test), MP_ROM_PTR(&mp_HX3918_open_test_obj)},
+       { MP_ROM_QSTR(MP_QSTR_get_test_data), MP_ROM_PTR(&mp_HX3918_get_test_data_obj)},
 };
 
 STATIC MP_DEFINE_CONST_DICT(HX3918_locals_dict, HX3918_locals_dict_table);