|
|
@ -101,6 +101,11 @@ static void app_event_process_cb(void* p_event_data, uint16_t event_size); |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
// 导联连接状态事件生成器 |
|
|
|
static uint32_t m_plod_state_disconnect_timepoint = 0; |
|
|
|
static uint32_t m_plod_state_connect_timepoint = 0; |
|
|
|
static bool m_plod_state_connected_state = false; |
|
|
|
static uint32_t plod_state_has_disconnected_ms() { return znordic_haspassed_ms(m_plod_state_disconnect_timepoint); } |
|
|
|
static bool plod_state_is_connected() {} |
|
|
|
static void m_plod_state_event_detect_tmr_cb(void* p_context) { // |
|
|
|
static uint32_t connecte_state_trigger_cnt = 0; |
|
|
|
static uint32_t connecte_state_trigger_cnt_last_val = 0; |
|
|
@ -108,7 +113,7 @@ static void m_plod_state_event_detect_tmr_cb(void* p_context) { // |
|
|
|
memset(&appevent, 0, sizeof(appevent)); |
|
|
|
|
|
|
|
connecte_state_trigger_cnt_last_val = connecte_state_trigger_cnt; |
|
|
|
if (!SingleLeadECG_ecg_plod_get_connected_state()) { |
|
|
|
if (SingleLeadECG_ecg_plod_get_connected_state()) { |
|
|
|
connecte_state_trigger_cnt++; |
|
|
|
} else { |
|
|
|
connecte_state_trigger_cnt = 0; |
|
|
@ -117,10 +122,14 @@ static void m_plod_state_event_detect_tmr_cb(void* p_context) { // |
|
|
|
if (connecte_state_trigger_cnt == 5) { |
|
|
|
// 连接事件 |
|
|
|
appevent.eventType = kplod_connected_event; |
|
|
|
m_plod_state_connect_timepoint = znordic_getpower_on_ms(); |
|
|
|
m_plod_state_connected_state = true; |
|
|
|
app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); |
|
|
|
} else if (connecte_state_trigger_cnt_last_val >= 5 && connecte_state_trigger_cnt == 0) { |
|
|
|
// 断开事件 |
|
|
|
appevent.eventType = kplod_disconnected_event; |
|
|
|
m_plod_state_connected_state = false; |
|
|
|
m_plod_state_disconnect_timepoint = znordic_getpower_on_ms(); |
|
|
|
app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); |
|
|
|
} else if (connecte_state_trigger_cnt >= 10 && connecte_state_trigger_cnt % 10 == 0) { |
|
|
|
// 连接持续事件 |
|
|
@ -162,9 +171,11 @@ static void state_machine_driver_tmr_cb(void* p_context) { // |
|
|
|
static void state_machine_change_to_state(device_state_t state) { |
|
|
|
ZLOGI("change state from %s to %s", device_state_to_str(m_device_state), device_state_to_str(state)); |
|
|
|
m_device_state = state; |
|
|
|
m_change_to_cur_state_tp = znordic_getpower_on_s(); |
|
|
|
m_change_to_cur_state_tp = znordic_getpower_on_ms(); |
|
|
|
} |
|
|
|
|
|
|
|
static uint32_t cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); } |
|
|
|
static bool m_poweronflag; |
|
|
|
static void power_on() { |
|
|
|
SingleLeadECG_adc_module_init(); |
|
|
|
SingleLeadECG_beep_init(); |
|
|
@ -174,7 +185,7 @@ static void power_on() { |
|
|
|
|
|
|
|
sample_data_mgr_init(); |
|
|
|
dsp_mgr_init(); |
|
|
|
|
|
|
|
m_poweronflag = true; |
|
|
|
ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(5), NULL)); // 200HZ采样 |
|
|
|
} |
|
|
|
static void power_off() { |
|
|
@ -186,9 +197,11 @@ static void power_off() { |
|
|
|
SingleLeadECG_led_deinit(); |
|
|
|
SingleLeadECG_beep_deinit(); |
|
|
|
SingleLeadECG_adc_module_deinit(); |
|
|
|
|
|
|
|
ZERROR_CHECK(app_timer_stop(m_state_machine_driver_tmr)); |
|
|
|
} |
|
|
|
/******************************************************************************* |
|
|
|
* 状态切换方法 * |
|
|
|
*******************************************************************************/ |
|
|
|
/** |
|
|
|
* @brief 切换到充电中状态 |
|
|
|
*/ |
|
|
@ -205,6 +218,33 @@ static void state_machine__change_to_charging_state() { // |
|
|
|
state_machine_change_to_state(kdevice_state_charging); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 切换到待机状态 |
|
|
|
*/ |
|
|
|
|
|
|
|
static void state_machine__change_to_standby_state() { |
|
|
|
ZLOGI_BLOCK("change to standby"); |
|
|
|
power_off(); |
|
|
|
state_machine_change_to_state(kdevice_state_standby); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 切换到开机中画面 |
|
|
|
*/ |
|
|
|
static void state_machine__change_to_poweroning_state() { |
|
|
|
power_on(); |
|
|
|
dsp_mgr_change_to_welcome(); |
|
|
|
state_machine_change_to_state(kdevice_state_poweron); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 切换到首页 |
|
|
|
*/ |
|
|
|
static void state_machine__change_to_home_state() { |
|
|
|
state_machine_change_to_state(kdevice_state_home); |
|
|
|
dsp_mgr_change_to_main(); |
|
|
|
} |
|
|
|
|
|
|
|
static void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
if (!p_event_data) return; |
|
|
|
app_event_t* p_event = (app_event_t*)p_event_data; |
|
|
@ -217,13 +257,32 @@ static void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
// 切换到充电状态 |
|
|
|
state_machine__change_to_charging_state(); |
|
|
|
} |
|
|
|
|
|
|
|
if (p_event->eventType == kplod_connected_event) { |
|
|
|
// 切换到开机状态 |
|
|
|
state_machine__change_to_poweroning_state(); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (m_device_state == kdevice_state_charging) { |
|
|
|
/******************************************************************************* |
|
|
|
* 充电状态 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (!SingleLeadECG_battery_charge_get_state()) { |
|
|
|
power_off(); |
|
|
|
state_machine_change_to_state(kdevice_state_standby); |
|
|
|
state_machine__change_to_standby_state(); |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_poweron) { |
|
|
|
/******************************************************************************* |
|
|
|
* 开机中 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (cur_state_haspassed_ms() >= 1500) { |
|
|
|
state_machine__change_to_home_state(); |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_home) { |
|
|
|
/******************************************************************************* |
|
|
|
* 首页 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (!m_plod_state_connected_state && plod_state_has_disconnected_ms() >= 3000) { |
|
|
|
state_machine__change_to_standby_state(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -289,6 +348,7 @@ void one_conduction_main() { |
|
|
|
}; |
|
|
|
zble_module_init(&cfg); |
|
|
|
|
|
|
|
#if 1 |
|
|
|
SingleLeadECG_ecg_io_init(); |
|
|
|
SingleLeadECG_battery_charge_detect_io_init(); |
|
|
|
ZERROR_CHECK(app_timer_create(&m_state_machine_driver_tmr, APP_TIMER_MODE_REPEATED, state_machine_driver_tmr_cb)); |
|
|
@ -297,7 +357,16 @@ void one_conduction_main() { |
|
|
|
|
|
|
|
ZERROR_CHECK(app_timer_start(m_plod_state_event_detect_tmr, APP_TIMER_TICKS(100), NULL)); |
|
|
|
ZERROR_CHECK(app_timer_start(m_charge_event_detect_tmr, APP_TIMER_TICKS(100), NULL)); |
|
|
|
znordic_loop(); |
|
|
|
#endif |
|
|
|
// ZERROR_CHECK(); |
|
|
|
while (true) { |
|
|
|
app_sched_execute(); |
|
|
|
if (NRF_LOG_PROCESS() == false) { |
|
|
|
nrf_pwr_mgmt_run(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// znordic_loop(); |
|
|
|
} |
|
|
|
|
|
|
|
// ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(5), NULL)); |
|
|
|