📄 tirtoshiba.c.svn-base
字号:
/**
* This code and information is part of Trident DPTV API (TDAPI)
*
* Copyright (C) Trident Multimedia Technologies (Shanghai) Co., Ltd.
* 2002 - 2003 All rights reserved.
*
* This file provides functions for TV or demoboard remote controller.
*
* Revision:
* 20/01/2005 Created by Lewis and Archie
*
*/
#include "tdefs.h"
#include "tio.h"
#include "tutils.h"
#include "tvkey.h"
#include "thilevel.h"
#include "ttimer.h"
#include "tRemote.h"
/*remote flag*/
static Byte s_ucRemoteFlag = 0;
/*the following two global variables are used by remote routines*/
static Void tdRemoteCodeDetect(Byte ucRemoteCode);
static Gdata struct tagRemoteData
{
Dword ucRemoteTemp; /*store the temporary value of a code,tdRemoteCodeDetect was call definite times to generate a code*/
Dword ucRemoteShift; /*used to count shift times and generate s_RemoteData.ucRemoteTemp*/
Byte ucPreviousCountVal; /*timer count value of last time*/
Byte ucDataCode; /*store the data code part*/
Byte ucRemoteCode;
Byte ucOffset;
Byte ucKeyNum;
} s_RemoteData;
static Void tdIRTOSHIBA1msTimer(Void)
{
if (t_RemoteData.wCount == t_RemoteData.wFirstDelay)
{
tdAddVirtualKey(s_RemoteData.ucRemoteCode);
t_RemoteData.wCount--;
tdClearValBit(s_ucRemoteFlag, _RF_TOSHIBA_REPEAT_);
}else if (t_RemoteData.wCount)
{
t_RemoteData.wCount--;
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_TOSHIBA_REPEAT_))
{
if(t_RemoteData.wCount == 0)
{
tdAddVirtualKey(s_RemoteData.ucRemoteCode /*| _VK_STATUS_DOWN_*/);
tdClearValBit(s_ucRemoteFlag, _RF_TOSHIBA_REPEAT_);
t_RemoteData.wCount = t_RemoteData.wRepeatDelay - 1;
}
}
}
}
static Byte tdGetTimeInterval(Byte ucCurrentCountVal)
{
/* when the INT0 interrupt the timer interrupt service */
if (!ucCurrentCountVal)
ucCurrentCountVal = tdLoadInitTimerCount();
#ifdef _TIMERCOUNT_DOWN_
if (ucCurrentCountVal < s_RemoteData.ucPreviousCountVal)
ucCurrentCountVal = s_RemoteData.ucPreviousCountVal - ucCurrentCountVal;
else
ucCurrentCountVal = s_RemoteData.ucPreviousCountVal + tdGetTimerBInterval() - ucCurrentCountVal;
#else
if (ucCurrentCountVal >= s_RemoteData.ucPreviousCountVal)
ucCurrentCountVal = ucCurrentCountVal - s_RemoteData.ucPreviousCountVal;
else
ucCurrentCountVal = ucCurrentCountVal + tdGetTimerBInterval() - s_RemoteData.ucPreviousCountVal;
#endif
return ucCurrentCountVal;
}
static Void tdIRTOSHIBAService(Void)
{
IByte ucRemoteCode;
IByte ucCurrentCountVal;
ucCurrentCountVal = tdGetTimerBCurrentCount();
#ifdef _TIMERCOUNT_DOWN_
if(ucCurrentCountVal > tdLoadInitTimerCount())
#else
if(ucCurrentCountVal < tdLoadInitTimerCount())
#endif
ucCurrentCountVal = tdLoadInitTimerCount();
tdClearInterruptPend();
ucRemoteCode = tdGetTimeInterval(ucCurrentCountVal);
s_RemoteData.ucPreviousCountVal = ucCurrentCountVal;
tdRemoteCodeDetect(ucRemoteCode); /* Analyse remote key */
}
static Void tdRemoteCodeDetect(Byte ucRemoteCode)
{
IByte ucIndex;
IByte i;
if((s_ucRemoteFlag & _RF_TOSHIBA_STARTED_) != 0)
{
if((pTOSHIBARemote->Remote_Code_0_Min <= ucRemoteCode) && (ucRemoteCode <= pTOSHIBARemote->Remote_Code_0_Max))
{
//Check if code "0".
tdLeftShift1(s_RemoteData.ucRemoteShift);
}else if((pTOSHIBARemote->Remote_Code_1_Min <= ucRemoteCode) && ( ucRemoteCode <= pTOSHIBARemote->Remote_Code_1_Max)) /*code 1*/
{
//Check if code "1".
s_RemoteData.ucRemoteTemp += s_RemoteData.ucRemoteShift;
tdLeftShift1(s_RemoteData.ucRemoteShift);
}else
{
//if error remote code,do not translate, and recheck the header pulse.
s_ucRemoteFlag = 0;
goto detect_head;
}
if((s_ucRemoteFlag & _RF_TOSHIBA_SYSTEMCODE_) != 0)
{
if(s_RemoteData.ucRemoteShift == (1 << 1))
{
if(s_RemoteData.ucRemoteTemp & 0x01 != 0)
{
s_ucRemoteFlag = 0;
s_ucRemoteFlag |= _RF_TOSHIBA_REPEAT_;
return;
}
s_ucRemoteFlag &= ~_RF_TOSHIBA_REPEAT_;
s_RemoteData.ucRemoteCode = 0;
}
if(s_RemoteData.ucRemoteShift == (1 << 16)) //pTOSHIBARemote->System_Bit_Num can not be achieved from tool
{
s_ucRemoteFlag &= ~_RF_TOSHIBA_SYSTEMCODE_;
if((s_RemoteData.ucRemoteTemp & 0x00FF) != (s_RemoteData.ucRemoteTemp >> 8))
{
s_ucRemoteFlag = 0;
return;
}
for(ucIndex = 0; ucIndex < pTOSHIBARemote->System_Code_Num; ucIndex++)
{
if(pTOSHIBARemote->RemoteKeySet[ucIndex].ucSystemCode == (Byte)s_RemoteData.ucRemoteTemp)
break;
}
if(ucIndex == pTOSHIBARemote->System_Code_Num)
{
s_ucRemoteFlag =0;
return;//goto detect_head;
}
else
{
s_RemoteData.ucOffset = pTOSHIBARemote->RemoteKeySet[ucIndex].ucKeySetOffset;
s_RemoteData.ucKeyNum = pTOSHIBARemote->RemoteKeySet[ucIndex].ucKeyNum << 1;
s_ucRemoteFlag |= _RF_TOSHIBA_DATACODE_;
s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;
s_RemoteData.ucRemoteTemp = 0;
return;
}
}
return;
}
if((s_ucRemoteFlag & _RF_TOSHIBA_DATACODE_) != 0)
{
if(s_RemoteData.ucRemoteShift == 1<<16)
{
if(((s_RemoteData.ucRemoteTemp & 0xFF) + (s_RemoteData.ucRemoteTemp >> 8)) != 0xFF)
{
s_ucRemoteFlag = 0;
return;
}
s_RemoteData.ucDataCode = (Byte)s_RemoteData.ucRemoteTemp;
ucIndex = 0;
while((*((RPByte)pTOSHIBARemote + s_RemoteData.ucOffset + ucIndex) != s_RemoteData.ucDataCode) && (ucIndex < s_RemoteData.ucKeyNum))
{
ucIndex += 2;
}
if(ucIndex < s_RemoteData.ucKeyNum)
{
s_RemoteData.ucRemoteCode = *((RPByte)pTOSHIBARemote + s_RemoteData.ucOffset + ucIndex + 1);
s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;
s_RemoteData.ucRemoteTemp = 0;
s_RemoteData.ucDataCode = 0;
//Timing related set
t_RemoteData.wCount = t_RemoteData.wFirstDelay;
s_ucRemoteFlag &= ~_RF_TOSHIBA_REPEAT_;
s_ucRemoteFlag &= ~_RF_TOSHIBA_STARTED_;
}
else
{
s_ucRemoteFlag = 0;
s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;
}
}
return;
}
}
detect_head:
if((pTOSHIBARemote->Remote_Code_Header_Min <= ucRemoteCode) && (ucRemoteCode <= pTOSHIBARemote->Remote_Code_Header_Max)) //sync code
{
//started parsing.
s_ucRemoteFlag |= _RF_TOSHIBA_STARTED_;
s_ucRemoteFlag |= _RF_TOSHIBA_SYSTEMCODE_;
//set the initial value of shifting.
s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;
s_RemoteData.ucRemoteTemp = 0;
s_RemoteData.ucDataCode = 0;
}
else
{
//if error remote code,do not translate.
//s_ucRemoteFlag = 0;
s_ucRemoteFlag &= ~_RF_TOSHIBA_STARTED_;
}
return;
}
Code RemoteControllerDriver f_IRTOSHIBADriver =
{
tdIRTOSHIBA1msTimer, tdIRTOSHIBAService
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -