|
|
@ -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 |