diff --git a/.vscode/settings.json b/.vscode/settings.json index d13aefa..d614fa7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -93,7 +93,8 @@ "heart_wave_sample_service.h": "c", "device_info_mgr.h": "c", "znordic_device_info_mgr.h": "c", - "device_state.h": "c" + "device_state.h": "c", + "app_event.h": "c" }, "files.encoding": "gbk" } \ No newline at end of file diff --git a/app/app.uvprojx b/app/app.uvprojx index dbb6b38..21f9601 100644 --- a/app/app.uvprojx +++ b/app/app.uvprojx @@ -313,7 +313,7 @@ 1 - 4 + 1 0 0 1 diff --git a/app/config/sdk_config.h b/app/config/sdk_config.h index 3cbeadf..578bc9e 100644 --- a/app/config/sdk_config.h +++ b/app/config/sdk_config.h @@ -11963,7 +11963,7 @@ // <2=> NRF_SDH_DISPATCH_MODEL_POLLING #ifndef NRF_SDH_DISPATCH_MODEL -#define NRF_SDH_DISPATCH_MODEL 1 +#define NRF_SDH_DISPATCH_MODEL 0 #endif // diff --git a/app/main.c b/app/main.c index dafb9a3..fa049a6 100644 --- a/app/main.c +++ b/app/main.c @@ -20,9 +20,124 @@ #include "nrf_uarte.h" #endif -#if 1 +#if 0 int main() { one_conduction_main(); return 0; } +#else +#include "nrfx_timer.h" + +ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); // 蓝牙服务 +static const nrfx_timer_t m_timer = NRFX_TIMER_INSTANCE(1); /**< Timer used for channel sweeps and tx with duty cycle. */ + +static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) { + /** + * @brief + */ + if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) { + } +} + +static void on_service_init(void) { + ZLOGI("init zdatachannel service"); + zdatachannel_init_t zdatachannle_init; + memset(&zdatachannle_init, 0, sizeof(zdatachannle_init)); + zdatachannle_init.data_handler = zdatachannel_data_handler; + ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init)); +} + +uint16_t adc_val_cache[5] = {0}; +int adc_val_index = 0; + +void sendpacket_to_pc() { + uint8_t data[255]; + // adc_val_cache[0] = 1; + // adc_val_cache[1] = 2; + // adc_val_cache[2] = 3; + // adc_val_cache[3] = 4; + // adc_val_cache[4] = 5; + + for (int i = 0; i < adc_val_index; i++) { + data[i * 6 + 0] = 0xA2; + data[i * 6 + 1] = 0x2; + data[i * 6 + 2] = adc_val_cache[i] & 0xff; + data[i * 6 + 3] = adc_val_cache[i] >> 8 & 0xff; + data[i * 6 + 4] = 0x2; + data[i * 6 + 5] = 0xA2; + } + zdatachannel_data_send2(data, 6 * adc_val_index); +} + +static void nrfx_timer_event_handler(nrf_timer_event_t event_type, void* p_context) { // + uint16_t val = SingleLeadECG_ecg_plod_get_ecg_val(); // 12bit + /******************************************************************************* + * 显示数据计算并赋值 * + *******************************************************************************/ + adc_val_cache[adc_val_index] = val; + adc_val_index++; + if (adc_val_index >= 5) { + if (zdatachannel_is_connected()) { + sendpacket_to_pc(); + } else { + } + adc_val_index = 0; + } + + static int cnt; + static bool state; + cnt++; + if (zdatachannel_is_connected()) { + SingleLeadECG_led_green_set_state(1); + } else { + if (cnt % 500 == 0) { + SingleLeadECG_led_green_set_state(state); + state = !state; + } + } +} +int main() { // + APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20); + + znordic_init(); + NRF_LOG_INFO("compile time :%s", __TIME__); + + ztm_t tm; + static zble_module_cfg_t cfg = // + { + .deviceName = "OneLeadTest", + .on_service_init = on_service_init, + }; + zble_module_init(&cfg); + SingleLeadECG_adc_module_init(); + SingleLeadECG_led_init(); + SingleLeadECG_led_green_set_state(0); + + zble_module_start_adv(); + + /******************************************************************************* + * 定时器初始化 * + *******************************************************************************/ + /** + * @brief 初始化定时器 + */ + nrfx_err_t err; + nrfx_timer_config_t timer_cfg = { + .frequency = NRF_TIMER_FREQ_500kHz, + .mode = NRF_TIMER_MODE_TIMER, + .bit_width = NRF_TIMER_BIT_WIDTH_24, + .p_context = NULL, + .interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, + }; + + err = nrfx_timer_init(&m_timer, &timer_cfg, nrfx_timer_event_handler); + if (err != NRFX_SUCCESS) { + NRF_LOG_ERROR("nrfx_timer_init failed with: %d\n", err); + } + uint32_t timer_ticks = nrfx_timer_ms_to_ticks(&m_timer, 5); // 500HZ + nrfx_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, timer_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); + nrfx_timer_enable(&m_timer); + znordic_loop(); +} + #endif \ No newline at end of file diff --git a/app/src/board/board.h b/app/src/board/board.h index 9041700..a3507a3 100644 --- a/app/src/board/board.h +++ b/app/src/board/board.h @@ -21,6 +21,6 @@ #define AUTOMATIC_SLEEP_TIME 15000 #define SAMPLE_MIN_TIME_S (30.0) -#define ENABLE_SLEEP +// #define ENABLE_SLEEP #define LITTLE_DATA_BLOCK_FRAME_NUM 5 // 每次多少帧上报一次