key.c

来自「myson的MTV332的DEMO程序 主要功能有菜单的设计和无线遥控以及视频」· C语言 代码 · 共 248 行

C
248
字号
#include "global.h"

BIT i2c_flag=0;
BYTE HoldKeyIndex = 0 ;
BYTE FactoryKeyIndex= 0 ;
BYTE RecoveryKeyIndex= 0;

#define KeyCount	5
/****************************************************************************/
void Initial_Key(void)
{
	OldKey = 0x00;
	KeyStep = 0;
	IR_Key = IR_No_Key;
}

/****************************************************************************/
#ifdef _BAUO070_CS7110_M3_
BYTE ReadKeyPort(void)
{
	BYTE tempkey;
	if(PressPOWERKey)
		tempkey = POWERKEY;
	else if(PressMENUKey)
		tempkey = MENUKEY;
	else if(PressSELECTKey)
		tempkey = SELECTKEY;
	else if(PressUPKey)
		tempkey = UPKEY;
	else if(PressDOWNKey)
		tempkey = DOWNKEY;
	else
		tempkey = NOKEY;
	return tempkey;
}
#else
BYTE ReadKeyPort(void)
{
   BYTE ADPort0; 

   byMTV_ADC = 0x81;		//Use P5.0 ADC0 pin
   Short_Delay(500);		//    DELAY10ms(1);//DoWait(2);
   ADPort0 = byMTV_ADC;	//	   ADPort0 <<=2;

	//tempkey = NOKEY;
	if(KEYPIN0) 		
		return  SELECTKEY;	 
	else if(KEYPIN1)		
		return  UPKEY;
	 else if(KEYPIN2)		
		return   MENUKEY;
	 else if(KEYPIN3)		
		return  DOWNKEY; 
	 else if(KEYPIN4)
	 	return SHUNTDOWN;
	else 
		return  NOKEY;

}
#endif

/****************************************************************************/
BYTE GetKey(void)
{
	BYTE temp, keyno;

	keyno = NOKEY;

	switch(KeyStep)
	{
		case 0 :   // check key change
			
			temp = ReadKeyPort();
			if( temp != OldKey)
			{
				OldKey = temp;
				KeyStep = 1;
				KeyReChkCnt = KEY_STABLE_TIME;
			}
			
		break;	
		case 1 :  // wait key stable
			if(KeyReChkCnt == 0)
			{
				KeyStep = 0;
				temp = ReadKeyPort();
				//keytest = temp;
				if( temp == OldKey)
				{
					keyno = temp;
					if(keyno == UPKEY || keyno == DOWNKEY )
					{
						KeyStep = 2;
						KeyReChkCnt = KEY_REPEAT_TIME1;
					}
					else if(keyno == DEBUGKEY)  // i2c debug mode
					{
						KeyStep = 2;
						KeyReChkCnt = KEY_DEBUG_TIME;
					}
					else if(keyno == SHUNTDOWN)  // i2c debug mode
					{
						KeyStep = 2;
						KeyReChkCnt = 2000;  //Wait 3Second then power off
						
						PowerFlag = ~PowerFlag; 				
						if(PowerFlag)	
						{
							DisableOSD();				
							MenuProcess = Disp_Entry;
							bMenuFlag=0;
							Res_BKLT;
							Res_PowerLED;
						}
						else	
						{
						       bVsyncChange = 1;
						       Get_VideoSync();
							Set_BKLT; //panel on
							Set_PowerLED;
						}
					}
				}
			}
			
		break;
		case 2 :  // check key repeat
			temp = ReadKeyPort();
			if( temp != OldKey)
				KeyStep = 0;
			
			if(KeyReChkCnt == 0)
			{
				keyno = temp;
				KeyReChkCnt = KEY_REPEAT_TIME2;		
				if(keyno == DEBUGKEY)  // i2c debug mode
				{
					KeyStep = 0;
					i2c_flag = ~i2c_flag;
					/*
					if(i2c_flag)
						MenuProcess = Disp_IICHold;
					else
						MenuProcess = Disp_Entry;
					*/
					bMenuFlag = 0;
				}	
			}
			
		break;
	}
	
	return keyno;
}

void CheckIICHoldKey()
{
	//BYTE code HoldKey[KeyCount]={SELECTKEY,DOWNKEY,SELECTKEY,DOWNKEY,DOWNKEY};
	BYTE code HoldKey[]={SELECTKEY,SELECTKEY,SELECTKEY,SELECTKEY,SELECTKEY};
	BYTE code FactoryKey[]={MENUKEY,DOWNKEY,MENUKEY,SELECTKEY,SELECTKEY};
	BYTE code RecoveryKey[]={SELECTKEY,SELECTKEY,SELECTKEY,SELECTKEY,DOWNKEY};
	if(KeyNo==NOKEY)
		return;

	if(KeyNo==HoldKey[HoldKeyIndex])
		HoldKeyIndex++;	
	else
		HoldKeyIndex=0;
		
	if(KeyNo==FactoryKey[FactoryKeyIndex])
		FactoryKeyIndex++;		
	else
		FactoryKeyIndex = 0;

	if(KeyNo==RecoveryKey[RecoveryKeyIndex])
		RecoveryKeyIndex++;		
	else
		RecoveryKeyIndex = 0;

	
	if(RecoveryKeyIndex>=KeyCount)
	{
		RecoveryKeyIndex = 0;
		Initial_EEPData();
		Read_EEPData();
		Initial_SystemSetting();
		#ifdef _CS7111_
		Initial_Video();
		#endif
	}

	if(HoldKeyIndex>=KeyCount)
	{
		i2c_flag=~i2c_flag;
		HoldKeyIndex = 0;
		if(i2c_flag)
		{
			gotoxy(0,0);
			PrintChar(_D,Cyan);
			PrintChar(_e,Cyan);
			PrintChar(_b,Cyan);
			PrintChar(_u,Cyan);
			PrintChar(_g,Cyan);
			EnableOSD();
			SetSDA;
			SetSCL;
		}
		else
		{
			gotoxy(0,0);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			EnableOSD();
		}
	}

	if(FactoryKeyIndex>=KeyCount)
	{
		FactoryFg=~FactoryFg;
		FactoryKeyIndex = 0;
		if(FactoryFg)
		{
			gotoxy(0,0);
			PrintChar(_F,Cyan);
			PrintChar(_A,Cyan);
			PrintChar(_C,Cyan);
			PrintChar(_T,Cyan);
			PrintChar(_O,Cyan);
			EnableOSD();
		}
		else
		{
			gotoxy(0,0);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			PrintChar(__,Cyan);
			EnableOSD();
		}
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?