|
@@ -8,44 +8,61 @@ Key_TypeDef Key_Break_Right;
|
|
|
Key_TypeDef Key_GearSensor;
|
|
|
|
|
|
/**********************局部函数定义************************/
|
|
|
-void _GPIO_Read(Key_TypeDef* Key)
|
|
|
+void _GPIO_Read(Key_TypeDef* Key, uint8_t TrigNum)
|
|
|
{
|
|
|
uint8_t ReadData;
|
|
|
|
|
|
+ //读按键状态
|
|
|
if(HAL_GPIO_ReadPin(Key->GPIOx, Key->GPIO_Pin) == GPIO_PIN_RESET)
|
|
|
{
|
|
|
- if(Key->SwitchType == NormallyOpen)
|
|
|
+ if(Key->SwitchType == NormallyOpen)//常开型开关
|
|
|
{
|
|
|
ReadData = 0x01;
|
|
|
}
|
|
|
- else
|
|
|
+ else//常闭型开关
|
|
|
{
|
|
|
ReadData = 0x00;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(Key->SwitchType == NormallyOpen)
|
|
|
+ if(Key->SwitchType == NormallyOpen)//常开型开关
|
|
|
{
|
|
|
ReadData = 0x00;
|
|
|
}
|
|
|
- else
|
|
|
+ else//常闭型开关
|
|
|
{
|
|
|
ReadData = 0x01;
|
|
|
}
|
|
|
}
|
|
|
- Key->Trg = ReadData & (ReadData ^ (Key->Cont));
|
|
|
+
|
|
|
+ //触发标志
|
|
|
+ if(TrigNum == 1) //单极触发
|
|
|
+ {
|
|
|
+ Key->Trg = ReadData & (ReadData ^ (Key->Cont));
|
|
|
+ }
|
|
|
+ else //双极触发
|
|
|
+ {
|
|
|
+ Key->Trg = ReadData ^ (Key->Cont);
|
|
|
+ }
|
|
|
Key->Cont = ReadData;
|
|
|
}
|
|
|
|
|
|
|
|
|
-void Key_Check(Key_TypeDef* Key, uint32_t DelayTime, TrueOrFalse_Flag_Struct_t* Flag)
|
|
|
+void Key_Check(Key_TypeDef* Key, uint32_t DelayTime, uint32_t AutoReleaseDelayTime, FlagStatus UndoReleaseFlag, TrueOrFalse_Flag_Struct_t* Flag)
|
|
|
{
|
|
|
- _GPIO_Read(Key);
|
|
|
+ if(UndoReleaseFlag == RESET) //松开按键不释放信号,等待自动超时释放,此时AutoReleaseDelayTime不能设置为0
|
|
|
+ {
|
|
|
+ _GPIO_Read(Key, 1);
|
|
|
+ }
|
|
|
+ else //松开按键释放信号
|
|
|
+ {
|
|
|
+ _GPIO_Read(Key, 2);
|
|
|
+ }
|
|
|
+
|
|
|
if(Key->Trg & 0x01)//表示有触发(下降沿)
|
|
|
{
|
|
|
Key->PressFlasg = 1;
|
|
|
- *Flag = TRUE;//有效信号
|
|
|
Key->TimeCnt = HAL_GetTick();//计时赋初值
|
|
|
}
|
|
|
if(Key->PressFlasg == 1)//被触发一次
|
|
@@ -53,26 +70,34 @@ void Key_Check(Key_TypeDef* Key, uint32_t DelayTime, TrueOrFalse_Flag_Struct_t*
|
|
|
if(Key->Cont == 0x00)//表示松开
|
|
|
{
|
|
|
Key->TimeCnt = HAL_GetTick();
|
|
|
+ Key->AutoReleaseTimeCnt = HAL_GetTick();
|
|
|
Key->PressFlasg = 0;
|
|
|
*Flag = FALSE;//松开释放信号
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if((HAL_GetTick() - Key->TimeCnt) > DelayTime)
|
|
|
+ {
|
|
|
+ Key->TimeCnt = HAL_GetTick();
|
|
|
+ Key->PressFlasg = 0;
|
|
|
+ *Flag = TRUE;
|
|
|
+ Key->AutoReleaseTimeCnt = HAL_GetTick();//自动释放计时赋初值
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if(*Flag == 1)//超时自动释放信号
|
|
|
+ if(*Flag == TRUE)//超时自动释放信号
|
|
|
{
|
|
|
- if(DelayTime != 0) //超时设置值为0时不自动释放信号
|
|
|
+ if(AutoReleaseDelayTime != 0) //超时设置值为0时不自动释放信号
|
|
|
{
|
|
|
- if((HAL_GetTick() - Key->TimeCnt) > DelayTime)
|
|
|
+ if((HAL_GetTick() - Key->AutoReleaseTimeCnt) > AutoReleaseDelayTime)
|
|
|
{
|
|
|
- Key->TimeCnt = HAL_GetTick();
|
|
|
+ Key->AutoReleaseTimeCnt = HAL_GetTick();
|
|
|
Key->PressFlasg = 0;
|
|
|
*Flag = FALSE;//超时自动释放信号
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- Key->TimeCnt = HAL_GetTick();
|
|
|
- }
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -138,8 +163,8 @@ void Break_Check(TrueOrFalse_Flag_Struct_t* BreakFlag)
|
|
|
static TrueOrFalse_Flag_Struct_t IsBreakTrig_Left_Flag = FALSE;//刹车标志
|
|
|
static TrueOrFalse_Flag_Struct_t IsBreakTrig_Right_Flag = FALSE;//刹车标志
|
|
|
|
|
|
- Key_Check(&Key_Break_Left, 0, &IsBreakTrig_Left_Flag); //被触发时认为有效信号,松开时释放
|
|
|
- Key_Check(&Key_Break_Right, 0, &IsBreakTrig_Right_Flag); //被触发时认为有效信号,松开时释放
|
|
|
+ Key_Check(&Key_Break_Left, 100, 0, SET, &IsBreakTrig_Left_Flag); //被长按100ms时认为有效信号,松开时释放
|
|
|
+ Key_Check(&Key_Break_Right, 100, 0, SET, &IsBreakTrig_Right_Flag); //被长按100ms时认为有效信号,松开时释放
|
|
|
|
|
|
*BreakFlag = (TrueOrFalse_Flag_Struct_t)((uint8_t)IsBreakTrig_Left_Flag & (uint8_t)IsBreakTrig_Right_Flag);
|
|
|
|
|
@@ -152,7 +177,7 @@ void Break_Check(TrueOrFalse_Flag_Struct_t* BreakFlag)
|
|
|
//GearSensor检测函数
|
|
|
void GearSensor_Check(TrueOrFalse_Flag_Struct_t *Flag)
|
|
|
{
|
|
|
- Key_Check(&Key_GearSensor, 1000, Flag);//被触发时认为有效信号,松开时释放或超时1000ms释放
|
|
|
+ Key_Check(&Key_GearSensor, 10, 1000, SET, Flag);//被长按10ms时认为有效信号,松开时释放或超时1000ms释放
|
|
|
|
|
|
#if 0
|
|
|
static uint8_t GearSensorFlag_Debug;
|