From 4fa2d4ca389c319929e8f5cb47dc93b8a45490be Mon Sep 17 00:00:00 2001 From: 1624952103 Date: Thu, 11 Jun 2026 18:09:37 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96ECG=E6=88=BF?= =?utf8?q?=E9=A2=A4=E5=92=8C=E8=A1=80=E5=8E=8B=E7=BB=93=E6=9E=9C=E6=8E=A5?= =?utf8?q?=E5=8F=A3,=E5=A2=9E=E5=8A=A0=E7=94=B5=E6=9E=81=E8=A7=A6=E6=91=B8?= =?utf8?q?=E5=80=BC=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c | 14 ++++-- code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h | 27 ++++++------ .../ppg/pah831x/pah_sensor/pah831x_main.c | 43 +++++++++++++++---- .../ppg/pah831x/pah_sensor/pah831x_main.h | 4 +- 4 files changed, 61 insertions(+), 27 deletions(-) diff --git a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c index 8ce83b1d4..df95e009b 100644 --- a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c +++ b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c @@ -137,7 +137,7 @@ uint8_t ppg_get_hrv(void) return hrv; } -void ppg_get_ecg_bp(int *sbp, int *dbp, uint8_t *status) +void ppg_get_ecg_bp(int *sbp, int *dbp, uint8_t *status, uint8_t *touch_flag) { if (sbp != NULL) { *sbp = 0; @@ -148,9 +148,12 @@ void ppg_get_ecg_bp(int *sbp, int *dbp, uint8_t *status) if (status != NULL) { *status = PPG_ECG_BP_STATUS_MEASURING; } + if (touch_flag != NULL) { + *touch_flag = 0; + } #if defined PPG_PAH831X - pah831x_get_ecg_bp(sbp, dbp, status); + pah831x_get_ecg_bp(sbp, dbp, status, touch_flag); #endif } @@ -180,7 +183,7 @@ uint32_t ppg_read_ecg_raw(int32_t *buf, uint32_t buf_len) #endif } -void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status) +void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status, uint8_t *touch_flag) { if (ecg_hr != NULL) { *ecg_hr = 0; @@ -191,9 +194,12 @@ void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status) if (status != NULL) { *status = PPG_ECG_AFIB_STATUS_IDLE; } + if (touch_flag != NULL) { + *touch_flag = 0; + } #if defined PPG_PAH831X - pah831x_get_ecg_afib(ecg_hr, afib_result, status); + pah831x_get_ecg_afib(ecg_hr, afib_result, status, touch_flag); #endif } diff --git a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h index d1bc7edf0..3112e9ba7 100644 --- a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h +++ b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h @@ -38,6 +38,15 @@ extern "C" { #define PPG_ECG_AFIB_RESULT_INVALID 0xFF +#define PPG_ECG_BP_STATUS_MEASURING 0 /* 测量中 */ +#define PPG_ECG_BP_STATUS_WEAK_SIGNAL 1 /* ECG已停止,疑似信号弱,请重新测试 */ + +#define PPG_ECG_AFIB_STATUS_IDLE 0 /* 未开始测量 */ +#define PPG_ECG_AFIB_STATUS_MEASURING 1 /* 测量中 */ +#define PPG_ECG_AFIB_STATUS_FAILED 2 /* 测量失败(ready sqi>0 停测、超时等) */ +#define PPG_ECG_AFIB_STATUS_SUCCESS 3 /* 测量成功,已出结论 */ + + typedef uint32_t PPG_CMD_TYPE_T ; typedef enum{ @@ -85,26 +94,20 @@ bool is_ppg_bp_need_cali(void); * 开始/停止 ecgbp、ecgafib、ecgraw 时驱动内部自动清缓冲。 */ uint32_t ppg_read_ecg_raw(int32_t *buf, uint32_t buf_len); -#define PPG_ECG_AFIB_STATUS_IDLE 0 /* 未开始测量 */ -#define PPG_ECG_AFIB_STATUS_MEASURING 1 /* 测量中 */ -#define PPG_ECG_AFIB_STATUS_FAILED 2 /* 测量失败(ready sqi>0 停测、超时等) */ -#define PPG_ECG_AFIB_STATUS_SUCCESS 3 /* 测量成功,已出结论 */ - /* 获取 ECG 房颤测试结果。 * ecg_hr: ECG 心率(bpm),测量过程中持续更新; * afib_result: 房颤结论,未开始/测量中/失败时为 0xFF * 0 窦性心律 1 不确定(不规则) 2 可能房颤 * 3 不确定(信号/特征) 4 心率过低 5 心率过高 - * status: 0 未开始 1 测量中 2 测量失败 3 测量成功(已出结论) */ -void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status); - -#define PPG_ECG_BP_STATUS_MEASURING 0 /* 测量中 */ -#define PPG_ECG_BP_STATUS_WEAK_SIGNAL 1 /* ECG已停止,疑似信号弱,请重新测试 */ + * status: 0 未开始 1 测量中 2 测量失败 3 测量成功(已出结论) + * touch_flag:电极触摸标志 0 未触摸 1 已触摸 */ +void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status, uint8_t *ecg_touch_flag); /* 获取 ECG 血压测量结果。 * sbp/dbp: 收缩压/舒张压,未出结果时为 0; - * status: 0 测量中 1 ECG已停止(疑似信号弱,请重新测试) */ -void ppg_get_ecg_bp(int *sbp, int *dbp, uint8_t *status); + * status: 0 测量中 1 ECG已停止(疑似信号弱,请重新测试) + * touch_flag: 电极触摸标志 0 未触摸 1 已触摸 */ +void ppg_get_ecg_bp(int *sbp, int *dbp, uint8_t *status, uint8_t *ecg_touch_flag); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c index 8254cabe2..c282cd11a 100644 --- a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c +++ b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c @@ -784,7 +784,7 @@ static void send_fifo_data(main_state *this, uint8_t *fifo, uint16_t data_count, duration =(uint32_t)(this->task_timestamp - this->prev_task_timestamp ); _ecg_data_out.ecg_data_ready++; _ecg_data_out.duration = duration; - _ecg_data_out.is_touched = 1 ; + _ecg_data_out.is_touched = _state.core.touch_flag ? 1U : 0U; _ecg_data_out.ch_num = 1 ; _ecg_data_out.sample_num_per_ch = ecg_sample_num ; @@ -811,7 +811,7 @@ static void send_fifo_data(main_state *this, uint8_t *fifo, uint16_t data_count, duration =(uint32_t)(this->task_timestamp - this->prev_task_timestamp ); _ecg_data_out.ecg_data_ready++; _ecg_data_out.duration = duration; - //_ecg_data_out.is_touched = 1 ; + _ecg_data_out.is_touched = _state.core.touch_flag ? 1U : 0U; _ecg_data_out.ch_num = 1 ; _ecg_data_out.sample_num_per_ch = ecg_sample_num ; _ppg_data_out.ppg_data_ready++; @@ -1021,15 +1021,33 @@ void set_ir_r_led_switch_status(bool status) _state.core.ir_r_led_switch_new_status = status; } -uint16_t get_pah831x_touch_value() +uint16_t get_pah831x_touch_value(void) { - uint16_t pah831x_touch_value = 0 ; + uint16_t touch_value = 0; - pah831x_read_touch_value(&_state.core, &pah831x_touch_value); - - return pah831x_touch_value ; + pah831x_read_touch_value(&_state.core, &touch_value); + return touch_value; +} + +static void pah831x_fill_ecg_touch_flag(uint8_t *touch_flag) +{ + bool flag = false; + + if (touch_flag == NULL) { + return; + } + + pah831x_read_touch_flag(&_state.core, &flag); + *touch_flag = flag ? 1U : 0U; } +static void pah831x_reset_ecg_touch_cache(void) +{ + _state.touch_status = TOUCH_STATUS__UNKNOWN; + _state.core.touch_flag = false; + _state.core.touch_value = 0; + _ecg_data_out.is_touched = 0; +} static void get_avg_hrs(uint8_t hrs) { @@ -1768,12 +1786,14 @@ void pah831x_ecg_bp_start(uint8_t cmd) if(calibration_mode==ECG_PPG_BP_CALI) { pah831x_sensor_init(); + pah831x_reset_ecg_touch_cache(); pah831x_sensor_start(PAH831X_WORK_POLLING, PAH831X_INIT_ALWAYS_RUN, PAH831X_PPG_REG_SETTING_IDLE, PAH831X_ECG_REG_SETTING_2, 128, 3.90625f); ecg_bp_algorithm_init(); }else if(calibration_mode==ECG_PPG_BP_ESTIMATE) { pah831x_sensor_init(); + pah831x_reset_ecg_touch_cache(); pah831x_sensor_start(PAH831X_WORK_POLLING, PAH831X_INIT_ALWAYS_RUN, PAH831X_PPG_REG_SETTING_IDLE, PAH831X_ECG_REG_SETTING_2, 128, 3.90625f); ecg_bp_algorithm_init(); //calibration_mode = ECG_PPG_BP_ESTIMATE; @@ -1816,6 +1836,7 @@ void pah831x_ecg_afib_start(void) ret_ecg_afib_status = PAH_ECG_AFIB_STATUS_MEASURING; ecg_afib_algorithm_init(); pah831x_sensor_init(); + pah831x_reset_ecg_touch_cache(); pah831x_sensor_start(PAH831X_WORK_POLLING ,PAH831X_INIT_ALWAYS_RUN,PAH831X_PPG_REG_SETTING_IDLE ,PAH831X_ECG_REG_SETTING_1,256,3.91f ); } @@ -1863,6 +1884,7 @@ void pah831x_ecgbp_stop(void) pah_sensor_stop(); ecg_bp_algorithm_close(); + pah831x_reset_ecg_touch_cache(); if(calibration_mode == ECG_PPG_BP_CALI) { @@ -1875,6 +1897,7 @@ void pah831x_ecg_afib_stop(void) pah_sensor_stop(); ecg_afib_algorithm_close(); ecg_afib_algorithm_init(); + pah831x_reset_ecg_touch_cache(); ret_ecg_afib_hr = 0; ret_ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID; @@ -2175,7 +2198,7 @@ uint8_t pah831x_get_hrv(void) return ret_hrv; } -void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status) +void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status, uint8_t *touch_flag) { if (ecg_hr != NULL) { *ecg_hr = ret_ecg_afib_hr; @@ -2186,14 +2209,16 @@ void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status if (status != NULL) { *status = ret_ecg_afib_status; } + pah831x_fill_ecg_touch_flag(touch_flag); } -void pah831x_get_ecg_bp(int *sbp, int *dbp, uint8_t *status) +void pah831x_get_ecg_bp(int *sbp, int *dbp, uint8_t *status, uint8_t *touch_flag) { pah_ecg_bp_get_bp(sbp, dbp); if (status != NULL) { *status = ret_ecg_bp_status; } + pah831x_fill_ecg_touch_flag(touch_flag); } uint8_t pah831x_get_wear_status(void) diff --git a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h index b790fb117..d287b01f5 100644 --- a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h +++ b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h @@ -369,9 +369,9 @@ uint8_t pah831x_get_spo2(void); uint8_t pah831x_get_hrv(void); -void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status); +void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status, uint8_t *touch_flag); -void pah831x_get_ecg_bp(int *sbp, int *dbp, uint8_t *status); +void pah831x_get_ecg_bp(int *sbp, int *dbp, uint8_t *status, uint8_t *touch_flag); void pah8311_get_bp(int *sbp,int *dbp); -- 2.17.1