/************************************************************************
*                             ---- 居加居 ----                           
*  文件名:      	Keys.c
*  编写人员:    	Kinve JQ
*  说明:         
*  版本:        		V0.1
*  编写日期:    	2018-09-30
*  程序维护:     
*  维护记录:    
*    					2018-09-30.Kinve:1.创建文件
* 免责声明：
* (c) Author Kinve JQ. All rights reserved.
**************************************************************************/
#include "Keys.h"
#include "Delay.h"

#define delay_ms(ms)	Timer3_Delay1ms(ms)

/********************************方式2*******************************/
u8 GetKey_CS(void)
{
	return !P05;		//按下
}

u8 Fast_Check_CS(void)
{
	if(GetKey_CS()){
		delay_ms(20);
		if(GetKey_CS()){
			return 1;
		}		
	}
	return 0;
}


volatile pKey Keys[KEY_MAX] =
{
    {KEY_CS, GetKey_CS, KEY_UP_FLAG, 0, 0, 0, NO_KEY_FLAG},
};

void Keys_Even(void)	//20ms
{
	u8 i;
	for ( i = 0; i < KEY_MAX; i++ )
    {
        if ( Keys[i].GetKey() )	
        {
            Keys[i].DnTime++;

            if ( Keys[i].DnTime == CANCEL_KEY_DOWN ) 	//80ms
            {
            	Keys[i].Res = ONE_HITS_KEY_FLAG;
            }
            else if ( Keys[i].DnTime == LONG_KEY_DOWN ) //3秒，长按
            {
            	Keys[i].Res = LONG_KEY_FLAG;
            }
		}
		else
		{
			Keys[i].DnTime = 0;
		}
	}

}


void Key_CS_Hanlder(void);
void Key_CS_Long_Hanlder(void);
void Key_JS_Hanlder(void);
void Key_JS_Long_Hanlder(void);
void Keys_All_Handler(void)
{
	if(Keys[KEY_CS].Res == ONE_HITS_KEY_FLAG)
	{
		Keys[KEY_CS].Res = NO_KEY_FLAG;
		Key_CS_Hanlder();
	}
	else if(Keys[KEY_CS].Res == LONG_KEY_FLAG)
	{
		Keys[KEY_CS].Res = NO_KEY_FLAG;
		Key_CS_Long_Hanlder();
	}	
}


/****************************按键处理***********************************/
void Key_JS_Hanlder ( void )
{
#if 0

    if ( SysRunType == SysRun_Norm )
    {
        StopBeep();
    }
#endif	
}

#if 0
void soft_reset(void)
{
   ((void (code *) (void)) 0x0000) ();
}
#endif
void Key_CS_Hanlder ( void )
{
#if 0
    switch ( SysRunType )
    {
    case SysRun_Norm:
        SysRunType = SysRun_Test;
        sysLed_Set ( LED_MODE_TEST_RUN );
        break;

    case SysRun_Test:
        SysRunType = SysRun_Norm;
        sysLed_Set ( LED_MODE_WORK_RUN );
        break;
    }

    Fas_Param_Of_Mode_Change ( SysRunType );
#endif	

}

void Key_JS_Long_Hanlder ( void )
{

}

void Key_CS_Long_Hanlder ( void)
{
}

void WaitKey_GotoTest ( void )
{
#if 0

    static bool Can_enter_Factory = TRUE;

    if ( sys_rtc_time <= 10 )				//启动10秒内,按下Key_CS
    {
        if ( Can_enter_Factory )
        {
            Can_enter_Factory = FALSE;
            SysRunType = SysRun_Test;
            sysLed_Set ( LED_MODE_TEST_RUN );
        }
    }
#endif	
}

/********************* (C) COPYRIGHT Kinve JQ  *******END OF FILE ********/


