📄 tirmat88.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 IR function for MAT88 Remoter which is from National/Panasonic.
*
* Revision:
* 06/09/2004 Modified by Ivan wen for support the new MAT88 remoter controller.
* 08/26/2004 Updated by Ivan Wen for support two series of system code setting in one remoter controller.
* 07/21/2004 Created by Ivan Wen.
*
*/
#include "tdefs.h"
#include "tio.h"
#include "tutils.h"
#include "tvkey.h"
#include "tRemote.h"
#include "ioctrl.h"
#include "thilevel.h"
#include "ttimer.h"
#include "tvdebug.h"
Byte Factory_Data[4];
/*remote flag*/
static Byte s_ucRemoteFlag = 0;
#ifdef _IR_DEBUG_
Byte IR_DATA[50];
Byte IR_Index ;
#endif
static Void tdRemoteCodeDetect(Byte ucRemoteCode);
/*the following two global variables are used by remote routines*/
static Gdata struct tagRemoteData
{
Word wRemoteShift;
Word wRemoteTemp;
Byte ucDataCode;
Byte ucRemoteCode;
Byte ucPreviousCountVal;
Byte ucSysIndex;
} s_RemoteData;
extern GBool t_bNewKey;
extern GBool t_bRemoteKey;
extern Gdata Byte ucAutoOffTimer;
static GByte s_ucTimeOutCount = 0;
#ifdef _IR_DEBUG_
Byte uc;
#endif
static Void tdIRM881msTimer(Void)
{
if (t_RemoteData.wCount == t_RemoteData.wFirstDelay)
{
tdAddVirtualKey(s_RemoteData.ucRemoteCode);
t_RemoteData.wCount--;
}else if (t_RemoteData.wCount)
{
t_RemoteData.wCount--;
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_M88_LEADERCODE_))
{
if(t_RemoteData.wCount == 0)
{
tdAddVirtualKey(s_RemoteData.ucRemoteCode /*| _VK_STATUS_DOWN_*/);
tdClearValBit(s_ucRemoteFlag, _RF_M88_LEADERCODE_);
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 tdIRM88Service(Void)
{
IByte ucRemoteCode;
IWord 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 */
REMOTE_TIMER_LOAD;
ucCurrentCountVal = TB0CP0H;
ucRemoteCode = ucCurrentCountVal;
REMOTE_TIMER_STOP; // Stop & Clear Timer
REMOTE_TIMER_START; // ReStart Timer
//if (ucRemoteCode > 10)
{
// if (ucRemotetestIndex <99)
// ucRemotecodetest[ucRemotetestIndex++] = ucRemoteCode;
tdRemoteCodeDetect(ucRemoteCode);
}
}
static Void tdRemoteCodeDetect(Byte ucRemoteCode)
{
IByte ucIndex;
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_M88_STARTED_))
{
if((pM88Remote->Remote_Code_0_Min <= ucRemoteCode) && (ucRemoteCode <= pM88Remote->Remote_Code_0_Max))
{
//Check if code "0".
tdLeftShift1(s_RemoteData.wRemoteShift);
}else
{
if((pM88Remote->Remote_Code_1_Min <= ucRemoteCode) && ( ucRemoteCode <= pM88Remote->Remote_Code_1_Max)) /*code 1*/
{
//Check if code "1".
s_RemoteData.wRemoteTemp += s_RemoteData.wRemoteShift;
tdLeftShift1(s_RemoteData.wRemoteShift);
}
else
{
//if error remote code,do not translate, and recheck the sync head pulse.
s_ucRemoteFlag = 0;
goto detect_head;
}
}
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_M88_HEADCODE_))
{
if(!(s_RemoteData.wRemoteShift))
{
for(ucIndex =0; ucIndex < pM88Remote->System_Code_Num; ucIndex++)
{
if(s_RemoteData.wRemoteTemp == pM88Remote->RemoteKeySet[ucIndex].ucHeadCode)
{
break;
}
}
if(ucIndex == pM88Remote->System_Code_Num)
{
tdClearValBit(s_ucRemoteFlag, _RF_M88_STARTED_|_RF_M88_HEADCODE_);
goto detect_head;
}
tdClearValBit(s_ucRemoteFlag, _RF_M88_HEADCODE_);
tdSetValBit(s_ucRemoteFlag, _RF_M88_SYSTEMCODE1_);
s_RemoteData.wRemoteTemp = 0;
s_RemoteData.wRemoteShift =REMOTE_SHIFT_START;
}
return;
}
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_M88_SYSTEMCODE1_))
{
if(s_RemoteData.wRemoteShift == 0x100)
{
for(ucIndex =0; ucIndex < pM88Remote->System_Code_Num; ucIndex++)
{
if(pM88Remote->RemoteKeySet[ucIndex].ucSystem1Code == (s_RemoteData.wRemoteTemp & 0xFF))
{
break;
}
}
if(ucIndex == pM88Remote->System_Code_Num)
{
tdClearValBit(s_ucRemoteFlag, _RF_M88_STARTED_|_RF_M88_SYSTEMCODE1_);
goto detect_head;
}
tdClearValBit(s_ucRemoteFlag, _RF_M88_SYSTEMCODE1_);
tdSetValBit(s_ucRemoteFlag, _RF_M88_SYSTEMCODE2_);
s_RemoteData.wRemoteTemp = 0;
s_RemoteData.wRemoteShift =REMOTE_SHIFT_START;
}
return;
}
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_M88_SYSTEMCODE2_))
{
if(s_RemoteData.wRemoteShift == 0x100)
{
for(ucIndex = 0; ucIndex < pM88Remote->System_Code_Num; ucIndex ++)
{
if(pM88Remote->RemoteKeySet[ucIndex].ucSystem2Code == (s_RemoteData.wRemoteTemp & 0xFF))
break;
}
if(ucIndex == pM88Remote->System_Code_Num)
{
tdClearValBit(s_ucRemoteFlag, _RF_M88_STARTED_|_RF_M88_SYSTEMCODE2_);
goto detect_head;
}
s_RemoteData.ucSysIndex = ucIndex;
tdClearValBit(s_ucRemoteFlag, _RF_M88_SYSTEMCODE2_);
tdSetValBit(s_ucRemoteFlag, _RF_M88_DATACODE_);
s_RemoteData.wRemoteTemp = 0;
s_RemoteData.wRemoteShift =REMOTE_SHIFT_START;
}
return;
}
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_M88_DATACODE_))
{
if(s_RemoteData.wRemoteShift == 0x100)
{
s_RemoteData.ucDataCode = s_RemoteData.wRemoteTemp & 0xFF;
tdClearValBit(s_ucRemoteFlag, _RF_M88_DATACODE_);
tdSetValBit(s_ucRemoteFlag, _RF_M88_CHECKCODE_);
s_RemoteData.wRemoteTemp = 0;
s_RemoteData.wRemoteShift =REMOTE_SHIFT_START;
}
return;
}
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_M88_CHECKCODE_))
{
if(s_RemoteData.wRemoteShift == 0x100)
{
if((pM88Remote->RemoteKeySet[s_RemoteData.ucSysIndex].ucSystem1Code ^ pM88Remote->RemoteKeySet[s_RemoteData.ucSysIndex].ucSystem2Code ^ s_RemoteData.ucDataCode) != (s_RemoteData.wRemoteTemp & 0xFF))
{
}else
{
ucIndex = 0;
while ((*((RPByte)pM88Remote + pM88Remote->RemoteKeySet[s_RemoteData.ucSysIndex].ucKeySetOffset + ucIndex) != s_RemoteData.ucDataCode) && (ucIndex < 2 * pM88Remote->RemoteKeySet[s_RemoteData.ucSysIndex].ucKeyNum))
{
ucIndex += 2;
}
if(ucIndex < 2 * pM88Remote->RemoteKeySet[s_RemoteData.ucSysIndex].ucKeyNum)
{
s_RemoteData.ucDataCode = *((RPByte)pM88Remote + pM88Remote->RemoteKeySet[s_RemoteData.ucSysIndex].ucKeySetOffset + ucIndex + 1);
if(t_RemoteData.wCount != 0)
{
if(s_RemoteData.ucDataCode == s_RemoteData.ucRemoteCode)
{
}else
{
t_RemoteData.wCount = t_RemoteData.wFirstDelay;
s_RemoteData.ucRemoteCode = s_RemoteData.ucDataCode;
}
}else
{
t_RemoteData.wCount = t_RemoteData.wFirstDelay;
s_RemoteData.ucRemoteCode = s_RemoteData.ucDataCode;
}
}
}
tdClearValBit(s_ucRemoteFlag, _RF_M88_STARTED_|_RF_M88_CHECKCODE_);
}
return;
}
}
detect_head:
if((pM88Remote->Remote_Code_Sync_Min <= ucRemoteCode) && (ucRemoteCode <= pM88Remote->Remote_Code_Sync_Max)) //sync code
{
//started parsing.
tdSetValBit(s_ucRemoteFlag, _RF_M88_STARTED_|_RF_M88_HEADCODE_);
//set the initial value of shifing.
s_RemoteData.wRemoteShift = REMOTE_SHIFT_START;
s_RemoteData.wRemoteTemp = 0x00;
s_RemoteData.ucSysIndex =0;
return;
}
}
Code RemoteControllerDriver f_IRM88Driver =
{
tdIRM881msTimer, tdIRM88Service
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -