From 3864c542a3c68fceb3f99834372144d406d0f325 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Fri, 9 Feb 2024 17:21:56 +0800 Subject: [PATCH] update --- README.md | 15 +++ app/app.uvoptx | 174 ++++++++++++++++-------------- app/app.uvprojx | 10 ++ app/src/basic/version.h | 2 +- app/src/board/board.h | 36 +++---- app/src/board/board_beep_ctrl.c | 140 +++++++++++++++++++++++++ app/src/board/board_beep_ctrl.h | 26 +++++ app/src/one_conduction_board.c | 52 +-------- app/src/one_conduction_board.h | 8 +- app/src/one_conduction_main.c | 227 +++++++++++++++++++++------------------- scripter/build_app.bat | 12 ++- 11 files changed, 433 insertions(+), 269 deletions(-) create mode 100644 app/src/board/board_beep_ctrl.c create mode 100644 app/src/board/board_beep_ctrl.h diff --git a/README.md b/README.md index 31441b6..1cc331a 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,19 @@ ``` TODO +0. 支持无线升级,修改SN码 +6. 开始采集蜂鸣器响响三声,结束采集蜂鸣器响三声 +1. 添加逻辑,如果未配置时间,设备进入深度休眠。 +2. 修改电池电量相关逻辑,校准电池电量。 +3. 修改心率采样ADC参考电压 +4. 修改屏幕显示位置 +5. 充电中,限制用户操作 +6. 调整ADC放大倍数 + + +测试: +1. 电池电量测试 +2. 充电插入检测 + + ... diff --git a/app/app.uvoptx b/app/app.uvoptx index 446f0dd..972c44d 100644 --- a/app/app.uvoptx +++ b/app/app.uvoptx @@ -612,6 +612,18 @@ 0 0 + + 1 + 20 + 1 + 0 + 0 + 0 + .\src\board\board_beep_ctrl.c + board_beep_ctrl.c + 0 + 0 + @@ -622,7 +634,7 @@ 0 2 - 20 + 21 1 0 0 @@ -642,7 +654,7 @@ 0 3 - 21 + 22 1 0 0 @@ -654,7 +666,7 @@ 3 - 22 + 23 1 0 0 @@ -674,7 +686,7 @@ 0 4 - 23 + 24 1 0 0 @@ -694,7 +706,7 @@ 0 5 - 24 + 25 1 0 0 @@ -706,7 +718,7 @@ 5 - 25 + 26 1 0 0 @@ -718,7 +730,7 @@ 5 - 26 + 27 1 0 0 @@ -730,7 +742,7 @@ 5 - 27 + 28 1 0 0 @@ -742,7 +754,7 @@ 5 - 28 + 29 1 0 0 @@ -754,7 +766,7 @@ 5 - 29 + 30 1 0 0 @@ -766,7 +778,7 @@ 5 - 30 + 31 1 0 0 @@ -778,7 +790,7 @@ 5 - 31 + 32 1 0 0 @@ -798,7 +810,7 @@ 0 6 - 32 + 33 1 0 0 @@ -818,7 +830,7 @@ 0 7 - 33 + 34 1 0 0 @@ -830,7 +842,7 @@ 7 - 34 + 35 1 0 0 @@ -842,7 +854,7 @@ 7 - 35 + 36 1 0 0 @@ -854,7 +866,7 @@ 7 - 36 + 37 1 0 0 @@ -866,7 +878,7 @@ 7 - 37 + 38 1 0 0 @@ -878,7 +890,7 @@ 7 - 38 + 39 1 0 0 @@ -890,7 +902,7 @@ 7 - 39 + 40 1 0 0 @@ -902,7 +914,7 @@ 7 - 40 + 41 1 0 0 @@ -914,7 +926,7 @@ 7 - 41 + 42 1 0 0 @@ -926,7 +938,7 @@ 7 - 42 + 43 1 0 0 @@ -938,7 +950,7 @@ 7 - 43 + 44 1 0 0 @@ -950,7 +962,7 @@ 7 - 44 + 45 1 0 0 @@ -962,7 +974,7 @@ 7 - 45 + 46 1 0 0 @@ -974,7 +986,7 @@ 7 - 46 + 47 1 0 0 @@ -986,7 +998,7 @@ 7 - 47 + 48 1 0 0 @@ -998,7 +1010,7 @@ 7 - 48 + 49 1 0 0 @@ -1010,7 +1022,7 @@ 7 - 49 + 50 1 0 0 @@ -1022,7 +1034,7 @@ 7 - 50 + 51 1 0 0 @@ -1034,7 +1046,7 @@ 7 - 51 + 52 1 0 0 @@ -1046,7 +1058,7 @@ 7 - 52 + 53 1 0 0 @@ -1066,7 +1078,7 @@ 0 8 - 53 + 54 1 0 0 @@ -1078,7 +1090,7 @@ 8 - 54 + 55 1 0 0 @@ -1090,7 +1102,7 @@ 8 - 55 + 56 1 0 0 @@ -1102,7 +1114,7 @@ 8 - 56 + 57 1 0 0 @@ -1114,7 +1126,7 @@ 8 - 57 + 58 1 0 0 @@ -1126,7 +1138,7 @@ 8 - 58 + 59 1 0 0 @@ -1138,7 +1150,7 @@ 8 - 59 + 60 1 0 0 @@ -1150,7 +1162,7 @@ 8 - 60 + 61 1 0 0 @@ -1162,7 +1174,7 @@ 8 - 61 + 62 1 0 0 @@ -1174,7 +1186,7 @@ 8 - 62 + 63 1 0 0 @@ -1186,7 +1198,7 @@ 8 - 63 + 64 1 0 0 @@ -1198,7 +1210,7 @@ 8 - 64 + 65 1 0 0 @@ -1210,7 +1222,7 @@ 8 - 65 + 66 1 0 0 @@ -1222,7 +1234,7 @@ 8 - 66 + 67 1 0 0 @@ -1234,7 +1246,7 @@ 8 - 67 + 68 1 0 0 @@ -1246,7 +1258,7 @@ 8 - 68 + 69 1 0 0 @@ -1258,7 +1270,7 @@ 8 - 69 + 70 1 0 0 @@ -1270,7 +1282,7 @@ 8 - 70 + 71 1 0 0 @@ -1282,7 +1294,7 @@ 8 - 71 + 72 1 0 0 @@ -1294,7 +1306,7 @@ 8 - 72 + 73 1 0 0 @@ -1306,7 +1318,7 @@ 8 - 73 + 74 1 0 0 @@ -1318,7 +1330,7 @@ 8 - 74 + 75 1 0 0 @@ -1330,7 +1342,7 @@ 8 - 75 + 76 1 0 0 @@ -1342,7 +1354,7 @@ 8 - 76 + 77 1 0 0 @@ -1354,7 +1366,7 @@ 8 - 77 + 78 1 0 0 @@ -1366,7 +1378,7 @@ 8 - 78 + 79 1 0 0 @@ -1378,7 +1390,7 @@ 8 - 79 + 80 1 0 0 @@ -1398,7 +1410,7 @@ 0 9 - 80 + 81 1 0 0 @@ -1410,7 +1422,7 @@ 9 - 81 + 82 1 0 0 @@ -1422,7 +1434,7 @@ 9 - 82 + 83 1 0 0 @@ -1434,7 +1446,7 @@ 9 - 83 + 84 1 0 0 @@ -1446,7 +1458,7 @@ 9 - 84 + 85 1 0 0 @@ -1458,7 +1470,7 @@ 9 - 85 + 86 1 0 0 @@ -1478,7 +1490,7 @@ 0 10 - 86 + 87 1 0 0 @@ -1490,7 +1502,7 @@ 10 - 87 + 88 1 0 0 @@ -1502,7 +1514,7 @@ 10 - 88 + 89 1 0 0 @@ -1522,7 +1534,7 @@ 0 11 - 89 + 90 1 0 0 @@ -1534,7 +1546,7 @@ 11 - 90 + 91 1 0 0 @@ -1546,7 +1558,7 @@ 11 - 91 + 92 1 0 0 @@ -1566,7 +1578,7 @@ 0 12 - 92 + 93 1 0 0 @@ -1578,7 +1590,7 @@ 12 - 93 + 94 1 0 0 @@ -1590,7 +1602,7 @@ 12 - 94 + 95 1 0 0 @@ -1610,7 +1622,7 @@ 0 13 - 95 + 96 1 0 0 @@ -1622,7 +1634,7 @@ 13 - 96 + 97 1 0 0 @@ -1642,7 +1654,7 @@ 0 14 - 97 + 98 1 0 0 @@ -1654,7 +1666,7 @@ 14 - 98 + 99 1 0 0 @@ -1666,7 +1678,7 @@ 14 - 99 + 100 1 0 0 @@ -1678,7 +1690,7 @@ 14 - 100 + 101 1 0 0 diff --git a/app/app.uvprojx b/app/app.uvprojx index 19323f3..73e2ba1 100644 --- a/app/app.uvprojx +++ b/app/app.uvprojx @@ -478,6 +478,11 @@ 1 .\src\main.c + + board_beep_ctrl.c + 1 + .\src\board\board_beep_ctrl.c + @@ -4337,6 +4342,11 @@ 1 .\src\main.c + + board_beep_ctrl.c + 1 + .\src\board\board_beep_ctrl.c + diff --git a/app/src/basic/version.h b/app/src/basic/version.h index 93078c5..566d0b0 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 0x0001 +#define FIRMWARE_VERSION (1) #define BLESTACK_VERSION 1 #define BOOTLOADER_VERSION 1 #define HARDWARE_VERSION (1) diff --git a/app/src/board/board.h b/app/src/board/board.h index a3507a3..c2f8de9 100644 --- a/app/src/board/board.h +++ b/app/src/board/board.h @@ -1,26 +1,24 @@ #pragma once -/** - * @brief - * - * 200HZ,16bit - * -> - * 1s => 200*2 => 400BYTE - * 248k - * -> - * 1s => 248*1024/400 => 634_S => 10.5min - */ +/******************************************************************************* + * BEEP * + *******************************************************************************/ +#define BEEP_PIN 1 +#define BEEP_PWM_INSTANCE 0 -#define MAX_STORAGE_TIMEOUT_S (60 * 10) -#define MAX_STORAGE_SIZE (MAX_STORAGE_TIMEOUT_S * 400) // 存储最大限制为 (256-8)kbyte -#define MAX_FILE_NUM 10 -#define SAMPLE_RATE 500 -#define SAMPLE_PRECISION 12 -#define AUTOMATIC_SLEEP_TIME 15000 -#define SAMPLE_MIN_TIME_S (30.0) +/** + * @brief + */ -// #define ENABLE_SLEEP +#define MAX_STORAGE_TIMEOUT_S (60 * 10) // 最长存储时间 +#define MAX_STORAGE_SIZE (MAX_STORAGE_TIMEOUT_S * 400) // 存储最大限制为 (256-8)kbyte +#define MAX_FILE_NUM 10 // 最多存储条目数 +#define SAMPLE_RATE 500 // 采样率 +#define SAMPLE_PRECISION 12 // 采样精度 +#define AUTOMATIC_SLEEP_TIME 30000 // 开机后自动休眠时间 +#define SAMPLE_MIN_TIME_S (30.0) // 采样最小时间 +#define LITTLE_DATA_BLOCK_FRAME_NUM 5 // 每次多少帧上报一次 -#define LITTLE_DATA_BLOCK_FRAME_NUM 5 // 每次多少帧上报一次 +#define KEEP_STILL_OVERTIME_MS_1P5 2000 // 保持静止超时时间的1/6 diff --git a/app/src/board/board_beep_ctrl.c b/app/src/board/board_beep_ctrl.c new file mode 100644 index 0000000..1803e7d --- /dev/null +++ b/app/src/board/board_beep_ctrl.c @@ -0,0 +1,140 @@ +#include "board_beep_ctrl.h" +#define BEEP_TIMER_INTERVAL (150) +#if 1 + +APP_TIMER_DEF(m_beep_tmr); // +static nrf_drv_pwm_t m_beep_pwm0 = NRF_DRV_PWM_INSTANCE(BEEP_PWM_INSTANCE); +static nrf_pwm_values_individual_t m_beep_pwm0_seq_values = {0}; +static nrf_pwm_sequence_t const m_beep_pwm0_seq = { + .values.p_individual = &m_beep_pwm0_seq_values, + .length = NRF_PWM_VALUES_LENGTH(m_beep_pwm0_seq_values), + .repeats = 0, + .end_delay = 0, +}; +static nrf_drv_pwm_config_t const m_beep_pwm0_config0 = { + .output_pins = + { + BEEP_PIN, // + NRF_DRV_PWM_PIN_NOT_USED, + NRF_DRV_PWM_PIN_NOT_USED, + NRF_DRV_PWM_PIN_NOT_USED, + }, + .irq_priority = APP_IRQ_PRIORITY_LOWEST, + .base_clock = NRF_PWM_CLK_125kHz, + .count_mode = NRF_PWM_MODE_UP, + .top_value = 80, // 125kHz / 46 = 2.717k + .load_mode = NRF_PWM_LOAD_INDIVIDUAL, + .step_mode = NRF_PWM_STEP_AUTO, +}; +BoardBeepEffect_t m_beep_effect = kBoardBeepEffect_none; +static uint32_t m_beep_cnt = 0; + +static void beep_tmr_handler(void *context) { + if (m_beep_effect == kBoardBeepEffect_none) { + BoardBeepCtrl_set(false); + } else if (m_beep_effect == kBoardBeepEffect_oneShortBeep) { + if (m_beep_cnt == 0) { + BoardBeepCtrl_set(true); + } else if (m_beep_cnt >= 1) { + BoardBeepCtrl_set(false); + app_timer_stop(m_beep_tmr); + m_beep_effect = kBoardBeepEffect_none; + } + } + + else if (m_beep_effect == kBoardBeepEffect_oneShortLongBeep) { + if (m_beep_cnt == 0) { + BoardBeepCtrl_set(true); + } else if (m_beep_cnt >= 6) { + BoardBeepCtrl_set(false); + app_timer_stop(m_beep_tmr); + m_beep_effect = kBoardBeepEffect_none; + } + } + + else if (m_beep_effect == kBoardBeepEffect_threeShortBeep) { + if (m_beep_cnt < 6) { + if (m_beep_cnt % 2 == 0) { + BoardBeepCtrl_set(true); + } else if (m_beep_cnt % 2 == 1) { + BoardBeepCtrl_set(false); + } + } else { + BoardBeepCtrl_set(false); + app_timer_stop(m_beep_tmr); + m_beep_effect = kBoardBeepEffect_none; + } + + } else if (m_beep_effect == kBoardBeepEffect_continuousShortBeep) { + // 每隔1秒响三声 + if (m_beep_cnt < 6) { + if (m_beep_cnt % 2 == 0) { + BoardBeepCtrl_set(true); + } else if (m_beep_cnt % 2 == 1) { + BoardBeepCtrl_set(false); + } + } else { + if (BEEP_TIMER_INTERVAL * m_beep_cnt >= 10000) { + m_beep_cnt = 0; + return; + } + } + } + m_beep_cnt++; +} + +void BoardBeepCtrl_init(void) { // + app_timer_create(&m_beep_tmr, APP_TIMER_MODE_REPEATED, beep_tmr_handler); +} +static bool m_beep_loaded = false; + +void BoardBeepCtrl_load() { // + if (m_beep_loaded) return; + + APP_ERROR_CHECK(nrfx_pwm_init(&m_beep_pwm0, &m_beep_pwm0_config0, NULL)); + m_beep_loaded = true; +} +void BoardBeepCtrl_unload() { + if (!m_beep_loaded) return; + + BoardBeepCtrl_set(0); + nrfx_pwm_uninit(&m_beep_pwm0); + m_beep_loaded = false; +} + +void BoardBeepCtrl_set(uint8_t state) { + if (state) { + m_beep_pwm0_seq_values.channel_0 = 10; // 设置占空比,数值最大不超过 top_value + nrfx_pwm_simple_playback(&m_beep_pwm0, &m_beep_pwm0_seq, 1, NRF_DRV_PWM_FLAG_LOOP); + } else { + nrfx_pwm_stop(&m_beep_pwm0, true); + } +} + +void BoardBeepCtrl_setEffect(BoardBeepEffect_t effect) { + if (m_beep_effect == effect) return; + + m_beep_effect = effect; + + app_timer_stop(m_beep_tmr); + m_beep_cnt = 0; + if (m_beep_effect == kBoardBeepEffect_none) { + BoardBeepCtrl_set(false); + } + + else { + app_timer_start(m_beep_tmr, APP_TIMER_TICKS(BEEP_TIMER_INTERVAL), NULL); + } +} + +#else + +void BoardBeepCtrl_init(void) {} +void BoardBeepCtrl_load() {} + +void BoardBeepCtrl_unload() {} + +void BoardBeepCtrl_set(uint8_t state) {} + +void BoardBeepCtrl_setEffect(BoardBeepEffect_t effect) {} +#endif \ No newline at end of file diff --git a/app/src/board/board_beep_ctrl.h b/app/src/board/board_beep_ctrl.h new file mode 100644 index 0000000..6aef541 --- /dev/null +++ b/app/src/board/board_beep_ctrl.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "board/board.h" +#include "znordic.h" + +typedef enum { + kBoardBeepEffect_none = 0, + // 响一声 + kBoardBeepEffect_oneShortBeep, + // 响一声长鸣 + kBoardBeepEffect_oneShortLongBeep, + // 响三声 + kBoardBeepEffect_threeShortBeep, + // 持续短鸣报警 + kBoardBeepEffect_continuousShortBeep, +} BoardBeepEffect_t; + +void BoardBeepCtrl_init(void); +void BoardBeepCtrl_load(); +void BoardBeepCtrl_unload(); + +void BoardBeepCtrl_set(uint8_t beep); +void BoardBeepCtrl_setEffect(BoardBeepEffect_t effect); diff --git a/app/src/one_conduction_board.c b/app/src/one_conduction_board.c index 8eab403..0c206b0 100644 --- a/app/src/one_conduction_board.c +++ b/app/src/one_conduction_board.c @@ -41,8 +41,7 @@ #define EEPROM_I2C_SDA_M 17 // I2C SDA引脚 #define EEPROM_I2C_INSTANCE 1 // I2C使用的硬件控制器ID -#define BEEP_PWM_INSTANCE 0 -#define BEEP_PIN 1 + #define BATTERY_CHARGE_DETECT_PIN 18 @@ -91,55 +90,6 @@ void SingleLeadECG_adc_module_deinit() { } /******************************************************************************* - * 蜂鸣器 * - *******************************************************************************/ -static nrf_drv_pwm_t m_beep_pwm0 = NRF_DRV_PWM_INSTANCE(BEEP_PWM_INSTANCE); -static nrf_pwm_values_individual_t m_beep_pwm0_seq_values = {0}; -static nrf_pwm_sequence_t const m_beep_pwm0_seq = { - .values.p_individual = &m_beep_pwm0_seq_values, - .length = NRF_PWM_VALUES_LENGTH(m_beep_pwm0_seq_values), - .repeats = 0, - .end_delay = 0, -}; -static nrf_drv_pwm_config_t const m_beep_pwm0_config0 = { - .output_pins = {BEEP_PIN}, - .irq_priority = APP_IRQ_PRIORITY_LOWEST, - .base_clock = NRF_PWM_CLK_125kHz, - .count_mode = NRF_PWM_MODE_UP, - .top_value = 46, // 125kHz / 46 = 2.717k - .load_mode = NRF_PWM_LOAD_INDIVIDUAL, - .step_mode = NRF_PWM_STEP_AUTO, -}; -APP_TIMER_DEF(m_beep_tmr); // 蜂鸣器自动关闭定时器 -bool m_beep_tmr_is_inited = false; -static void beep_tmr_handler(void *context) { SingleLeadECG_beep_set_state(false); } -void SingleLeadECG_beep_init() { - if (!m_beep_tmr_is_inited) { - m_beep_tmr_is_inited = true; - app_timer_create(&m_beep_tmr, APP_TIMER_MODE_SINGLE_SHOT, beep_tmr_handler); - } - - APP_ERROR_CHECK(nrfx_pwm_init(&m_beep_pwm0, &m_beep_pwm0_config0, NULL)); -} -void SingleLeadECG_beep_deinit() { - SingleLeadECG_beep_set_state(false); - nrfx_pwm_uninit(&m_beep_pwm0); -} - -void SingleLeadECG_beep_set_state(bool state) { - if (state) { - m_beep_pwm0_seq_values.channel_0 = 23; // 设置占空比,数值最大不超过 top_value - nrfx_pwm_simple_playback(&m_beep_pwm0, &m_beep_pwm0_seq, 1, NRF_DRV_PWM_FLAG_LOOP); - } else { - nrfx_pwm_stop(&m_beep_pwm0, true); - } -} -void SingleLeadECG_beep_trigger_once() { - SingleLeadECG_beep_set_state(true); - app_timer_start(m_beep_tmr, APP_TIMER_TICKS(200), NULL); -} - -/******************************************************************************* * SCREEN * *******************************************************************************/ diff --git a/app/src/one_conduction_board.h b/app/src/one_conduction_board.h index f2c33f6..87b8401 100644 --- a/app/src/one_conduction_board.h +++ b/app/src/one_conduction_board.h @@ -16,13 +16,7 @@ void SingleLeadECG_adc_module_init(); void SingleLeadECG_adc_module_deinit(); -/******************************************************************************* - * 蜂鸣器 * - *******************************************************************************/ -void SingleLeadECG_beep_init(); -void SingleLeadECG_beep_deinit(); -void SingleLeadECG_beep_set_state(bool state); -void SingleLeadECG_beep_trigger_once(); + /******************************************************************************* * EEPROM * diff --git a/app/src/one_conduction_main.c b/app/src/one_conduction_main.c index c17c65b..5d056f5 100644 --- a/app/src/one_conduction_main.c +++ b/app/src/one_conduction_main.c @@ -2,7 +2,9 @@ #include "app_event.h" #include "app_event_distribute.h" +#include "basic/device_version_info_mgr.h" #include "ble_cmd_process_service.h" +#include "board/board_beep_ctrl.h" #include "config.h" #include "display_manager.h" #include "heart_wave_sample_service.h" @@ -11,16 +13,14 @@ #include "zble_module.h" #include "zdatachannel_service.h" #include "znordic.h" -#include "basic/device_version_info_mgr.h" /******************************************************************************* * GLOBAL * *******************************************************************************/ - -APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态机驱动定时器 -APP_TIMER_DEF(m_plod_state_event_detect_tmr); // 导联连接状态检测定时器 -APP_TIMER_DEF(m_charge_event_detect_tmr); // 充电事件检测 +APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态机驱动定时器 +APP_TIMER_DEF(m_plod_state_event_detect_tmr); // 导联连接状态检测定时器 +APP_TIMER_DEF(m_charge_event_detect_tmr); // 充电事件检测 static int m_cur_fd; static sample_data_filename_t sampledata_file_name; @@ -113,7 +113,7 @@ static void power_on() { return; } SingleLeadECG_adc_module_init(); - SingleLeadECG_beep_init(); + BoardBeepCtrl_load(); SingleLeadECG_led_init(); SingleLeadECG_ecg_init(); SingleLeadECG_battery_init(); @@ -136,7 +136,7 @@ static void power_off() { SingleLeadECG_battery_deinit(); SingleLeadECG_ecg_deinit(); SingleLeadECG_led_deinit(); - SingleLeadECG_beep_deinit(); + BoardBeepCtrl_unload(); SingleLeadECG_adc_module_deinit(); ble_cmder_stop_adv(); ble_cmder_uninit(); @@ -198,45 +198,57 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { SingleLeadECG_led_blue_set_state(false); } + /******************************************************************************* + * 待机状态 * + *******************************************************************************/ if (ds_now_state() == kdevice_state_standby) { - /******************************************************************************* - * 待机状态 * - *******************************************************************************/ + /** + * @brief + * 充电事件触发 --> 切换到充电页面 + * 导联连接事件触发 --> 切换到开机中页面 + * + */ + // if (!SingleLeadECG_battery_charge_get_state()) { - // // 切换到充电状态 // state_machine__change_to_charging_state(); // } + if (p_event->eventType == kplod_connected_event) { - // 切换到开机状态 state_machine__change_to_poweroning_state(); } - } else if (ds_now_state() == kdevice_state_charging) { - /******************************************************************************* - * 充电状态 * - *******************************************************************************/ + } + + /******************************************************************************* + * 充电状态 * + *******************************************************************************/ + else if (ds_now_state() == kdevice_state_charging) { if (!SingleLeadECG_battery_charge_get_state()) { state_machine__change_to_standby_state(); } - } else if (ds_now_state() == kdevice_state_poweron) { - /******************************************************************************* - * 开机中 * - *******************************************************************************/ + } + + /******************************************************************************* + * 开机中 * + *******************************************************************************/ + + else if (ds_now_state() == kdevice_state_poweron) { if (ds_cur_state_haspassed_ms() >= 1500) { state_machine__change_to_home_state(); } - } else if (ds_now_state() == kdevice_state_home) { - /******************************************************************************* - * 首页 * - *******************************************************************************/ - // // 如果用户长时间不操作,自动切换到待机状态 + } + + /******************************************************************************* + * 首页 * + *******************************************************************************/ + + else if (ds_now_state() == kdevice_state_home) { + // 如果用户长时间不操作,自动切换到待机状态 if (!zdatachannel_is_connected() && // !plod_state_is_connected() && // plod_state_has_disconnected_ms() >= 3000 && // ds_cur_state_haspassed_ms() >= AUTOMATIC_SLEEP_TIME) { -#ifdef ENABLE_SLEEP state_machine__change_to_standby_state(); -#endif } // 如果用户继续保持静止,切换到采集页面 else if (plod_state_is_connected() && ds_cur_state_haspassed_ms() > 1500) { @@ -245,10 +257,12 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { dsp_mgr_change_to_preparePage(); } // ZLOGI("bt:%d plod:%d has_disc:%d state:%d", zdatachannel_is_connected(), plod_state_is_connected(), plod_state_has_disconnected_ms(), ds_cur_state_haspassed_ms()); - } else if (ds_now_state() == kdevice_state_keep_still) { - /******************************************************************************* - * 保持静止页面 * - *******************************************************************************/ + } + + /******************************************************************************* + * 保持静止页面 * + *******************************************************************************/ + else if (ds_now_state() == kdevice_state_keep_still) { if (!plod_state_is_connected()) { // 如果用户未保持静止,切换到首页 state_machine__change_to_home_state(); @@ -256,9 +270,9 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { /******************************************************************************* * 页面加载中 * *******************************************************************************/ - if (ds_cur_state_haspassed_ms() >= (2000 * 5)) { + if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 5)) { /** - * @brief 保持静止2500ms后,切换到采集页面 + * @brief * * 1. 启动采样定时器 * 2. 切换状态 @@ -279,57 +293,45 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { sampledata_file_name.min = tm.tm_min; sampledata_file_name.sec = tm.tm_sec; m_cur_fd = sample_data_mgr_open(&sampledata_file_name, kwrflag_write_only); + BoardBeepCtrl_setEffect(kBoardBeepEffect_oneShortBeep); - } else if (ds_cur_state_haspassed_ms() >= (2000 * 4)) { + } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 4)) { if (dsp_mgr_preparePage_get_progress() != 4) { dsp_mgr_preparePage_set_progress(4); } - } else if (ds_cur_state_haspassed_ms() >= (2000 * 3)) { + } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 3)) { if (dsp_mgr_preparePage_get_progress() != 3) { dsp_mgr_preparePage_set_progress(3); } - } else if (ds_cur_state_haspassed_ms() >= (2000 * 2)) { + } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 2)) { if (dsp_mgr_preparePage_get_progress() != 2) { dsp_mgr_preparePage_set_progress(2); } - } else if (ds_cur_state_haspassed_ms() >= (2000 * 1)) { + } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 1)) { if (dsp_mgr_preparePage_get_progress() != 1) { dsp_mgr_preparePage_set_progress(1); } } } - } else if (ds_now_state() == kdevice_state_sampling) { - /******************************************************************************* - * 采样页面逻辑 * - *******************************************************************************/ + } - /** - * @brief - * 数据事件 - * ---> 存储 - * 不足30秒 - * ---> 切换到采样出错状态 - * 超过30秒且采集完成 或 采满存储空间 - * ---> 切换到存储中 - */ + /******************************************************************************* + * 采样页面逻辑 * + *******************************************************************************/ - bool always_capture = false; + else if (ds_now_state() == kdevice_state_sampling) { + /******************************************************************************* + * 采样数据存储 * + *******************************************************************************/ if (p_event->eventType == kevent_capture_256data_event) { if (hwss_has_captured_time_ms() <= (MAX_STORAGE_TIMEOUT_S * 1000)) { - // ZLOGI("storage data 256 [%d]ms", hwss_has_captured_time_ms()); sample_data_mgr_write(m_cur_fd, p_event->val.capture_data_cache, 256); - } else { - // 采满存储 - /******************************************************************************* - * 存满切换到采集完成页面 * - *******************************************************************************/ - if (!always_capture) { - sample_data_mgr_close(m_cur_fd); - ds_change_to_state(kdevice_state_sampling_complete); - hwss_stop_capture(); - } } - } else if (p_event->eventType == kevent_capture_little_data_block_event) { + } + /******************************************************************************* + * 实时采样数据上报 * + *******************************************************************************/ + if (p_event->eventType == kevent_capture_little_data_block_event) { // 单帧实时上报 ZASSERT(LITTLE_DATA_BLOCK_FRAME_NUM == 5); ble_cmder_try_report_one_sample_data(p_event->val.little_data_block.frameIndex, // @@ -338,60 +340,69 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { p_event->val.little_data_block.data[2].data, // p_event->val.little_data_block.data[3].data, // p_event->val.little_data_block.data[4].data); - // ble_cmder_try_report_one_sample_data(p_event->val.little_data_block.frameIndex, // - // 12345, // - // 12346, // - // 12347, // - // 12348, // - // 12349 // - // ); - } else if (p_event->eventType == kplod_disconnected_event || !m_plod_state_connected_state) { - /******************************************************************************* - * 导联断开 * - *******************************************************************************/ + } - if (hwss_has_captured_time_ms() < (SAMPLE_MIN_TIME_S * 1000)) { - // 采集不足30秒 - ble_cmder_try_report_sensor_drop_event(0x01, 0); - /******************************************************************************* - * 切换到采集出错页面 * - *******************************************************************************/ - if (!always_capture) { - sample_data_mgr_close(m_cur_fd); - sample_data_mgr_delete_file(&sampledata_file_name); - dsp_mgr_change_to_samplingError(); - ds_change_to_state(kdevice_state_sampling_error); - hwss_stop_capture(); - } + /******************************************************************************* + * 采样足30秒事件捕获 * + *******************************************************************************/ + if (hwss_has_captured_time_ms() >= (SAMPLE_MIN_TIME_S * 1000)) { + if (!sample_capture_state_get()->is_over30s) { + BoardBeepCtrl_setEffect(kBoardBeepEffect_oneShortBeep); + sample_capture_state_set_is_over30s(true); + } + } + + /******************************************************************************* + * 采样结束判定 * + *******************************************************************************/ + bool capture_end = false; + if (hwss_has_captured_time_ms() >= (MAX_STORAGE_TIMEOUT_S * 1000)) { + capture_end = true; + } else if (p_event->eventType == kplod_disconnected_event) { + ble_cmder_try_report_sensor_drop_event(0x01, 0); + capture_end = true; + } + + if (capture_end) { + if (sample_capture_state_get()->is_over30s) { + sample_data_mgr_close(m_cur_fd); + dsp_mgr_change_to_sampleSuc(); + BoardBeepCtrl_setEffect(kBoardBeepEffect_oneShortBeep); + ds_change_to_state(kdevice_state_sampling_complete); + hwss_stop_capture(); } else { - // 采集超过30秒 - /******************************************************************************* - * 切换到采集完成页面 * - *******************************************************************************/ - if (!always_capture) { - SingleLeadECG_beep_trigger_once(); - sample_data_mgr_close(m_cur_fd); - dsp_mgr_change_to_sampleSuc(); - ds_change_to_state(kdevice_state_sampling_complete); - hwss_stop_capture(); - } - } - } else { - if (hwss_has_captured_time_ms() >= (SAMPLE_MIN_TIME_S * 1000)) { - if (!sample_capture_state_get()->is_over30s) { - SingleLeadECG_beep_trigger_once(); - sample_capture_state_set_is_over30s(true); - } + // 采样不足三十秒 + + // 停止采样 + hwss_stop_capture(); + // 关闭文件 + sample_data_mgr_close(m_cur_fd); + // 删除文件 + sample_data_mgr_delete_file(&sampledata_file_name); + // 切换到采集出错页面 + dsp_mgr_change_to_samplingError(); + BoardBeepCtrl_setEffect(kBoardBeepEffect_threeShortBeep); + ds_change_to_state(kdevice_state_sampling_error); } } - } else if (ds_now_state() == kdevice_state_sampling_complete) { + + } + + /******************************************************************************* + * 采样完成页面 * + *******************************************************************************/ + else if (ds_now_state() == kdevice_state_sampling_complete) { if (ds_cur_state_haspassed_ms() >= 3000) { ZLOGI("ds_cur_state_haspassed_ms() %d> 3000", ds_cur_state_haspassed_ms()); state_machine__change_to_home_state(); ble_cmder_report_sample_finish_event(); } - } else if (ds_now_state() == kdevice_state_sampling_error) { + } + /******************************************************************************* + * 采样错误页面 * + *******************************************************************************/ + else if (ds_now_state() == kdevice_state_sampling_error) { if ((ds_cur_state_haspassed_ms() >= 3000) || (ds_cur_state_haspassed_ms() >= 1000 && m_plod_state_connected_state)) { ZLOGI("ds_cur_state_haspassed_ms() %d> 3000", ds_cur_state_haspassed_ms()); state_machine__change_to_home_state(); @@ -404,7 +415,7 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { *******************************************************************************/ void one_conduction_main() { - + BoardBeepCtrl_init(); SingleLeadECG_ecg_io_init(); SingleLeadECG_battery_charge_detect_io_init(); AppEvent_regListener(app_event_listener); diff --git a/scripter/build_app.bat b/scripter/build_app.bat index 642f3ac..6426ed6 100644 --- a/scripter/build_app.bat +++ b/scripter/build_app.bat @@ -3,6 +3,12 @@ @REM 编译app call scripter\keil_build.bat app\app.uvprojx app\_build\app.hex + +del output\app_whole.hex +del output\app.zip +del output\one_lead_ecg.zip +del output\one_lead_ecg.hexb + @REM 检查是否编译成功 if not exist app\_build\app.hex ( echo 编译app失败 @@ -43,8 +49,6 @@ if %errorlevel% neq 0 ( exit /b 1 ) -copy /y output\app.zip output\one_lead_ecg.zip -copy /y output\app_whole.hex output\one_lead_ecg.hex @REM 打包整体镜像 @@ -54,6 +58,10 @@ del output\bl_temp.hex del output\settings.hex del output\app.hex + +copy /y output\app.zip output\one_lead_ecg.zip +copy /y output\app_whole.hex output\one_lead_ecg.hex + echo "Start flashing..." call scripter\unlock.bat