Browse Source

add charge event

3lead_uart_test_ok_version
zhaohe 1 year ago
parent
commit
801a8b709e
  1. 7
      app/src/one_conduction/one_conduction_board.c
  2. 8
      app/src/one_conduction/one_conduction_board.h
  3. 33
      app/src/one_conduction/one_conduction_main.c

7
app/src/one_conduction/one_conduction_board.c

@ -44,6 +44,8 @@
#define BEEP_PWM_INSTANCE 0 #define BEEP_PWM_INSTANCE 0
#define BEEP_PIN 1 #define BEEP_PIN 1
#define BATTERY_CHARGE_DETECT_PIN 18
/******************************************************************************* /*******************************************************************************
* TOOLS * * TOOLS *
*******************************************************************************/ *******************************************************************************/
@ -211,6 +213,11 @@ int16_t SingleLeadECG_battery_get_adc_val() {
return 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 * * eeprom *
*******************************************************************************/ *******************************************************************************/

8
app/src/one_conduction/one_conduction_board.h

@ -54,9 +54,9 @@ void SingleLeadECG_led_blue_set_state(bool state);
* ECG * * 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_nlod_get_connected_state();
uint32_t SingleLeadECG_ecg_plod_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(); void SingleLeadECG_battery_init();
int16_t SingleLeadECG_battery_get_adc_val(); int16_t SingleLeadECG_battery_get_adc_val();
void SingleLeadECG_battery_charge_detect_io_init();
bool SingleLeadECG_battery_charge_get_state();

33
app/src/one_conduction/one_conduction_main.c

@ -14,6 +14,7 @@
ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); // ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); //
APP_TIMER_DEF(m_state_machine_driver_tmr); // APP_TIMER_DEF(m_state_machine_driver_tmr); //
APP_TIMER_DEF(m_plod_state_event_detect_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; 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. */ #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_connected_event = 0, //
kplod_disconnected_event, // kplod_disconnected_event, //
kplod_connecting_event, // kplod_connecting_event, //
kplod_start_charge_event, //
kplod_end_charge_event, //
} app_event_type_t; } app_event_type_t;
typedef struct { 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) { } else if (p_event->eventType == kplod_connecting_event) {
ZLOGI("plod connecting %d", p_event->val.plod_connected_accumulation_time); 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); zble_module_init(&cfg);
SingleLeadECG_ecg_io_init(); 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_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_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_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(); znordic_loop();
} }

Loading…
Cancel
Save