📄 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 8
static const unsigned char ADKeyTable[AD_ONE_LINE_KEY_NUM]=
{
0x14,0x20,0x40,0x60,0x85,0xb0
};
/*********************************************
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;
//if(Getkey != NOKEY) return ;
temp=GetADValue(ADLine);
if(temp>240)return;
for(i=0;i<(AD_ONE_LINE_KEY_NUM+1);i++)
{
if(temp<=ADKeyTable[i])
{
Getkey=i+1+AD_ONE_LINE_KEY_NUM*Linenum;
break;
}
}
}
/*********************************************
Function: GetADKey
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:20
*********************************************/
void GetADKey(void)
{
GetOneLineADKey(AD_KEY1,1);
//GetOneLineADKey(AD_KEY2,2);
}
//SUNPLUS IR201
static const unsigned char RemoteTable[49]={
0x30 /*POWER*/,0x00/*EJECT*/,
0xb0/*VOL+*/,0x90/*1*/,0xa0/*2*/,0x80/*3*/,
0x70/*VOL-*/,0x50/*4*/,0x60/*5*/,0x40/*6*/,
0xf0/*MUTE*/,0xd0/*7*/,0xe0/*8*/,0xc0/*9*/,
0x32/*DVD/DVB*/,0x12/*TV/RADIO*/,0x22/*10+*/,0x02/*0*/,
0xb2/*RETURN*/,0x92/*MENU*/,0x62/*DISPLAY*/,0xa2/*LANGUAGE*/,0x82/*L/R*/,
0xe2/*UP*/,
0x72/*FAV-*/,0x52/*ENTER*/,0x42/*FAV+*/,
0xd2/*DOWN*/,
0xf2/*TITLE/TTX*/, 0xe8/*SUBTITLE*/,0xc2/*PROG/EPG*/,
0xf8/*FB*/,0x2a/*PLAY*/,0xc8/*PREVIOUS*/,
0x3a/*FF*/,0xaa/*STOP*/,0x0a/*NEXT*/,
0x38/*SETUP*/,0x18/*GOTO*/,0x28/*P-SCAN/VGA*/,0x08/*P/N*/,
0xb8/*REPEAT*/,0x98/*PREVIEW*/,0xa8/*SLOW+/-*/,0x88/*PAUSE/STEP*/,
0x78/*ZOOM*/,0x58/*A-B*/,0x68/*3D*/,0x48/*ANGLE*/,
};
/*********************************************
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;
#ifdef SINO_MOS
if(IrxBuffer[0] == (unsigned char)((IR_SYSTEM_CODE >> 8)&0x00ff) && IrxBuffer[1] == (unsigned char)(IR_SYSTEM_CODE &0x00ff)){
IrKey = IrxBuffer[2];
}
#else
if((IrxBuffer[1] == 0xFF)
&& (IrxBuffer[0]+IrxBuffer[1]==255)
&& (IrxBuffer[2]+IrxBuffer[3]==255))
//&& (IrxBuffer[0] == ~IrxBuffer[1])
//&& (IrxBuffer[2] == ~IrxBuffer[3]) )
IrKey = IrxBuffer[2];
#endif
}
}
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(Getkey != NOKEY)
// return ;
if(IrKey != 0xFF)
{
for(i=0;i<49;i++)
{
if(RemoteTable[i]==IrKey)
{
Getkey=i+AD_ONE_LINE_KEY_NUM;//To Get area so set the length is 10
break;
}
}
}
}
void KeyPreproc()
{
static unsigned char times = 0;
times ++;
times = times%5;
if(PreviousKey != Getkey && PreviousKey == NOKEY)
{
PreviousKey = Getkey;
debug_val("Key:",Getkey);
switch(Getkey)
{
case IR_POWER:
case KEY_POWER:
SysCommand = SYSTEM_COMMAND_POWER;
break;
case KEY_MODE:
SysCommand = SYSTEM_COMMAND_MODE;
break;
case KEY_EJECT:
case IR_EJECT:
SysCommand = SYSTEM_COMMAND_EJECT;
break;
case IR_DVD_DVB:
SysCommand = SYSTEM_COMMAND_MODE;
break;
default:
ADDSendCommandToBuff(SEND_IRVFD_KEY,Getkey);
// DSA_init();
// SendBuf[0] = SEND_IRVFD_KEY << 8 | Getkey;
// DsaSendCommand();
break;
}
}else if(Getkey == NOKEY){
PreviousKey = NOKEY;
}
}
/*********************************************
Function: LongShortKeyProcess
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:27
*********************************************/
#if 0
void LongShortKeyProcess(void)
{
if(Getkey != DBGetkey)
{
DBGetkey = Getkey;
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_AD_DIRDOWN:
case P_AD_DIRUP:
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;
//SCI_SendPromter("L KEY", &KeyCode, 1);
//SCI_SendString("L:");
//SCI_Val(KeyCode);
}
else
{
//SHORT
KeyCode=PreviousKey | SHORTKEY;
//SCI_SendPromter("S KEY", &KeyCode, 1);
//SCI_SendString("S:");
//SCI_Val(KeyCode);
}
KeyProcessTimer=0;
}
PreviousKey=CurrentKey;
}
#endif
/*********************************************
Function: KeyInit
Description:
Write/Modify: Perry.Liang
Time: 2006-1-24- 15:41:30
*********************************************/
void KeyInit(void)
{
PD_REMOTE=0;
PCR1_REMOTE=1;
PCR2_REMOTE=1;
/*
PDDR_ADKEY1=0;
PCR1_ADKEY1=0;
PCR2_ADKEY1=0;
PDDR_ADKEY2=0;
PCR1_ADKEY2=0;
PCR2_ADKEY2=0;
*/
ADC_TDRL |= y00000100;
ADC_TDRH |=y10000000;
IrKey = 0xFF;
PreviousKey = NOKEY;
Getkey = NOKEY;
SysCommand = SYSTEM_COMMAND_IDLE;
// status = WHEEL_STATUS_CLK_INIT;
}
/*********************************************
Function: KeyMain
Description:
Write/Modify: Perry.Liang
Time: 2004-7-9- 10:46:15
*********************************************/
void KeyMain(void)
{
//SCI_SendString("KEY");
Getkey=NOKEY;
SysCommand = SYSTEM_COMMAND_IDLE;
//KeyCode=NOKEY;
//GetADKey();
GetRemote();
KeyPreproc();
// MultiFuncKey();
//LongShortKeyProcess();
//GetEncode();
//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
*********************************************/
#if 0
void KeyTimer10ms(void)
{
if ((KeyProcessTimer!=0xFF)&&(KeyProcessTimer>0))
KeyProcessTimer--;
}
#endif
/*********************************************************
File End
*********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -