From 1f6020a3a965652d298f328ab6897725a526c119 Mon Sep 17 00:00:00 2001 From: stark1898y <1658608470@qq.com> Date: Fri, 30 May 2025 16:36:43 +0800 Subject: [PATCH] =?UTF-8?q?2.2V=E4=BD=8E=E5=8E=8B=E5=85=B3=E9=98=80?= =?UTF-8?q?=EF=BC=8CVAVLE=5FLOOP=5FDECT=5FEVT=E5=92=8CperformPeriodicTask?= =?UTF-8?q?=E9=94=99=E5=BC=80=EF=BC=9F=E5=8D=87=E5=8E=8B=E6=97=B6=E5=80=99?= =?UTF-8?q?=E5=88=AB=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/peripheral.c | 85 ++++++++++++++------------------------ BSP/inc/bsp_beep_led_emv.h | 9 ++-- BSP/inc/bsp_valve.h | 8 ++-- BSP/src/bsp_valve.c | 68 +++++++++++++++++------------- 4 files changed, 81 insertions(+), 89 deletions(-) diff --git a/APP/peripheral.c b/APP/peripheral.c index 0ef3043..4a42b03 100644 --- a/APP/peripheral.c +++ b/APP/peripheral.c @@ -730,66 +730,43 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven */ static void performPeriodicTask(void) { - gValveData.bat = BSP_ReadVbat(); - -#if 0 - BSP_BlockSleep(); - BSP_RequestBoost(); - // DelayMs(1); - ShowLed(); - - DelayMs(2); - LED_ALL_OFF_DEINIT; - // BEEP_OFF_DEINIT; - - BSP_NoNeedBoost(); - BSP_RequestSleep(); -#endif - // // 如果电压低就都不亮灯、蜂鸣器 - // if (bat_mv <= LOW_VABAT_CLOSE_MV) - // { - // logDebug("低压关阀"); - // tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); - // } - // if (gValveData.bat <= LOW_VABAT_CLOSE_VALUE) - // { - // gValveData.switch_status = kClosed; - // tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); - // } - // else if (gValveData.bat <= LOW_VABAT_ALARM_VALUE) - // { - // tmos_set_event(vavle_task_id, VAVLE_LOW_VBAT_ALARM_EVT); - // } - - // TODO:温湿度传感器读错的话就不发了? - float _humi, _temp; - if (BSP_ReadTempHumi(&_humi, &_temp) == 0) + if (boost_en_flag == 0 && GPIOA_ReadITFlagBit(BOOST_APIN) == 0) { - gValveData.temp = (int8_t)_temp; - gValveData.humi = (uint8_t)_humi; - if (gValveData.temp >= HIGN_TEMP_CLOSE_C) + gValveData.bat = BSP_ReadVbat(); + // TODO:温湿度传感器读错的话就不发了? + float _humi, _temp; + if (BSP_ReadTempHumi(&_humi, &_temp) == 0) { - logDebug("高温关阀"); - tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); + gValveData.temp = (int8_t)_temp; + gValveData.humi = (uint8_t)_humi; + if (gValveData.temp >= HIGN_TEMP_CLOSE_C) + { + logDebug("高温关阀"); + tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); + } } + else + { + logError("Read TempHumi Err"); + // return; + } + #if 1 + logDebug("switch_status:%d Temp:%d Bat:%d Humi:%d%% RSSI: %d" + , gValveData.switch_status, gValveData.temp, gValveData.bat, gValveData.humi, gValveData.rssi); + + #endif + TsRawFrameData RawData; + + BSP_VALVE_Generate_UploadData(&RawData); + + peripheralChar4Notify(&RawData.buf[0], RawData.len); + + tmos_set_event(led_task_id, LED_SHOW_START_EVT); } - else + else if(GPIOA_ReadITFlagBit(BOOST_APIN) == 1) { - logError("Read TempHumi Err"); - // return; + tmos_start_task(Peripheral_TaskID, SBP_PERIODIC_EVT, MS1_TO_SYSTEM_TIME(1000)); } - #if 1 - logDebug("switch_status:%d Temp:%d Bat:%d Humi:%d%% RSSI: %d" - , gValveData.switch_status, gValveData.temp, gValveData.bat, gValveData.humi, gValveData.rssi); - - #endif - TsRawFrameData RawData; - - BSP_VALVE_Generate_UploadData(&RawData); - - peripheralChar4Notify(&RawData.buf[0], RawData.len); - - tmos_set_event(led_task_id, LED_SHOW_START_EVT); } /********************************************************************* diff --git a/BSP/inc/bsp_beep_led_emv.h b/BSP/inc/bsp_beep_led_emv.h index f962c06..faf7229 100644 --- a/BSP/inc/bsp_beep_led_emv.h +++ b/BSP/inc/bsp_beep_led_emv.h @@ -30,18 +30,19 @@ extern tmosTaskID led_task_id; /**********************BOOST 12V_EN PA1************************ */ +#define BOOST_APIN GPIO_Pin_1 #define BOOST_EN \ do \ { \ - GPIOA_SetBits(GPIO_Pin_1); \ - GPIOA_ModeCfg(GPIO_Pin_1, GPIO_ModeOut_PP_5mA); \ + GPIOA_SetBits(BOOST_APIN); \ + GPIOA_ModeCfg(BOOST_APIN, GPIO_ModeOut_PP_5mA); \ } while (0); #define BOOST_OFF_DEINIT \ do \ { \ - GPIOA_ResetBits(GPIO_Pin_1); \ - GPIOA_ModeCfg(GPIO_Pin_1, GPIO_ModeIN_PD); \ + GPIOA_ResetBits(BOOST_APIN); \ + GPIOA_ModeCfg(BOOST_APIN, GPIO_ModeIN_PD); \ } while (0); /***********************BEEP PA0************************ */ diff --git a/BSP/inc/bsp_valve.h b/BSP/inc/bsp_valve.h index 4114a89..c0de180 100644 --- a/BSP/inc/bsp_valve.h +++ b/BSP/inc/bsp_valve.h @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-12 15:55:38 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2025-05-30 13:51:02 + * @LastEditTime : 2025-05-30 16:33:29 * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_valve.h * @Description : * @@ -15,6 +15,8 @@ extern tmosTaskID vavle_task_id; +extern volatile uint8_t boost_en_flag; + #define VAVLE_RX_DATA_EVT (0x0001 << 0) #define VAVLE_TX_DATA_EVT (0x0001 << 1) @@ -38,7 +40,7 @@ extern tmosTaskID vavle_task_id; // #define VALVE_LOW_VBAT_ALARM_PERIOD_MS (1000 * 60 * 10) -#define VALVE_DECT_PERIOD_MS (1000 * 60 * 10) +#define VALVE_DECT_PERIOD_MS (1000 * 60 * 3) #define CHARGE_TIME_MS (2000) @@ -48,7 +50,7 @@ extern tmosTaskID vavle_task_id; // #define LOW_VABAT_CLOSE_VALUE 2000 -#define LOW_VABAT_CLOSE_MV 2150 +#define LOW_VABAT_CLOSE_MV 2200 #define HIGN_TEMP_CLOSE_C 60 diff --git a/BSP/src/bsp_valve.c b/BSP/src/bsp_valve.c index f739b90..e2609e5 100644 --- a/BSP/src/bsp_valve.c +++ b/BSP/src/bsp_valve.c @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-15 15:01:15 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2025-05-29 18:42:42 + * @LastEditTime : 2025-05-30 16:30:38 * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_valve.c * @Description : * @@ -31,6 +31,8 @@ #undef LOG_TAG #define LOG_TAG "BSP_VALVE" +volatile uint8_t boost_en_flag; + TsValveData gValveData = {0}; uint16_t bat_mv; @@ -393,10 +395,11 @@ static uint16_t VAVLE_Task_ProcessEvent(uint8_t task_id, uint16_t events) if (events & VAVLE_CLOSE_START_EVT) { logDebug("VAVLE_CLOSE_START_EVT"); - DelayMs(1); + // DelayMs(1); BSP_BlockSleep(); BSP_RequestBoost(); - DelayMs(10); + boost_en_flag = 1; + // DelayMs(10); EMV_CHARGE_EN; @@ -468,6 +471,7 @@ static uint16_t VAVLE_Task_ProcessEvent(uint8_t task_id, uint16_t events) tmos_set_event(Peripheral_TaskID, SBP_REPLY_CMD_EVT); logDebug("VAVLE_CLOSE_END_EVT"); + boost_en_flag = 0; return (events ^ VAVLE_CLOSE_END_EVT); } // 开始测量电磁铁电感 @@ -533,37 +537,45 @@ static uint16_t VAVLE_Task_ProcessEvent(uint8_t task_id, uint16_t events) if (events & VAVLE_LOOP_DECT_EVT) { logDebug("VAVLE_LOOP_DECT_EVT"); - - // TODO:亮灯或者蜂鸣器的时候读电压就低了 - gValveData.bat = BSP_ReadVbat(); - - // 电压过低就关阀 - // if (gValveData.bat <= LOW_VABAT_CLOSE_VALUE) - if (bat_mv <= LOW_VABAT_CLOSE_MV) + if (GPIOA_ReadITFlagBit(BOOST_APIN) == 0) { - gValveData.switch_status = kClosed; - tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); - } - // else if (gValveData.bat <= LOW_VABAT_ALARM_VALUE) - // { - // tmos_set_event(vavle_task_id, VAVLE_LOW_VBAT_ALARM_EVT); - // } - float _humi, _temp; - if (BSP_ReadTempHumi(&_humi, &_temp) == 0) - { - gValveData.temp = (int8_t)_temp; - gValveData.humi = (uint8_t)_humi; - if (gValveData.temp >= HIGN_TEMP_CLOSE_C) + // TODO:亮灯或者蜂鸣器的时候读电压就低了 + gValveData.bat = BSP_ReadVbat(); + + // 电压过低就关阀 + // if (gValveData.bat <= LOW_VABAT_CLOSE_VALUE) + if (bat_mv <= LOW_VABAT_CLOSE_MV) { - logDebug("高温关阀"); - tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); + gValveData.switch_status = kClosed; + logDebug("低压关阀"); + tmos_start_task(vavle_task_id, VAVLE_CLOSE_START_EVT, MS1_TO_SYSTEM_TIME(1100)); } + // else if (gValveData.bat <= LOW_VABAT_ALARM_VALUE) + // { + // tmos_set_event(vavle_task_id, VAVLE_LOW_VBAT_ALARM_EVT); + // } + float _humi, _temp; + if (BSP_ReadTempHumi(&_humi, &_temp) == 0) + { + gValveData.temp = (int8_t)_temp; + gValveData.humi = (uint8_t)_humi; + if (gValveData.temp >= HIGN_TEMP_CLOSE_C) + { + logDebug("高温关阀"); + tmos_start_task(vavle_task_id, VAVLE_CLOSE_START_EVT, MS1_TO_SYSTEM_TIME(1000)); + } + } + else + { + logError("Read TempHumi Err"); + } + tmos_start_task(vavle_task_id, VAVLE_LOOP_DECT_EVT, MS1_TO_SYSTEM_TIME(VALVE_DECT_PERIOD_MS)); } else { - logError("Read TempHumi Err"); + // 延后5s再测 + tmos_start_task(vavle_task_id, VAVLE_LOOP_DECT_EVT, MS1_TO_SYSTEM_TIME(5000)); } - tmos_start_task(vavle_task_id, VAVLE_LOOP_DECT_EVT, MS1_TO_SYSTEM_TIME(VALVE_DECT_PERIOD_MS)); return (events ^ VAVLE_LOOP_DECT_EVT); } @@ -660,7 +672,7 @@ void BSP_VAVLE_Init(void) gValveData.type = kTyq; gValveData.bat = BSP_ReadVbat(); - tmos_start_task(vavle_task_id, VAVLE_LOOP_DECT_EVT, MS1_TO_SYSTEM_TIME(1000)); + tmos_start_task(vavle_task_id, VAVLE_LOOP_DECT_EVT, MS1_TO_SYSTEM_TIME(VALVE_DECT_PERIOD_MS)); // GPIOA_ResetBits(GPIO_Pin_2); // GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_PU);