📄 key.c
字号:
/*********************************************************
Project: ST FST(TDA7540)
File name: key.c
Description:
Write/Modify: Perry
Time: 2005-11-22- 10:40:55
*********************************************************/
#include "public.h"
#define AD_ONE_LINE_KEY_NUM 11
#pragma INTO_ROM
static const unsigned char ADKeyTable[]=
{
//252,220,160,135,110,80,60,40,27,17,4,0,
252,210,160,136,111,85,62,43,27,17,5,0,
};
/*********************************************
Function: GetOneLineADKey
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:18
*********************************************/
void GetOneLineADKey(unsigned char ADLine,unsigned char Linenum)
{
unsigned char i,temp;
temp=GetADValue(ADLine);
if(temp>252)return;
for(i=0;i<(AD_ONE_LINE_KEY_NUM+1);i++)
{
if(temp>=ADKeyTable[i])
{
Getkey=i+AD_ONE_LINE_KEY_NUM*Linenum;
tempkey1=temp;
tempkey2=Getkey;
break;
}
}
}
/*********************************************
Function: GetADKey
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:20
*********************************************/
void GetADKey(void)
{
GetOneLineADKey(AD_KEY1,0);//getkey=0,11
GetOneLineADKey(AD_KEY2,1);//getkey=11,22
}
static const unsigned char RemoteTable[21]=
{
0x30,0x50,0xA8,0xC8,0x28,0x90,0x88,0xE0,0x60,0x70,
0x10,0x00,0x80,0xF0,0x48,0x40,0xC0,0x08,0x68,0x20,
0xA0
};
/*********************************************
Function: Infra_Red
Description:
Write/Modify: Perry.Liang
Time: 2004-7-2- 11:53:19
*********************************************/
void InfraRed(void)
{
if (IrKey == 0xFF)
{
if (RemoDelay < 6)
{
IrxBuffer[irbit/8] <<= 1;
if (RemoDelay <= 2)
(IrxBuffer[irbit/8]) &= 0xFE; // make 'low'
else
(IrxBuffer[irbit/8]) |= 0x01; // make 'high'
if(irbit<32)irbit++;
if (irbit == 32)
{
irbit=0;
if((IrxBuffer[1] == 0xFF)
&& (IrxBuffer[0] == ~IrxBuffer[1])
&& (IrxBuffer[2] == ~IrxBuffer[3]) )
IrKey = IrxBuffer[2];
}
}
else
irbit=0;
}
RemoDelay = 0;
}
/*********************************************
Function: Ir_Timer
Description:
Write/Modify: Perry.Liang
Time: 2004-7-2- 11:53:24
*********************************************/
void IrTimer(void)
{
if (RemoDelay >= 200)
IrKey = 0xFF;
else
RemoDelay++;
}
/*********************************************
Function: GetRemote
Description:
Write/Modify: Perry.Liang
Time: 2004-7-9- 10:46:07
*********************************************/
void GetRemote(void)
{
unsigned char i;
if(IrKey != 0xFF)
{
for(i=0;i<21;i++)
{
if(RemoteTable[i]==IrKey)
{
Getkey=i+31;
break;
}
}
}
}
/*********************************************
Function: INTEncoder
Description:
Write/Modify: Perry.Liang
Time: 2004-7-21- 10:47:53
*********************************************/
void INTEncoder(void)
{
if(F_EncBackup!=Pin_EVA)
{
M_WAIT;
if(Pin_EVB==Pin_EVA)
GetEnc=P_EC_DN;
else
GetEnc=P_EC_UP;
}
F_EncBackup=Pin_EVA;
}
/*********************************************
Function: GetEncoder
Description:
Write/Modify: Perry.Liang
Time: 2004-7-9- 10:46:03
*********************************************/
void GetEncoder(void)
{
if(GetEnc!=NOKEY && KeyCode==NOKEY)
{
KeyCode=GetEnc;
GetEnc=NOKEY;
}
}
/*********************************************
Function: LongShortKeyProcess
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:27
*********************************************/
void LongShortKeyProcess(void)
{
if(Getkey != DBGetkey&&KeyADTimer==0)
{
DBGetkey = Getkey;
KeyADTimer=3;//avoid vibrating specially when releasing
return;
}
KeyCode = Getkey;
CurrentKey = Getkey;
//PUSH
if (KeyProcessTimer==0 && PreviousKey==NOKEY
&& CurrentKey !=NOKEY)
{
//LONG KEY TIME OR DEPRESS KEY TIME SET
switch(CurrentKey)
{
/*case P_RM_VOLUP:
case P_RM_VOLDN:
case P_AD_VOLUP:
case P_AD_VOLDN:
KeyProcessTimer=HALF_SECOND ;
break;*/
case P_AD_SEEKUP:
case P_AD_SEEKDN:
case P_RM_SEEKUP:
case P_RM_SEEKDN:
KeyProcessTimer = ONE_SECOND;
break;
default :
KeyProcessTimer = ONE_SECOND;
break;
}
}
//LONG OR DEPRESS KEY
if( CurrentKey == PreviousKey
&& CurrentKey !=NOKEY)
{
if (KeyProcessTimer==0)
{
//LONG
switch(CurrentKey)
{
/*case P_RM_VOLUP:
case P_RM_VOLDN:
case P_AD_VOLUP:
case P_AD_VOLDN:
KeyProcessTimer=ONE_TEN_SECOND;
KeyCode=PreviousKey;
break;*/
default:
KeyCode=PreviousKey | LONGKEY;
KeyProcessTimer=0xFF;
break;
}
}
else
KeyCode=NOKEY;
}
//SHORT OR LONG RELEASE
if ( PreviousKey!=NOKEY && CurrentKey == NOKEY)
{
if (KeyProcessTimer==0xFF || KeyProcessTimer==0)
{
//LONG RELEASE
KeyCode=PreviousKey | LONG_RELEASEKEY;
}
else
{
//SHORT
KeyCode=PreviousKey | SHORTKEY;
}
KeyProcessTimer=0;
}
PreviousKey=CurrentKey;
}
/*********************************************
Function: KeyInit
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:30
*********************************************/
void KeyInit(void)
{
//InitRotary();
//PD_REMOTE=0;//PF2--floating interrupt input for keyboard remote
//PO_REMOTE=1;
PD_REMOTE=0;//PF2--floating input for detect panel open/close.(0-close,1-open)
PO_REMOTE=0;
PD_EVA=0;//PA2--floating input
PO_EVA=0;
PD_EVB=0;//PA3--floating input
PO_EVB=0;
PD_ADKEY1=0;//PC0, PC1--floating input
PO_ADKEY1=0;
PD_ADKEY2=0;
PO_ADKEY2=0;
GetEnc=NOKEY;
F_EncBackup=Pin_EVA;
}
/*********************************************
Function: KeyMain
Description:
Write/Modify: Perry.Liang
Time: 2004-7-9- 10:46:15
*********************************************/
void KeyMain(void)
{
Getkey=NOKEY;
KeyCode=NOKEY;
GetADKey();
GetRemote();
LongShortKeyProcess();
GetEncoder();
if(Pin_REMOTE&&KeyCode!=S_AD_EJECT)//Detect panel open/close to disable/enable key process
{
KeyCode=NOKEY;
}
}
/*********************************************
Function: KeyTimer100ms
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:32
*********************************************/
void KeyTimer10ms(void)
{
if ((KeyProcessTimer!=0xFF)&&(KeyProcessTimer>0))
KeyProcessTimer--;
if (KeyADTimer>0)
KeyADTimer--;
}
/*********************************************************
File End
*********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -