From 801a8b709ec3acbb2caeabf518be5f45c6c62019 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 28 Jan 2024 17:55:19 +0800 Subject: [PATCH] add charge event --- app/src/one_conduction/one_conduction_board.c | 7 ++++++ app/src/one_conduction/one_conduction_board.h | 8 +++++-- app/src/one_conduction/one_conduction_main.c | 33 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/src/one_conduction/one_conduction_board.c b/app/src/one_conduction/one_conduction_board.c index d3e9e88..7416c42 100644 --- a/app/src/one_conduction/one_conduction_board.c +++ b/app/src/one_conduction/one_conduction_board.c @@ -44,6 +44,8 @@ #define BEEP_PWM_INSTANCE 0 #define BEEP_PIN 1 +#define BATTERY_CHARGE_DETECT_PIN 18 + /******************************************************************************* * TOOLS * *******************************************************************************/ @@ -211,6 +213,11 @@ int16_t SingleLeadECG_battery_get_adc_val() { return val; } +void SingleLeadECG_battery_charge_detect_io_init() { // + nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE); +} +bool SingleLeadECG_battery_charge_get_state() { return nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN) == 0; } + /******************************************************************************* * eeprom * *******************************************************************************/ diff --git a/app/src/one_conduction/one_conduction_board.h b/app/src/one_conduction/one_conduction_board.h index afd2178..23fed79 100644 --- a/app/src/one_conduction/one_conduction_board.h +++ b/app/src/one_conduction/one_conduction_board.h @@ -54,9 +54,9 @@ void SingleLeadECG_led_blue_set_state(bool state); * ECG * *******************************************************************************/ -void SingleLeadECG_ecg_init(); +void SingleLeadECG_ecg_init(); -void SingleLeadECG_ecg_io_init(); +void SingleLeadECG_ecg_io_init(); uint32_t SingleLeadECG_ecg_nlod_get_connected_state(); uint32_t SingleLeadECG_ecg_plod_get_connected_state(); @@ -67,3 +67,7 @@ int16_t SingleLeadECG_ecg_plod_get_ecg_val(); *******************************************************************************/ void SingleLeadECG_battery_init(); int16_t SingleLeadECG_battery_get_adc_val(); + +void SingleLeadECG_battery_charge_detect_io_init(); +bool SingleLeadECG_battery_charge_get_state(); + diff --git a/app/src/one_conduction/one_conduction_main.c b/app/src/one_conduction/one_conduction_main.c index 6c1d66c..65d7a81 100644 --- a/app/src/one_conduction/one_conduction_main.c +++ b/app/src/one_conduction/one_conduction_main.c @@ -14,6 +14,7 @@ ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); // 蓝牙服务 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); // 充电事件检测 extern uint32_t g_nrf_log_tx_pin; #define SCHED_MAX_EVENT_DATA_SIZE APP_TIMER_SCHED_EVENT_DATA_SIZE /**< Maximum size of scheduler events. */ @@ -21,6 +22,10 @@ typedef enum { kplod_connected_event = 0, // 导联连接事件 kplod_disconnected_event, // 导联断开事件 kplod_connecting_event, // 导联连接中事件 + + kplod_start_charge_event, // 充电事件 + kplod_end_charge_event, // 充电结束事件 + } app_event_type_t; typedef struct { @@ -71,6 +76,25 @@ static void m_plod_state_event_detect_tmr_cb(void* p_context) { // } } +static void m_charge_event_detect_tmr_cb(void* p_context) { // + static app_event_t appevent; + memset(&appevent, 0, sizeof(appevent)); + static bool ischarging = false; + if (!SingleLeadECG_battery_charge_get_state()) { + if (!ischarging) { + appevent.eventType = kplod_start_charge_event; + ischarging = true; + app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); + } + } else { + if (ischarging) { + ischarging = false; + appevent.eventType = kplod_end_charge_event; + app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); + } + } +} + /******************************************************************************* * 事件处理 * *******************************************************************************/ @@ -86,6 +110,12 @@ static void app_event_process_cb(void* p_event_data, uint16_t event_size) { } else if (p_event->eventType == kplod_connecting_event) { ZLOGI("plod connecting %d", p_event->val.plod_connected_accumulation_time); } + + if (p_event->eventType == kplod_start_charge_event) { + ZLOGI("start charge"); + } else if (p_event->eventType == kplod_end_charge_event) { + ZLOGI("end charge"); + } } /** @@ -134,10 +164,13 @@ void one_conduction_main() { zble_module_init(&cfg); 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)); ZERROR_CHECK(app_timer_create(&m_plod_state_event_detect_tmr, APP_TIMER_MODE_REPEATED, m_plod_state_event_detect_tmr_cb)); + ZERROR_CHECK(app_timer_create(&m_charge_event_detect_tmr, APP_TIMER_MODE_REPEATED, m_charge_event_detect_tmr_cb)); 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(); }