#define IR_SENSE_SHORT_PRESS_THRESHOLD 2000 //200ms
#define IR_SENSE_LONG_PRESS_THRESHOLD 30000 //3s
void PT91_Recv_Handle(void)
{
static u8 flag = 0; //反转的标志
//PT_Level_Read_Temp=GPIO_ReadInputPin(PT91_PORT,PT91_PIN);
IR_Input_Level=GPIO_ReadInputPin(PT91_PORT,PT91_PIN);
// PT_PIN Trace follow start
if(IR_Input_Level==HIGH)//High
{
if(PT_Input_High_Counter<PT_INPUT_HIGH_COUNTER_MAX)// prevent to flow
{
PT_Input_High_Counter++;
}
else
{
PT_Input_High_Counter=0;
}
}
else//Low
{
if(PT_Input_Low_Counter<PT_INPUT_LOW_COUNTER_MAX)// prevent to flow
{
PT_Input_Low_Counter++;
}
else
{
PT_Input_Low_Counter=0;
}
}
// PT_PIN Trace follow end
// PT_PIN wave peroid judge start
PT_Trace_Peroid=PT_Input_Low_Counter+PT_Input_High_Counter;
PT_Input_PR=PT_Trace_Peroid;
if(PT_Trace_Peroid>PT_TRACE_PEROID_LOW_THRESHOLD && PT_Trace_Peroid<PT_TRACE_PEROID_HIGH_THRESHOLD) //trace success
{
PT_Trace_Success_Counter++;
if(PT_Trace_Success_Counter>IR_SENSE_LONG_PRESS_THRESHOLD)// long IR sensed
{
Short_IR_sense_judge_state=NO;
Long_IR_sense_judge_state=YES;
PT_Trace_Success_Counter=0;
// long IR sense handle
LED1_L;
}
else if(PT_Trace_Success_Counter>IR_SENSE_SHORT_PRESS_THRESHOLD)
{
if(flag)
{
Long_IR_sense_judge_state=YES;
}
Short_IR_sense_judge_state=YES;
PT_Trace_Success_Counter=0;
// short IR sense handle
LED3_L;
}
else
{
PT_Trace_Success_Counter++;
}
flag = !flag;
}
else //trace fail
{
PT_Trace_Success_Counter=0;
PT_Input_High_Counter=0;
PT_Input_Low_Counter=0;
Short_IR_sense_judge_state=NO;
Long_IR_sense_judge_state=NO;
}
// PT_PIN wave peroid judge end
}
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
TIM4_ClearITPendingBit(TIM4_IT_UPDATE);//清除更新标志位
PT91_Recv_Handle();
}
一周热门 更多>