From ddfa953c678ab61310578c7933476331e08e8b30 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 13 May 2024 17:29:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96leadoff=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/app_service/ecg_service/ecg_service.c | 73 +++++++++++++++++---------- app/src/aproject_config/config.h | 2 +- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/app/src/app_service/ecg_service/ecg_service.c b/app/src/app_service/ecg_service/ecg_service.c index 2ae2416..1370b7b 100644 --- a/app/src/app_service/ecg_service/ecg_service.c +++ b/app/src/app_service/ecg_service/ecg_service.c @@ -17,6 +17,8 @@ static bool m_report_data_in_raw_mode_flag; static bool m_leadoffstate; uint8_t m_leadoff_raw_state; +static uint32_t predata_filter_cnt = 0; + /*********************************************************************************************************************** * PRIVATE_FUNC * ***********************************************************************************************************************/ @@ -203,41 +205,59 @@ static void leadoff_state_process(ads129x_capture_data_t* capture_data) { * * */ + if (!m_leadoffstate) { + /** + * @brief 导联脱落检测 + */ + static uint32_t un_lead_off_cnt = 0; + bool leadoff = false; + if (capture_data->ch1data > 34000 || capture_data->ch1data < -34000) { + leadoff = true; + } - static uint32_t un_leadoffcnt = 0; - - bool leadoff = false; - // if (ecg_algo_get_peak2peak() > 15000) { - // leadoff = true; - // } - // if (ecg_algo_get_peak2peak() < 500) { - // leadoff = true; - // } - if (capture_data->ch1data > INT16_MAX || capture_data->ch1data < INT16_MIN) { - leadoff = true; - - } - // if (capture_data->loffstate & 0x3) { - // leadoff = true; - // } + if (leadoff) { + un_lead_off_cnt++; + } else { + un_lead_off_cnt = 0; + } + + if (un_lead_off_cnt > 10) { + un_lead_off_cnt = 0; + m_leadoffstate = true; + } - if (leadoff) { - un_leadoffcnt = 0; } else { - un_leadoffcnt++; - } + /** + * @brief 导联恢复检测 + */ - if (leadoff != m_leadoffstate) { - if (m_leadoffstate && un_leadoffcnt > 500) { - m_leadoffstate = false; + static uint32_t cnt = 0; + + int32_t absraw = capture_data->ch1data; + if (absraw < 0) { + absraw = -absraw; + } + + if (absraw < 25000) { + cnt++; } else { - m_leadoffstate = true; + cnt = 0; + } + + if (cnt > 10) { + cnt = 0; + m_leadoffstate = false; } } } static void ads1291_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { static ads129x_capture_data_t capture_data; + predata_filter_cnt++; + if (predata_filter_cnt < 500) { + return; + } + // 读 ads129x_read_data(&capture_data); @@ -248,7 +268,7 @@ static void ads1291_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t a // 上报 one_frame_t frame; if (m_report_data_in_raw_mode_flag) { - frame.data = capture_data.ch1data; + frame.data = capture_data.ch1data * 0.5; } else { frame.data = ecg_algo_get_report_data(); } @@ -353,6 +373,8 @@ static bool m_work_state; void ecg_service_start_capture() { // if (m_work_state) return; + predata_filter_cnt = 0; + ecg_data_mgr_clear_buffer(); static ads129x_regs_t regcache; @@ -380,7 +402,6 @@ void ecg_service_start_capture() { // } ads129x_write_regs(®cache); - ads129x_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ ecg_service_captured_time = znordic_getpower_on_ms(); m_leadoffstate = true; diff --git a/app/src/aproject_config/config.h b/app/src/aproject_config/config.h index 6522921..dfc5ba1 100644 --- a/app/src/aproject_config/config.h +++ b/app/src/aproject_config/config.h @@ -7,7 +7,7 @@ #define CATEGORY "M1003" // 单导联 #define MANUFACTURER_NAME "iflytop" -#define FIRMWARE_VERSION (501) +#define FIRMWARE_VERSION (505) #define BLESTACK_VERSION 1 #define BOOTLOADER_VERSION 1 #define HARDWARE_VERSION (2)