📄 tirmitsubishi.c.svn-base
字号:
/**
* This code and information is part of Trident DPTV API (TDAPI)
*
* Copyright (C) Trident Multimedia Technologies (Shanghai) Co., Ltd.
* 2004 - 2005 All rights reserved.
*
* This file provides functions for TV or demoboard remote controller.
* The driver is for Mitsubishi IR format.
*
* Revision:
* 09/10/2004 Created by Ivan Wen.
*
*/
#include "tdefs.h"
#include "tio.h"
#include "tutils.h"
#include "tvkey.h"
#include "tRemote.h"
#include "thilevel.h"
#include "ttimer.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
{
Byte ucRemoteTemp; /*store the temporary value of a code,tdRemoteCodeDetect was call 8 times to generate a code*/
Byte ucRemoteShift; /*used to count shift times and generate s_RemoteData.ucRemoteTemp*/
Byte ucPreviousCountVal; /*timer count value of last time*/
Byte ucRemoteCode;
Byte ucOffset;
Byte ucKeyNum;
} s_RemoteData;
static Void tdIRMI1msTimer(Void)
{
if (t_RemoteData.wCount == t_RemoteData.wFirstDelay)
{
tdAddVirtualKey(s_RemoteData.ucRemoteCode);
t_RemoteData.wCount--;
} else if (t_RemoteData.wCount)
{
t_RemoteData.wCount--;
}
}
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 tdIRMIService(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 */
}
/**
* This function translates the pressed remote key code.
* When user press on the remote controller, the key code
* will store in a global value and let the function RemoteInput()
* return key code.
*
*
* @param ucRemoteCode(I) - the time distance between two pulse
* generated by remote controller
* @return None
* @see tdRemoteService
*/
static Void tdRemoteCodeDetect(Byte ucRemoteCode)
{
IByte ucIndex;
if (tdTestValBitTrue(s_ucRemoteFlag, _RF_MI_STARTED_))
{
if ((pMIRemote->Remote_Code_0_Min <= ucRemoteCode) && (ucRemoteCode <= pMIRemote->Remote_Code_0_Max)) /*code 0*/
{
tdLeftShift1(s_RemoteData.ucRemoteShift);
} else if ((pMIRemote->Remote_Code_1_Min <= ucRemoteCode) && ( ucRemoteCode <= pMIRemote->Remote_Code_1_Max)) /*code 1*/
{
s_RemoteData.ucRemoteTemp += s_RemoteData.ucRemoteShift;
tdLeftShift1(s_RemoteData.ucRemoteShift);
} else if(tdTestValBitTrue(s_ucRemoteFlag, _RF_MI_PAUSECODE_) && (pMIRemote->Remote_Code_Pause_Min <= ucRemoteCode) && (ucRemoteCode <= pMIRemote->Remote_Code_Pause_Max))
{
tdClearValBit(s_ucRemoteFlag, _RF_MI_PAUSECODE_);
tdSetValBit(s_ucRemoteFlag, _RF_MI_DATACODE_);
s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START; /*0x01*/
s_RemoteData.ucRemoteTemp = 0x00;
return;
}else
{
/*if error remote code,do not translate.*/
tdClearValBit(s_ucRemoteFlag, (_RF_MI_STARTED_));
goto detect_head;
}
if (s_RemoteData.ucRemoteShift) /*if hasn't finished to shift eight times, return. */
return;
if (tdTestValBitTrue(s_ucRemoteFlag, _RF_MI_SYSTEMCODE_)) /*Is the second code*/
{
tdClearValBit(s_ucRemoteFlag, _RF_MI_SYSTEMCODE_);
if(pMIRemote->ucSystemCode == s_RemoteData.ucRemoteTemp)
{
tdSetValBit(s_ucRemoteFlag, _RF_MI_PAUSECODE_);
return;
}else
{
s_ucRemoteFlag = 0;
return;
}
}
if(tdTestValBitTrue(s_ucRemoteFlag, _RF_MI_DATACODE_))
{
ucIndex = 0;
tdClearValBit(s_ucRemoteFlag, _RF_MI_DATACODE_);
while(*((RPByte)pMIRemote +pMIRemote->ucKeyOffset + 2 * ucIndex) != s_RemoteData.ucRemoteTemp)
{
ucIndex ++;
}
if(ucIndex < pMIRemote->ucKeyNum)
{
s_RemoteData.ucRemoteTemp = *((RPByte)pMIRemote + pMIRemote->ucKeyOffset + 2 * ucIndex + 1);
if(s_RemoteData.ucRemoteCode == s_RemoteData.ucRemoteTemp)
{
if(t_RemoteData.wCount == 0)
{
t_RemoteData.wCount = t_RemoteData.wFirstDelay;
s_ucRemoteFlag = 0;
return;
}
}else
{
t_RemoteData.wCount = t_RemoteData.wFirstDelay;
s_RemoteData.ucRemoteCode = s_RemoteData.ucRemoteTemp;
s_ucRemoteFlag = 0;
return;
}
}
}
}
detect_head:
if ((pMIRemote->Remote_Code_Sync_Min <= ucRemoteCode) && (ucRemoteCode <= pMIRemote->Remote_Code_Sync_Max)) /*sync code*/
{
s_ucRemoteFlag = 0;
tdSetValBit(s_ucRemoteFlag, _RF_MI_STARTED_|_RF_MI_SYSTEMCODE_); /*started parsing*/
s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START; /*0x01*/
s_RemoteData.ucRemoteTemp = 0x00;
}
return;
}
Code RemoteControllerDriver f_IRMIDriver =
{
tdIRMI1msTimer, tdIRMIService
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -