ZDBMS/code_app/KeyApp.c

102 lines
2.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************************************************************
Copyright (C), Sinowealth Electronic. Ltd.
Author: Sino
Version: V0.0
Date: 2020/04/26
History:
V2.0 2020/04/26 Preliminary
********************************************************************************/
#include "Main.h"
U8 xdata ucDsgingSpeed;
/*************************************************************************************************
* 函数名: KeySwitchSpeed
* 参 数: 无
* 返回值: 无
* 描 述: 按键调速,分为三挡
*************************************************************************************************/
void KeySwitchSpeed(void)
{
bSlowDischarge = 0;
bMidDischarge = 0;
bFastDischarge = 0;
if(bDSGING)
{
if(ucDsgingSpeed == 0)
{
ucDsgingSpeed = 1;
bMidDischarge = 1;
McuPWM2Set(E2uiDSG1PWMFreq ,E2ucDSG1PWMRatioH);
McuPWM2En();
}
else if(ucDsgingSpeed == 1)
{
ucDsgingSpeed = 2;
bFastDischarge = 1;
McuPWM2Set(E2uiDSG1PWMFreq, 100);
McuPWM2En();
}
else
{
ucDsgingSpeed = 0;
bSlowDischarge = 1;
McuPWM2Set(E2uiDSG1PWMFreq ,E2ucDSG1PWMRatioL);
McuPWM2En();
}
}
else
{
bSlowDischarge = 0;
bMidDischarge = 0;
bFastDischarge = 0;
}
}
/*************************************************************************************************
* 函数名: KeyProcess
* 参 数: 无
* 返回值: 无
* 描 述: 当检测到有效按键后,处理对应按键
*************************************************************************************************/
void KeyProcess(void)
{
if(bKeyFlg)
{
bKeyFlg = 0; //同一按键一直被按下,如果持续的时间足够长,则会先触发长按,后触发长按持续,但目前我们没有用到长按持续状态
switch(ucKeyValue)
{
case KEY_ON_S:
KeySwitchSpeed();
break;
case KEY_LED_S:
bLedDisFlg = 1;
ucLedTimeCnt = 0;
break;
case KEY_LED_L: //长按LED进PD模式
bPDFlg = 1;
break;
case KEY_ON_L: //长按唤醒按键2S蓝牙电源开启/关闭
bLedDisBleFlg = ~bLedDisBleFlg;
if(bLedDisBleFlg)
{
BlueToothPowerEn();
}
else
{
BlueToothPowerDis();
}
break;
default:
break;
}
}
}