From 828b44ec21720beef14bf396ae12c13e31415716 Mon Sep 17 00:00:00 2001 From: stark1898y <1658608470@qq.com> Date: Thu, 27 Mar 2025 10:31:31 +0800 Subject: [PATCH] zancun --- APP/peripheral_main.c | 94 ++++++++++++++++++++++++++++++++++++++++--- BSP/src/bsp_key.c | 3 +- 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/APP/peripheral_main.c b/APP/peripheral_main.c index f81baf7..51bf7ed 100644 --- a/APP/peripheral_main.c +++ b/APP/peripheral_main.c @@ -41,6 +41,7 @@ __attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4]; static uint8_t key_press_cnt = 0; +#if 0 void app_task_handler(TeAppEvtType app_evt_type) { BSP_BlockSleep(); @@ -124,6 +125,87 @@ void app_task_handler(TeAppEvtType app_evt_type) } } +#endif + +void app_task_handler(TeAppEvtType app_evt_type) +{ + BSP_BlockSleep(); + // BSP_BlockSleep(); + BSP_RequestBoost(); + + switch(app_evt_type) + { + case kKeyShort: + logDebug("button short press"); + key_press_cnt++; + logDebug("key_press_cnt = %d", key_press_cnt); + if (key_press_cnt == 1) + { + logDebug("LED显示状态"); + // tmos_set_event(led_task_id, LED_SHOW_START_EVT); + BSP_BlockSleep(); + BSP_RequestBoost(); + DelayMs(1); + ShowLed(); + // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); + // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); + } + else if (key_press_cnt == 2) + { + if (gValveData.switch_status == kClosed) + { + logDebug("kClosed-->kOpened"); + // tmos_set_event(led_task_id, LED_SHOW_START_EVT); + gValveData.switch_status = kOpened; + BSP_BlockSleep(); + BSP_RequestBoost(); + DelayMs(1); + ShowLed(); + // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); + // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); + } + else if (gValveData.switch_status != kClosed) + { + logDebug("kOpened-->kClosed"); + gValveData.switch_status = kClosed; + tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); + + // tmos_set_event(led_task_id, LED_SHOW_START_EVT); + BSP_BlockSleep(); + BSP_RequestBoost(); + DelayMs(1); + ShowLed(); + // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); + // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); + } + } + break; + + case kKeyLong: + logDebug("button long press"); + + break; + case kKeyRelease: + // BSP_KEY_EnterLowpower(); + // DelayMs(10); + key_press_cnt = 0; + // BSP_RequestSleep(); + // tmos_set_event(led_task_id, LED_SHOW_END_EVT); + + LED_ALL_OFF_DEINIT; + BEEP_OFF_DEINIT; + + BSP_NoNeedBoost(); + BSP_RequestSleep(); + + logDebug("gpio relase;BSP_RequestSleep"); + + break; + default: + break; + } +} + /********************************************************************* * @fn Main_Circulation * @@ -182,9 +264,9 @@ int main(void) DelayMs(1000 * 3); CH58x_BLEInit(); - HAL_Init(); - GAPRole_PeripheralInit(); - Peripheral_Init(); + // HAL_Init(); + // GAPRole_PeripheralInit(); + // Peripheral_Init(); logDebug("GetSysClock = %d Hz", GetSysClock()); @@ -221,9 +303,9 @@ int main(void) BSP_VAVLE_Init(); - // HAL_Init(); - // GAPRole_PeripheralInit(); - // Peripheral_Init(); + HAL_Init(); + GAPRole_PeripheralInit(); + Peripheral_Init(); BSP_BlockSleep(); BSP_RequestBoost(); diff --git a/BSP/src/bsp_key.c b/BSP/src/bsp_key.c index 7bdbb9c..ac89f59 100644 --- a/BSP/src/bsp_key.c +++ b/BSP/src/bsp_key.c @@ -255,8 +255,9 @@ void BSP_KEY_Init(app_task_evt_handler_t handler) // GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_PU); // GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeIN_Floating); + GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeIN_PU); - GPIOB_ModeCfg(GPIO_Pin_0, GPIO_ModeIN_Floating); + GPIOB_ModeCfg(GPIO_Pin_0, GPIO_ModeIN_PU); // GPIOB_ModeCfg(GPIO_Pin_1, GPIO_ModeIN_Floating); #if 1