diff --git a/app/config/sdk_config.h b/app/config/sdk_config.h index a29e30b..1a2e89b 100644 --- a/app/config/sdk_config.h +++ b/app/config/sdk_config.h @@ -5,7 +5,7 @@ #define NRF_LOG_BACKEND_UART_TX_PIN 41 // #define NRF_LOG_BACKEND_UART_TX_PIN 6 -#define APP_TIMER_CONFIG_USE_SCHEDULER 1 +#define APP_TIMER_CONFIG_USE_SCHEDULER 0 // #define NRF_LOG_BACKEND_UART_BAUDRATE 121634816 // 400800 baud #define NRF_LOG_BACKEND_UART_BAUDRATE 268435456 // 1000000 baud diff --git a/app/src/app_basic_service/basic/event.h b/app/src/app_basic_service/basic/event.h index 7fb3907..6b5e221 100644 --- a/app/src/app_basic_service/basic/event.h +++ b/app/src/app_basic_service/basic/event.h @@ -13,6 +13,10 @@ typedef enum { kecg_data_report_event, // ecg数据上报事件 kappevent_battery_start_charge, // 开始充电事件 kappevent_battery_end_charge, // 停止充电事件 + + kappevent_start_capture, + kappevent_stop_capture, + } app_event_type_t; typedef struct { diff --git a/app/src/app_service/battery_mgr_service.c b/app/src/app_service/battery_mgr_service.c index 85be297..948aca8 100644 --- a/app/src/app_service/battery_mgr_service.c +++ b/app/src/app_service/battery_mgr_service.c @@ -96,7 +96,9 @@ void battery_mgr_service_init() { /** * @brief 500ms启动定时器500ms检查一次当前是否正在充电 */ - nrf_gpio_cfg_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP); + // nrf_gpio_cfg_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP); + nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE); + app_timer_create(&battery_state_detect_tmr, APP_TIMER_MODE_REPEATED, module_tmr_cb); m_state = kstandy; } diff --git a/app/src/app_service/beep_ctrl.h b/app/src/app_service/beep_ctrl.h index f9890f8..f62416b 100644 --- a/app/src/app_service/beep_ctrl.h +++ b/app/src/app_service/beep_ctrl.h @@ -6,15 +6,21 @@ #include "aproject_config/config.h" #include "znordic.h" + +#define START_SAMPLE_EFFECT kBoardBeepEffect_oneShortLongBeep +#define STOP_SAMPLE_EFFECT kBoardBeepEffect_oneShortLongBeep +#define POWER_ON_EFFECT kBoardBeepEffect_oneShortBeep +#define LEAD_OFF_EFFECT kBoardBeepEffect_continuousShortBeep + typedef enum { kBoardBeepEffect_none = 0, // 响一声 kBoardBeepEffect_oneShortBeep, - // 响一声长鸣 + // 响一声长鸣,开始采集 kBoardBeepEffect_oneShortLongBeep, - // 响三声 + // 响三声,采样异常 kBoardBeepEffect_threeShortBeep, - // 持续短鸣报警 + // 持续短鸣报警,导联脱落 kBoardBeepEffect_continuousShortBeep, } board_beep_effect_t; diff --git a/app/src/app_service/display_ctrl_service/ssd1306_if_impl.c b/app/src/app_service/display_ctrl_service/ssd1306_if_impl.c index d3bf60a..f7ac19d 100644 --- a/app/src/app_service/display_ctrl_service/ssd1306_if_impl.c +++ b/app/src/app_service/display_ctrl_service/ssd1306_if_impl.c @@ -35,7 +35,7 @@ void ssd1306_if_load() { znrf_gpio_cfg_output(SCREEN_A0PIN, NRF_GPIO_PIN_NOPULL); nrf_gpio_pin_clear(SCREEN_RESET_PIN); - nrf_gpio_pin_clear(SCREEN_POWER_PIN); + nrf_gpio_pin_set(SCREEN_POWER_PIN); nrf_gpio_pin_clear(SCREEN_A0PIN); // 参考 // OLED驱动程序 : https://iflytop1.feishu.cn/wiki/OQ4Iwv0DpiQDJvkjftjcQHJBnCg diff --git a/app/src/one_conduction_main.c b/app/src/one_conduction_main.c index 934e364..3a3d7a3 100644 --- a/app/src/one_conduction_main.c +++ b/app/src/one_conduction_main.c @@ -14,6 +14,7 @@ #include "app_service/display_ctrl_service/display_mgr.h" #include "app_service/ecg_service/ecg_service.h" #include "app_service/light_ctrl.h" +#include "zble_module.h" /*********************************************************************************************************************** * GLOBAL * @@ -21,6 +22,7 @@ static uint8_t bletxbuf[255]; static uint8_t blereportbuf[255]; +static bool m_poweron_flag; /******************************************************************************* * UTILS * @@ -48,9 +50,35 @@ static void send_success_receipt(ify_hrs_packet_t* rxpacket, int32_t emptydatasi zdatachannel_data_send2(bletxbuf, sendlen); } -/******************************************************************************* - * 下发消息处理 * - *******************************************************************************/ +/*********************************************************************************************************************** + * 蓝牙连接事件处理 * + ***********************************************************************************************************************/ + +static void process_on_connect(void* arg) { + if (zapp_state_machine_now_state() == kstate_standby) { + zapp_state_machine_change_state(kstate_welcomPage); + } + + if (m_poweron_flag) { + light_ctrl_set_green_light_effect(kLightEffect_slowFlash); + } +} +static void process_on_disconnect(void* arg) { + if (m_poweron_flag) { + light_ctrl_set_green_light_effect(kLightEffect_quickFlash); + } +} + +void on_zble_event(zble_event_t* event) { + if (event->eventType == kzble_event_connected) { + zapp_exec_in_main_context(NULL, process_on_connect, NULL); + } else if (event->eventType == kzble_event_disconnected) { + zapp_exec_in_main_context(NULL, process_on_disconnect, NULL); + } +} +/*********************************************************************************************************************** + * 蓝牙消息处理 * + ***********************************************************************************************************************/ void one_conduction_process_rx_packet(uint8_t* rx, int len) { /** * @brief @@ -155,14 +183,39 @@ void one_conduction_process_rx_packet(uint8_t* rx, int len) { zdatachannel_data_send2(bletxbuf, sendlen); } - /*********************************************************************************************************************** - * 测试指令 * - ***********************************************************************************************************************/ + else if (cmd == ify_hrs_cmd_start_realtime_preview) { + if (zapp_state_machine_now_state() != kstate_mainPage) { + send_error_receipt(rxheader, kifyhrs_ecode_device_busy); + return; + } + static app_event_t event; + event.eventType = kappevent_start_capture; + + zapp_ebus_push_event(&event); + send_success_receipt(rxheader, 0); + } + + else if (cmd == ify_hrs_cmd_stop_realtime_preview) { + if (zapp_state_machine_now_state() != kstate_mainPage) { + send_error_receipt(rxheader, kifyhrs_ecode_device_busy); + return; + } + + static app_event_t event; + event.eventType = kappevent_stop_capture; + + zapp_ebus_push_event(&event); + send_success_receipt(rxheader, 0); + } + else { send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); } } +/*********************************************************************************************************************** + * 状态切换 * + ***********************************************************************************************************************/ void on_state_change(device_state_t from, device_state_t to) { /** * @brief 开机 @@ -177,6 +230,11 @@ void on_state_change(device_state_t from, device_state_t to) { dsp_mgr_load(); // dsp_mgr_change_page(kpage_welcome); ecg_service_load(); + m_poweron_flag = true; + + if (zble_module_is_connected()) { + light_ctrl_set_green_light_effect(kLightEffect_slowFlash); + } } /** @@ -194,18 +252,87 @@ void on_state_change(device_state_t from, device_state_t to) { // battery_mgr_service_change_state_to_standy(); hardware_power_mgr_main_power_supply_set(false); + m_poweron_flag = false; } - if (to == kstate_welcomPage) { - // dsp_mgr_change_page(kpage_welcome); - zapp_state_machine_change_state(kstate_standby); + if (to == kstate_standby) { + dsp_mgr_change_page(kpage_poweroff); + } else if (to == kstate_welcomPage) { + dsp_mgr_change_page(kpage_welcome); + } else if (to == kstate_mainPage) { + dsp_mgr_change_page(kpage_main); + } else if (to == kstate_capture) { + dsp_mgr_change_page(kpage_sampling); + } else if (to == kstate_charging) { + dsp_mgr_change_page(kpage_charging_page); } } -void on_zapp_ebus_event(void* p_event_data, uint16_t event_size) { - - - +/*********************************************************************************************************************** + * 事件处理 * + ***********************************************************************************************************************/ +void on_zapp_ebus_event(void* p_event_data, uint16_t event_size) { + if (!p_event_data) return; + app_event_t* p_event = (app_event_t*)p_event_data; + if (zapp_state_machine_now_state() == kstate_standby) { + /** + * @brief + * 1. 充电切换到充电状态 + * + */ + if (p_event->eventType == kappevent_battery_start_charge) { + zapp_state_machine_change_state(kstate_charging); + } else if (!znordic_rtc_has_setted() && zapp_state_machine_haspassed_ms() >= 60000) { + ZLOGI_BLOCK("rtc not setted, power system off"); + ZERROR_CHECK(sd_power_system_off()); + } + + } else if (zapp_state_machine_now_state() == kstate_welcomPage) { + /** + * @brief + * 延迟1.5s切换到主页面 + */ + if (zapp_state_machine_haspassed_ms() >= 1500) { + zapp_state_machine_change_state(kstate_mainPage); + beep_set_effect(POWER_ON_EFFECT); + } + } else if (zapp_state_machine_now_state() == kstate_mainPage) { + /** + * @brief + * 1. 断开连接->切换到关机状态 + * 2. 开始采集指令->切换到采集状态 + * 3. 充电中事件->切换到充电状态 + * + */ + if (zble_module_has_disconnected_ms() >= 3000) { + zapp_state_machine_change_state(kstate_standby); + } else if (p_event->eventType == kappevent_start_capture) { + zapp_state_machine_change_state(kstate_capture); + } else if (p_event->eventType == kappevent_battery_start_charge) { + zapp_state_machine_change_state(kstate_charging); + } + + } else if (zapp_state_machine_now_state() == kstate_capture) { + /** + * @brief + * 1. 停止采集指令->切换到MainPage + */ + if (p_event->eventType == kappevent_stop_capture) { + zapp_state_machine_change_state(kstate_mainPage); + } + } else if (zapp_state_machine_now_state() == kstate_charging) { + /** + * @brief + * 1. 充电结束事件->切换到待机 + */ + if (p_event->eventType == kappevent_battery_end_charge) { + if (!zble_module_is_connected()) { + zapp_state_machine_change_state(kstate_standby); + } else { + zapp_state_machine_change_state(kstate_mainPage); + } + } + } } void one_conduction_main() { @@ -215,17 +342,20 @@ void one_conduction_main() { ZLOG_FLUSH(); zapp_ebus_reg_event_listener(on_zapp_ebus_event); zapp_state_machine_reg_state_change_listener(on_state_change); + zble_module_reglistener(on_zble_event); adc_mgr_init(); hardware_power_mgr_init(); battery_mgr_service_init(); + battery_mgr_service_load(); + light_ctrl_init(); beep_init(); dsp_mgr_init(); ecg_service_init(); - zapp_state_machine_change_state(kstate_welcomPage); + // zapp_state_machine_change_state(kstate_standby); zble_module_start_adv(); zapp_start_schedule(); diff --git a/libznordic b/libznordic index 1d9ac0b..6fb5f63 160000 --- a/libznordic +++ b/libznordic @@ -1 +1 @@ -Subproject commit 1d9ac0bb2d87ce60cbe742d2ddffa0b91c68acdd +Subproject commit 6fb5f63c43ea9866bef9eacd918ddd00468fa4f6