From d6f195c7b30c6659275b5a45702d6363e0f3b978 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 3 Apr 2024 10:22:25 +0800 Subject: [PATCH] v8 --- README.md | 14 +++++++++++- app/src/basic/qrs_time_domain_zh.c | 26 +++++++++++----------- app/src/basic/version.h | 2 +- app/src/board/board_battery_state.c | 2 +- app/src/heart_wave_sample_service.c | 39 ++++++++++++++++++++++----------- app/src/heart_wave_sample_service.h | 1 + app/src/one_conduction_main.c | 5 +++-- app/src/zeeprom_fs.c | 6 +++--- libznordic | 2 +- scripter/flash.bat | 1 + scripter/flash_with_id.bat | 43 +++++++++++++++++++++++++++++++++++++ 11 files changed, 107 insertions(+), 34 deletions(-) create mode 100644 scripter/flash_with_id.bat diff --git a/README.md b/README.md index 20f7626..275244d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,12 @@ V6: V7: 1. 优化电池电量显示 - +V8: + 1. 优化心电波形显示 + 2. 优化心率显示 + 3. 解决存储不自动清空的BUG。 + 4. 解决偶尔关机时,设备启动失败的异常。 + 5. 优化电池电量范围 测试: @@ -33,4 +38,11 @@ V7: ``` 单导:休眠527ua + +日志打开: +sdk_config.h + #ifndef NRF_LOG_ENABLED + #define NRF_LOG_ENABLED 0 + #endif + ``` \ No newline at end of file diff --git a/app/src/basic/qrs_time_domain_zh.c b/app/src/basic/qrs_time_domain_zh.c index 7f8f7e3..b42291e 100644 --- a/app/src/basic/qrs_time_domain_zh.c +++ b/app/src/basic/qrs_time_domain_zh.c @@ -4,7 +4,7 @@ #include #include -#define HEART_RATE_FILTER_SIZE 5 +#define HEART_RATE_FILTER_SIZE 10 typedef struct { uint16_t data[HEART_RATE_FILTER_SIZE]; @@ -34,11 +34,11 @@ static uint16_t HeartRateMedianFilter_process(uint16_t data) { pfilter->data[pfilter->index] = data; pfilter->index++; pfilter->cnt++; - if (pfilter->index >= 5) { + if (pfilter->index >=HEART_RATE_FILTER_SIZE) { pfilter->index = 0; } - if (pfilter->cnt < 5) { + if (pfilter->cnt index++; pfilter->cnt++; - if (pfilter->index >= 5) { + if (pfilter->index >= HEART_RATE_FILTER_SIZE) { pfilter->index = 0; } - if (pfilter->cnt < 5) { + if (pfilter->cnt < HEART_RATE_FILTER_SIZE) { return data; } - return pfilter->sum / 5; + return pfilter->sum / HEART_RATE_FILTER_SIZE; } static uint16_t m_data[TABLE_SIZE]; @@ -93,7 +93,7 @@ static uint32_t m_max_val_in_m_data; static bool m_findpeak = false; -static uint16_t pQRS_median_filter_cache[5]; +static uint16_t pQRS_median_filter_cache[HEART_RATE_FILTER_SIZE]; static uint16_t pQRS_median_filter_cache_index = 0; static uint16_t pQRS_median_filter_cache_cnt = 0; @@ -105,18 +105,18 @@ static uint16_t pQRS_median_filter(uint16_t indata) { pQRS_median_filter_cache[pQRS_median_filter_cache_index] = indata; pQRS_median_filter_cache_index++; pQRS_median_filter_cache_cnt++; - if (pQRS_median_filter_cache_index >= 5) { + if (pQRS_median_filter_cache_index >= HEART_RATE_FILTER_SIZE) { pQRS_median_filter_cache_index = 0; } - if (pQRS_median_filter_cache_cnt < 5) { + if (pQRS_median_filter_cache_cnt < HEART_RATE_FILTER_SIZE) { return indata; } - static uint16_t process_cache[5]; - memcpy(process_cache, pQRS_median_filter_cache, 5 * sizeof(uint16_t)); - for (uint8_t i = 0; i < 5; i++) { - for (uint8_t j = i + 1; j < 5; j++) { + static uint16_t process_cache[HEART_RATE_FILTER_SIZE]; + memcpy(process_cache, pQRS_median_filter_cache, HEART_RATE_FILTER_SIZE * sizeof(uint16_t)); + for (uint8_t i = 0; i < HEART_RATE_FILTER_SIZE; i++) { + for (uint8_t j = i + 1; j < HEART_RATE_FILTER_SIZE; j++) { if (process_cache[i] > process_cache[j]) { uint16_t temp = process_cache[i]; process_cache[i] = process_cache[j]; diff --git a/app/src/basic/version.h b/app/src/basic/version.h index 9c30822..40747f5 100644 --- a/app/src/basic/version.h +++ b/app/src/basic/version.h @@ -2,7 +2,7 @@ #define CATEGORY "M1001" // 单导联 #define MANUFACTURER_NAME "iflytop" -#define FIRMWARE_VERSION (7) +#define FIRMWARE_VERSION (8) #define BLESTACK_VERSION 1 #define BOOTLOADER_VERSION 1 #define HARDWARE_VERSION (1) diff --git a/app/src/board/board_battery_state.c b/app/src/board/board_battery_state.c index 283b74f..63f3490 100644 --- a/app/src/board/board_battery_state.c +++ b/app/src/board/board_battery_state.c @@ -65,7 +65,7 @@ static int16_t battery_level_filter(int16_t nowlevel) { int16_t BoardBattery_get_battery_level() { static const float maxv = 4.15; - static const float minv = 3.6; + static const float minv = 3.75; int16_t rawval = BoardBattery_get_adc_val(); diff --git a/app/src/heart_wave_sample_service.c b/app/src/heart_wave_sample_service.c index bccc93f..0189be9 100644 --- a/app/src/heart_wave_sample_service.c +++ b/app/src/heart_wave_sample_service.c @@ -15,7 +15,8 @@ static uint16_t m_capture_buffer_index = 0; volatile static float m_sensor_display_data = 0; // 0->100 static uint32_t m_start_capture_tp; -static uint32_t m_frame_index = 0; +static uint32_t m_frame_index = 0; +static bool m_prepare_capture = false; static one_frame_data_t m_sensor_little_frame_cache[LITTLE_DATA_BLOCK_FRAME_NUM]; static uint32_t m_little_frame_index; @@ -126,11 +127,11 @@ uint16_t getRecommendedMagnification() { // return 0; uint16_t max = QRS_getMaxValueLastVal(); if (max == 0) { - return 1; + return 15; } // 3750.0f if (max <= (3750 / 2)) { - return 1; + return 15; } float af = (3750 / 2) / (max - 3750 / 2); if (af > 15) { @@ -149,15 +150,17 @@ void nrfx_timer_event_handler(nrf_timer_event_t event_type, void* p_context) { // QRS_getMaxValueLastVal(); int16_t lowpassf_val = LPFilter_Update(&m_lpfilter_01, val); QRS_processData(lowpassf_val); - float val_af100 = (float)lowpassf_val / 3750.0f * 100; // 参考电压为3.6v,但信号范围为3.3v - m_frame_index++; + float val_af100 = (float)lowpassf_val / 3750.0f * 100; // 参考电压为3.6v,但信号范围为3.3v val_af100 = amp_val(val_af100, 50, getRecommendedMagnification()); val_af100 = LPFilter_Update(&m_lpfilter_02, val_af100); m_sensor_display_data = val_af100; + if (m_prepare_capture) return; + /******************************************************************************* * 采样数据缓存 * *******************************************************************************/ + m_frame_index++; if (m_capture_buffer == NULL) { swap_buffer(); } @@ -210,19 +213,31 @@ void hwss_init(void) { } } void hwss_uninit(void) { nrfx_timer_disable(&m_timer); } - -void hwss_start_capture(void) { +void hwss_start_prepare_capture(void) { m_start_capture_tp = znordic_getpower_on_s(); - swap_buffer(); - m_frame_index = 0; - LPFilter_Init(&m_lpfilter_01, 15, 0.002); - LPFilter_Init(&m_lpfilter_02, 15, 0.002); + m_prepare_capture = true; + m_frame_index = 0; + swap_buffer(); + LPFilter_Init(&m_lpfilter_01, 30, 0.002); + LPFilter_Init(&m_lpfilter_02, 30, 0.002); QRS_resetBuf(); - prvf_light_block_cache_clear(); nrfx_timer_enable(&m_timer); } +void hwss_start_capture(void) { + m_start_capture_tp = znordic_getpower_on_s(); + m_prepare_capture = false; + // swap_buffer(); + // m_frame_index = 0; + // LPFilter_Init(&m_lpfilter_01, 30, 0.002); + // LPFilter_Init(&m_lpfilter_02, 30, 0.002); + + // QRS_resetBuf(); + + // prvf_light_block_cache_clear(); + // nrfx_timer_enable(&m_timer); +} void hwss_stop_capture(void) { nrfx_timer_disable(&m_timer); m_frame_index = 0; diff --git a/app/src/heart_wave_sample_service.h b/app/src/heart_wave_sample_service.h index 65e18dc..1b12320 100644 --- a/app/src/heart_wave_sample_service.h +++ b/app/src/heart_wave_sample_service.h @@ -13,3 +13,4 @@ void hwss_stop_capture(void); float hwss_read_val(void); float hwss_read_heart_rate(void); int hwss_has_captured_time_ms(); +void hwss_start_prepare_capture(void); \ No newline at end of file diff --git a/app/src/one_conduction_main.c b/app/src/one_conduction_main.c index 83b3d4e..ed6ae0c 100644 --- a/app/src/one_conduction_main.c +++ b/app/src/one_conduction_main.c @@ -84,6 +84,7 @@ static void power_off() { BoardLight_unload(); BoardBeepCtrl_unload(); + zble_module_disconnect(); ble_cmder_stop_adv(); ble_cmder_uninit(); m_poweronflag = false; @@ -226,7 +227,7 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { if (!BoardBattery_get_charging_state()) { ds_change_to_state(kdevice_state_keep_still); dsp_mgr_change_to_preparePage(); - // hwss_pre_start_capture(); + hwss_start_prepare_capture(); } } @@ -254,7 +255,7 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { if (!BoardEcgSensor_plod_get_connected_state_after_filter()) { // 如果用户未保持静止,切换到首页 state_machine__change_to_home_state(); - // hwss_stop_capture(); + hwss_stop_capture(); } else { /******************************************************************************* * 页面加载中 * diff --git a/app/src/zeeprom_fs.c b/app/src/zeeprom_fs.c index 20b5fee..e605272 100644 --- a/app/src/zeeprom_fs.c +++ b/app/src/zeeprom_fs.c @@ -203,9 +203,9 @@ int zeeprom_fs_close(int fileid) { return -1; } - // sector_mgr_close_sector(fileHander->fileuuid); - // int32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.checksum)); - // m_eeprom_header.checksum = checksum_val; + sector_mgr_close_sector(fileHander->fileuuid); + int32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.checksum)); + m_eeprom_header.checksum = checksum_val; // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); filehandler_rlease(fileid); diff --git a/libznordic b/libznordic index a5cc523..9f78147 160000 --- a/libznordic +++ b/libznordic @@ -1 +1 @@ -Subproject commit a5cc5239adb61162d87d7109c9e6710d70c58d36 +Subproject commit 9f78147bbb47a49e378efcab6fd1c5f282931d7b diff --git a/scripter/flash.bat b/scripter/flash.bat index 0a4d9ba..f4716de 100644 --- a/scripter/flash.bat +++ b/scripter/flash.bat @@ -1,4 +1,5 @@ +@echo off echo "Start flashing..." call scripter\unlock.bat diff --git a/scripter/flash_with_id.bat b/scripter/flash_with_id.bat new file mode 100644 index 0000000..ca775fa --- /dev/null +++ b/scripter/flash_with_id.bat @@ -0,0 +1,43 @@ + +@echo off +echo "Start flashing..." + +call scripter\unlock.bat + + +@REM 烧录整体镜像 +nrfjprog --eraseall -f NRF52 %全擦除% +if %errorlevel% neq 0 ( + echo EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + echo E 擦除失败 E + echo EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + exit /b 1 +) + + +@REM 烧录lot +nrfjprog -f nrf52 --memwr 0x10001080 --val %1 +@REM 烧录ID +nrfjprog -f nrf52 --memwr 0x10001084 --val %2 + +nrfjprog --program output/app_whole.hex --verify -f NRF52 %烧录% +if %errorlevel% neq 0 ( + echo EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + echo E 烧录失败 E + echo EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + exit /b 1 +) +nrfjprog --reset -f NRF52 %复位% +if %errorlevel% neq 0 ( + echo EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + echo E 复位失败 E + echo EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + exit /b 1 +) + + +echo --------------------------------------------------------------- +echo - done +echo --------------------------------------------------------------- + +