class heart_rate

Revision:
1:e9f4fb198b63
Parent:
0:31d7988294aa
Child:
2:5cb0e405a24c
--- a/pixart_heart_rate.cpp	Fri Oct 27 05:55:57 2017 +0000
+++ b/pixart_heart_rate.cpp	Fri Oct 27 06:32:02 2017 +0000
@@ -7,9 +7,15 @@
 #include <stdlib.h>
 
 
+#define log_printf(...)     m_debug_printf_handler(__VA_ARGS__)
+
+
 namespace pixart {
     
     
+    class pah_hr_data : public pah8series_data_t {};
+    
+    
     const float     heart_rate::GRAVITY_OF_EARTH = 9.80665f;
     const size_t    heart_rate::PPG_SYNC_COUNT = 20;
     const size_t    heart_rate::ACCEL_AXIS_NUM = 3;
@@ -18,6 +24,7 @@
         : PPG_MAX_SAMPLE_NUM(ppg_max_sample_num)
         , PPG_CH_NUM(2)
         , ACCEL_MAX_SAMPLE_NUM(accel_max_sample_num)
+        , m_debug_printf_handler(NULL)
         , m_time_to_millisec_handler(time_to_millisec_handler)
         , m_alg_buffer(NULL)
         , m_gravity_mode(gravity_4g)
@@ -57,6 +64,11 @@
         return true;
     }
     
+    void heart_rate::set_debug_printf(DEBUG_PRINTF_HANDLE handler)
+    {
+        m_debug_printf_handler = handler;
+    }
+    
     void heart_rate::reset()
     {
         m_ppg_sample_queue.clear();
@@ -190,7 +202,7 @@
         uint32_t time_ms = (uint32_t)m_time_to_millisec_handler(ppg_timestamp - m_last_report_timestamp);
         m_last_report_timestamp = ppg_timestamp;
         
-        pah8series_data_t pah8series_data;
+        pah_hr_data pah8series_data;
         pah8series_data.frame_count        = m_frame_count;
         pah8series_data.time               = time_ms;
         pah8series_data.touch_flag         = touch_flag;
@@ -201,6 +213,9 @@
         pah8series_data.mems_data          = &hr_accel_data[0];
         ++m_frame_count;
         
+        if (m_debug_printf_handler)
+            log_pah8series_data(&pah8series_data);
+        
         uint8_t ret = pah8series_entrance(&pah8series_data);
         
         float hr = 0.0f;
@@ -221,6 +236,32 @@
         m_result.hr = hr;
         m_result.hr_trust_level = hr_trust_level;
     }
+    
+    void heart_rate::log_pah8series_data(const pah_hr_data *pxialg_data)
+    {
+        int i = 0;
+        uint32_t *ppg_data = (uint32_t *)pxialg_data->ppg_data;
+        int16_t *mems_data = pxialg_data->mems_data;
+        int data_num = pxialg_data->nf_ppg_channel * pxialg_data->nf_ppg_per_channel;
+        
+        log_printf("Frame Count, %d \n", pxialg_data->frame_count);
+        log_printf("Time, %d \n", pxialg_data->time);
+        log_printf("PPG, %d, %d, ", pxialg_data->touch_flag, data_num);
+        for (i = 0; i < data_num; ++i)
+        {
+            log_printf("%d, ", *ppg_data);
+            ppg_data++;
+        }
+        log_printf("\n");
+        log_printf("MEMS, %d, ", pxialg_data->nf_mems);
+        for (i = 0; i < pxialg_data->nf_mems * 3; ++i)
+        {
+            log_printf("%d, ", *mems_data);
+            mems_data++;
+        }
+        log_printf("\n");
+    }
+    
 
 }