TOUCH_STATUS__OFF,\r
} touch_status;\r
\r
+/* 0x2F LOD: bit0=LA, bit3=RA; 测量模式下 1=lead-off, 0=contact */\r
+#define ECG_LOD_FLAG_LA 0x01u\r
+#define ECG_LOD_FLAG_RA 0x08u\r
\r
typedef struct\r
{\r
// ecg\r
uint64_t ecg_prev_timestamp;\r
\r
- // touch\r
+ // touch: IR 佩戴 / ECG 电极(0=未触摸 1=已触摸)\r
touch_status touch_status;\r
+ uint8_t ecg_electrode_touch;\r
//Dri or Polling\r
uint8_t work_mode;\r
\r
\r
static void read_fifo_callback(void *user_data, uint8_t *fifo, uint16_t data_count, float read_size_ratio);\r
static void send_fifo_data(main_state *this, uint8_t *fifo, uint16_t data_count, float read_size_ratio);\r
+static void ecg_electrode_touch_reset(void);\r
+static void ecg_electrode_touch_update(const pah831x_int_flag *int_flag);\r
+static touch_status ecg_electrode_touch_for_alg(void);\r
static float update_sample_interval(main_state *this, uint64_t start_timestamp, uint64_t end_timestamp, uint32_t sample_num, float read_size_ratio);\r
\r
static void send_ppg_event(main_state *this, uint64_t timestamp, const pah831x_ppg_sample *ppg_sample);\r
\r
pah831x_int_flag int_flag;\r
pah831x_read_int_flag(&_state.core, &int_flag);\r
+ ecg_electrode_touch_update(&int_flag);\r
DEBUG_PRINT("int_flag(data[1],fifo,touch): 0x%02X, %d, %d,\n", int_flag.data[1], (int)PAH831X_HAS_FIFO_INT(int_flag), (int)PAH831X_HAS_TOUCH_INT(int_flag));\r
//uint16_t touch_value = 0 ;\r
//bool touch_flag = false;\r
now_timestamp = pxi_get_tick_count();\r
pah831x_int_flag int_flag;\r
pah831x_read_int_flag(&_state.core, &int_flag);\r
+ ecg_electrode_touch_update(&int_flag);\r
DEBUG_PRINT("int_flag(data[1],fifo,touch): 0x%02X, %d, %d\n", int_flag.data[1], (int)PAH831X_HAS_FIFO_INT(int_flag), (int)PAH831X_HAS_TOUCH_INT(int_flag));\r
pah831x_read_touch_flag(&_state.core,&_state.core.touch_flag);\r
pah831x_read_touch_value(&_state.core, &_state.core.touch_value);\r
send_fifo_data(this, fifo, data_count, read_size_ratio);\r
}\r
\r
+static void ecg_electrode_touch_reset(void)\r
+{\r
+ _state.ecg_electrode_touch = 0;\r
+}\r
+\r
+static void ecg_electrode_touch_update(const pah831x_int_flag *int_flag)\r
+{\r
+ uint8_t lod;\r
+\r
+ if (_state.ecg_reg_setting == PAH831X_ECG_REG_SETTING_IDLE) {\r
+ return;\r
+ }\r
+\r
+ lod = int_flag->data[0];\r
+ _state.ecg_electrode_touch = ((lod & (ECG_LOD_FLAG_LA | ECG_LOD_FLAG_RA)) == 0) ? 1 : 0;\r
+}\r
+\r
+static touch_status ecg_electrode_touch_for_alg(void)\r
+{\r
+ return _state.ecg_electrode_touch ? TOUCH_STATUS__ON : TOUCH_STATUS__OFF;\r
+}\r
+\r
+uint8_t pah831x_get_ecg_electrode_touch(void)\r
+{\r
+ return _state.ecg_electrode_touch;\r
+}\r
+\r
static void send_fifo_data(main_state *this, uint8_t *fifo, uint16_t data_count, float read_size_ratio)\r
{\r
uint16_t ppg_sample_num = 0;\r
duration =(uint32_t)(this->task_timestamp - this->prev_task_timestamp );\r
_ecg_data_out.ecg_data_ready++;\r
_ecg_data_out.duration = duration;\r
- _ecg_data_out.is_touched = _state.core.touch_flag ? 1U : 0U;\r
+ _ecg_data_out.is_touched = ecg_electrode_touch_for_alg();\r
_ecg_data_out.ch_num = 1 ;\r
_ecg_data_out.sample_num_per_ch = ecg_sample_num ;\r
\r
duration =(uint32_t)(this->task_timestamp - this->prev_task_timestamp );\r
_ecg_data_out.ecg_data_ready++;\r
_ecg_data_out.duration = duration;\r
- _ecg_data_out.is_touched = _state.core.touch_flag ? 1U : 0U;\r
+ _ecg_data_out.is_touched = ecg_electrode_touch_for_alg();\r
_ecg_data_out.ch_num = 1 ;\r
_ecg_data_out.sample_num_per_ch = ecg_sample_num ;\r
_ppg_data_out.ppg_data_ready++;\r
_state.core.ir_r_led_switch_new_status = status;\r
}\r
\r
-uint16_t get_pah831x_touch_value(void)\r
+uint16_t get_pah831x_touch_value()\r
{\r
- uint16_t touch_value = 0;\r
-\r
- pah831x_read_touch_value(&_state.core, &touch_value);\r
- return touch_value;\r
-}\r
-\r
-static void pah831x_fill_ecg_touch_flag(uint8_t *touch_flag)\r
-{\r
- bool flag = false;\r
-\r
- if (touch_flag == NULL) {\r
- return;\r
- }\r
+ uint16_t pah831x_touch_value = 0 ;\r
\r
- pah831x_read_touch_flag(&_state.core, &flag);\r
- *touch_flag = flag ? 1U : 0U;\r
+ pah831x_read_touch_value(&_state.core, &pah831x_touch_value);\r
+ \r
+ return pah831x_touch_value ;\r
}\r
\r
-static void pah831x_reset_ecg_touch_cache(void)\r
-{\r
- _state.touch_status = TOUCH_STATUS__UNKNOWN;\r
- _state.core.touch_flag = false;\r
- _state.core.touch_value = 0;\r
- _ecg_data_out.is_touched = 0;\r
-}\r
\r
static void get_avg_hrs(uint8_t hrs)\r
{\r
ret_ecg_bp_status = pah_ecg_bp_get_status();\r
\r
// LOG_PRINT("got_time_out =%d\n",got_time_out);\r
- // LOG_PRINT("got_BP =%d\n",got_BP);\r
- // LOG_PRINT("_ecg_data_out_alg.is_touched =%d\n",_ecg_data_out_alg.is_touched);\r
- // LOG_PRINT("ECG_PPG_BP_CALI_cali_value = %d, %d, %d, %d,\n", cal_sbp_in,cal_dbp_in,CalValue_in,CalValue1_in);\r
\r
clear_ecg_data_ready();\r
clear_ppg_data_ready();\r
void pah831x_ecg_bp_start(uint8_t cmd)\r
{\r
ret_ecg_bp_status = PAH_ECG_BP_STATUS_MEASURING;\r
+ ecg_electrode_touch_reset();\r
ecg_param_init = 0;\r
\r
if(cmd == 0)\r
if(calibration_mode==ECG_PPG_BP_CALI)\r
{\r
pah831x_sensor_init();\r
- pah831x_reset_ecg_touch_cache();\r
pah831x_sensor_start(PAH831X_WORK_POLLING, PAH831X_INIT_ALWAYS_RUN, PAH831X_PPG_REG_SETTING_IDLE, PAH831X_ECG_REG_SETTING_2, 128, 3.90625f);\r
ecg_bp_algorithm_init();\r
\r
}else if(calibration_mode==ECG_PPG_BP_ESTIMATE)\r
{\r
pah831x_sensor_init();\r
- pah831x_reset_ecg_touch_cache();\r
pah831x_sensor_start(PAH831X_WORK_POLLING, PAH831X_INIT_ALWAYS_RUN, PAH831X_PPG_REG_SETTING_IDLE, PAH831X_ECG_REG_SETTING_2, 128, 3.90625f);\r
ecg_bp_algorithm_init();\r
//calibration_mode = ECG_PPG_BP_ESTIMATE;\r
ret_ecg_afib_hr = 0;\r
ret_ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID;\r
ret_ecg_afib_status = PAH_ECG_AFIB_STATUS_MEASURING;\r
+ ecg_electrode_touch_reset();\r
ecg_afib_algorithm_init();\r
pah831x_sensor_init();\r
- pah831x_reset_ecg_touch_cache();\r
pah831x_sensor_start(PAH831X_WORK_POLLING ,PAH831X_INIT_ALWAYS_RUN,PAH831X_PPG_REG_SETTING_IDLE ,PAH831X_ECG_REG_SETTING_1,256,3.91f );\r
}\r
\r
\r
pah_sensor_stop();\r
ecg_bp_algorithm_close();\r
- pah831x_reset_ecg_touch_cache();\r
\r
if(calibration_mode == ECG_PPG_BP_CALI)\r
{\r
pah_sensor_stop();\r
ecg_afib_algorithm_close();\r
ecg_afib_algorithm_init();\r
- pah831x_reset_ecg_touch_cache();\r
\r
ret_ecg_afib_hr = 0;\r
ret_ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID;\r
ret_ecg_afib_status = PAH_ECG_AFIB_STATUS_IDLE;\r
+ ecg_electrode_touch_reset();\r
}\r
\r
void pah831x_stress_stop(void)\r
return ret_hrv;\r
}\r
\r
-void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status, uint8_t *touch_flag)\r
+void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status ,uint8_t *touch_flag)\r
{\r
if (ecg_hr != NULL) {\r
*ecg_hr = ret_ecg_afib_hr;\r
if (status != NULL) {\r
*status = ret_ecg_afib_status;\r
}\r
- pah831x_fill_ecg_touch_flag(touch_flag);\r
+ if (touch_flag != NULL) {\r
+ *touch_flag = pah831x_get_ecg_electrode_touch();\r
+ }\r
}\r
\r
void pah831x_get_ecg_bp(int *sbp, int *dbp, uint8_t *status, uint8_t *touch_flag)\r
if (status != NULL) {\r
*status = ret_ecg_bp_status;\r
}\r
- pah831x_fill_ecg_touch_flag(touch_flag);\r
+ if (touch_flag != NULL) {\r
+ *touch_flag = pah831x_get_ecg_electrode_touch();\r
+ }\r
}\r
\r
uint8_t pah831x_get_wear_status(void)\r