This commit is contained in:
parent
6be501416a
commit
6e21243b34
|
@ -1,15 +1,3 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : main.c
|
||||
* Author : WCH
|
||||
* Version : V1.1
|
||||
* Date : 2020/08/06
|
||||
* Description : 外设从机应用主函数及任务系统初始化
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "CONFIG.h"
|
||||
#include "HAL.h"
|
||||
#include "gattprofile.h"
|
||||
|
@ -43,49 +31,44 @@ __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();
|
||||
BSP_RequestBoost();
|
||||
|
||||
// DelayMs(15);
|
||||
// BSP_BlockSleep();
|
||||
// BSP_RequestBoost();
|
||||
|
||||
switch (app_evt_type)
|
||||
{
|
||||
case kKeyShort:
|
||||
tmos_set_event(vavle_task_id, VAVLE_DECT_SWITCH_START_EVT);
|
||||
logDebug("button short press");
|
||||
key_press_cnt++;
|
||||
logDebug("key_press_cnt = %d", key_press_cnt);
|
||||
|
||||
if (valve_switch_dect_flag)
|
||||
if (key_press_cnt == 1)
|
||||
{
|
||||
valve_switch_dect_flag = 0;
|
||||
|
||||
logDebug("LED显示状态");
|
||||
// tmos_set_event(led_task_id, LED_SHOW_START_EVT);
|
||||
BSP_BlockSleep();
|
||||
BSP_RequestBoost();
|
||||
DelayMs(1);
|
||||
// BSP_RequestBoost();
|
||||
DelayMs(3);
|
||||
ShowLed();
|
||||
// tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT);
|
||||
// tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000);
|
||||
}
|
||||
if (key_press_cnt >= 2)
|
||||
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)
|
||||
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(3);
|
||||
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;
|
||||
|
@ -93,8 +76,8 @@ void app_task_handler(TeAppEvtType app_evt_type)
|
|||
|
||||
// tmos_set_event(led_task_id, LED_SHOW_START_EVT);
|
||||
BSP_BlockSleep();
|
||||
BSP_RequestBoost();
|
||||
DelayMs(1);
|
||||
// BSP_RequestBoost();
|
||||
DelayMs(3);
|
||||
ShowLed();
|
||||
// tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT);
|
||||
// tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000);
|
||||
|
@ -127,87 +110,6 @@ 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(3);
|
||||
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(3);
|
||||
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(3);
|
||||
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
|
||||
*
|
||||
|
@ -264,115 +166,38 @@ int main(void)
|
|||
// 改成 4000000 波特率了
|
||||
BSP_UART1_Init(4000000);
|
||||
#endif
|
||||
DelayMs(1000 * 1);
|
||||
|
||||
ShowRestartReason();
|
||||
|
||||
CH58x_BLEInit();
|
||||
|
||||
HAL_Init();
|
||||
GAPRole_PeripheralInit();
|
||||
Peripheral_Init();
|
||||
|
||||
DelayMs(1000 * 3);
|
||||
|
||||
// HAL_Init();
|
||||
// GAPRole_PeripheralInit();
|
||||
// Peripheral_Init();
|
||||
|
||||
// log打印编译时间和编译日期
|
||||
logDebug("Compile Time: %s %s", __DATE__, __TIME__);
|
||||
logDebug("GetSysClock = %d Hz", GetSysClock());
|
||||
|
||||
// extern void Peripheral_SetMacName(void);
|
||||
// Peripheral_SetMacName();
|
||||
// while(1)
|
||||
// {
|
||||
// DelayMs(1000);
|
||||
// }
|
||||
|
||||
BSP_FLASH_Init();
|
||||
|
||||
BSP_BEEP_LED_EMV_Init();
|
||||
|
||||
PRINT("PRINT\r\n");
|
||||
|
||||
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
|
||||
logError("中文测试 %2.2f", 123.456);
|
||||
|
||||
logDebug("%s\n", VER_LIB);
|
||||
|
||||
uint8_t MacAddr[6];
|
||||
GetMACAddress(MacAddr);
|
||||
// 手机APP显示是倒序的[5-0],不是[0-5]
|
||||
logDebug("MacAddr: %02X:%02X:%02X:%02X:%02X:%02X", MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]);
|
||||
// log打印编译时间和编译日期
|
||||
logDebug("Compile Time: %s %s", __DATE__, __TIME__);
|
||||
|
||||
GXHTC3C_Init();
|
||||
CH58x_BLEInit();
|
||||
HAL_Init();
|
||||
GAPRole_PeripheralInit();
|
||||
Peripheral_Init();
|
||||
|
||||
BSP_FLASH_Init();
|
||||
|
||||
BSP_KEY_Init(app_task_handler);
|
||||
|
||||
// IWDG_Init(1500);
|
||||
// DelayMs(1000 * 3);
|
||||
|
||||
BSP_BEEP_LED_EMV_Init();
|
||||
GXHTC3C_Init();
|
||||
BSP_ADC_Init();
|
||||
|
||||
BSP_VAVLE_Init();
|
||||
|
||||
BSP_BlockSleep();
|
||||
BSP_RequestBoost();
|
||||
DelayMs(10);
|
||||
#if 0
|
||||
DelayMs(1);
|
||||
EMV_CHARGE_EN;
|
||||
logDebug("EMV_CHARGE_EN");
|
||||
DelayMs(1500);
|
||||
|
||||
BOOST_EN;
|
||||
// 关阀动作,一定要先关充电的,防止其他12V用电
|
||||
EMV_CHARGE_OFF_DEINIT;
|
||||
BEEP_ON;
|
||||
logDebug("EMV_CHARGE_OFF_DEINIT");
|
||||
EMV_ON;
|
||||
logDebug("EMV_ON");
|
||||
DelayMs(100);
|
||||
|
||||
BEEP_OFF_DEINIT;
|
||||
EMV_CHARGE_OFF_DEINIT;
|
||||
EMV_OFF_DEINIT;
|
||||
LED_ALL_OFF_DEINIT;
|
||||
|
||||
DelayMs(100);
|
||||
|
||||
BSP_VAVLE_Init();
|
||||
VavleDect_Start();
|
||||
DelayMs(10);
|
||||
valve_switch_off_freq = VavleDect_GetFreq();
|
||||
logDebug("valve_switch_off_freq = %06d Hz", valve_switch_off_freq);
|
||||
|
||||
while (1)
|
||||
{
|
||||
LED_ALL_OFF_DEINIT;
|
||||
DelayMs(500);
|
||||
LED_R_ON;
|
||||
DelayMs(500);
|
||||
if (IS_KEY_Vaild())
|
||||
{
|
||||
DelayMs(20);
|
||||
if (IS_KEY_Vaild())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DelayMs(100);
|
||||
|
||||
BSP_VAVLE_Init();
|
||||
VavleDect_Start();
|
||||
DelayMs(10);
|
||||
valve_switch_on_freq = VavleDect_GetFreq();
|
||||
logDebug("valve_switch_on_freq = %06d Hz", valve_switch_on_freq);
|
||||
valve_switch_freq = valve_switch_on_freq;
|
||||
VavleDect_Switch();
|
||||
#endif
|
||||
// BSP_VAVLE_Init();
|
||||
|
||||
ShowLed();
|
||||
BEEP_ON;
|
||||
|
@ -435,6 +260,4 @@ int main(void)
|
|||
Main_Circulation();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************************** endfile @ main ******************************/
|
||||
|
|
Loading…
Reference in New Issue