⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tirnec_2.c.svn-base

📁 最新火热的CX32 源代码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
 /**
 *  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:
 *  03/04/2004     Modify RC5 part(decode & repeat) by Max and Joy
 *  04/18/2003     Added repeat key support by Archie
 *  08/01/2002     Created by Rick, York, Joy and Archie
 *
 */

#include "tdefs.h"
#include "tio.h"
#include "tutils.h"
#include "tvkey.h"
#include "tRemote.h"

#include "thilevel.h"
#include "ttimer.h"

//#define _IR_DEBUG_

enum SYSCODE
{
	SYSUSER = 0xFC,//0xBF,
	SYSFACTORY = 0xEE,
	SYSDATAW = 0xE2,
	SYSDATAR = 0xE3,
	SYSEEPROM = 0xE6,
	SYSTESTSIGNAL = 0xEA,
	SYSDIRECTAV = 0xEB
};


/*remote flag*/
static Byte s_ucRemoteFlag = 0;
static Byte SYS_MODE = 0xff;
Byte	 Factory_Data[4];

#ifdef _IR_DEBUG_
Byte IR_DATA[50];
Byte IR_Index ;
#endif

/*dy
const Byte KeyCodeFactory[][2] =
{
	{0x01, COMMAND_M},
	{0x08, COMMAND_BUSOFF},
};
*/
/*the following two global variables are used by remote routines*/
static Void tdRemoteCodeDetect(Byte ucRemoteCode);

static Gdata struct tagRemoteData
{
    Byte ucRemoteBackup;     /*store the first code of system or data*/
    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 ucSCheckSum;
    Byte ucDCheckSum;
    Byte ucPreviousCountVal; /*timer count value of last time*/
    Byte ucSystemCode;
    Byte ucRemoteCode;
    Byte ucOffset;
    Byte ucKeyNum;
} s_RemoteData;

extern GBool t_bFastRepeatKeyEnable;
extern GBool t_bSlowRepeatKeyEnable;
extern GBool t_bNewKey;
extern GBool t_bRemoteKey;

extern Gdata Byte ucAutoOffTimer;
static  Void tdIRNEC1msTimer(Void)
{
	if (t_RemoteData.wCount == t_RemoteData.wFirstDelay)
	{
#ifdef _NEW_REPEATKEY_FUNC_
		t_bFastRepeatKeyEnable = _FALSE_;
		t_bSlowRepeatKeyEnable = _FALSE_;
#endif       
		tdAddVirtualKey(s_RemoteData.ucRemoteCode/* | _VK_STATUS_DOWN_*/);
		t_RemoteData.wCount--;
		ucAutoOffTimer = 0;
#ifdef _IR_DEBUG_
		Printf("Downing Code:0x%x\n", s_RemoteData.ucRemoteCode);
#endif

	} 
	else if (t_RemoteData.wCount) 
	{
		t_RemoteData.wCount--;
		if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_LEADERCODE_))
		{  
			if (t_RemoteData.wCount == 0)
			{
#ifdef _NEW_REPEATKEY_FUNC_
				if(t_bFastRepeatKeyEnable||t_bSlowRepeatKeyEnable)
				{
			#ifdef _IR_DEBUG_
					Printf("Repeating Code:0x%x\n", s_RemoteData.ucRemoteCode);
			#endif
					tdAddVirtualKey(s_RemoteData.ucRemoteCode/*| _VK_STATUS_DOWN_*/);				
				}
#else
				tdAddVirtualKey(s_RemoteData.ucRemoteCode | _VK_STATUS_DOWN_);
#endif                
				tdClearValBit(s_ucRemoteFlag, _RF_NEC_LEADERCODE_);
				if(t_bSlowRepeatKeyEnable)
					t_RemoteData.wCount = t_RemoteData.wRepeatDelay*4 - 1;
				else
					t_RemoteData.wCount = t_RemoteData.wRepeatDelay - 1;
				t_bNewKey = 0;
			}
		} 
	}
	/*
	else
	{
	#ifdef _IR_DEBUG_
		Printf("Key is up!\n", 12);
	#endif
		tdAddVirtualKey(s_RemoteData.ucRemoteCode);
		s_RemoteData.ucRemoteCode = _VK_NONE_;
	}*/
}

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;
}


Bool ucselect = _TRUE_;
IWord ucCurrentCountValtemp1,ucCurrentCountValtemp2;
Word ucRemotecodetest[100];
static BYTE ucRemotetestIndex = 0;

static Void tdIRNECService(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 = REMOTE_TIMER_VALUE;  
       ucRemoteCode = ucCurrentCountVal / 0x05;
   	REMOTE_TIMER_STOP;      // Stop & Clear Timer
   	REMOTE_TIMER_START;     // ReStart Timer
   	//if (ucRemoteCode > 10)
   	{
   	 if (ucRemotetestIndex <99)
   	 	ucRemotecodetest[ucRemotetestIndex++] = ucRemoteCode;
	tdRemoteCodeDetect(ucRemoteCode); 
   	}

}

/**
 *    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
 */
 //Defined for NEC Remote Protocol.
static Void tdRemoteCodeDetect(Byte ucRemoteCode)
{
	IByte ucIndex;
	IByte i;

	Byte j;
	
	if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_STARTED_))
	{
		if ((pNECRemote->Remote_Code_0_Min <= ucRemoteCode) && (ucRemoteCode <= pNECRemote->Remote_Code_0_Max)) /*code 0*/
		{
			tdLeftShift1(s_RemoteData.ucRemoteShift); 
#ifdef _IR_DEBUG_
			//IR_DATA[IR_Index++] = ucRemoteCode;
#endif
		}
		else if ((pNECRemote->Remote_Code_1_Min <= ucRemoteCode) && ( ucRemoteCode <= pNECRemote->Remote_Code_1_Max))   /*code 1*/
		{
#ifdef _IR_DEBUG_
			//IR_DATA[IR_Index++] = ucRemoteCode;
#endif
			s_RemoteData.ucRemoteTemp += s_RemoteData.ucRemoteShift;
			tdLeftShift1(s_RemoteData.ucRemoteShift);        
		}
		else
		{
			/*if error remote code,do not translate.*/
			tdClearValBit(s_ucRemoteFlag, (_RF_NEC_TRANSLATE_|_RF_NEC_CONVERT_|_RF_NEC_STARTED_));
			goto detect_head;
		}

		if (s_RemoteData.ucRemoteShift)        /*if hasn't finished to shift eight times, return. */
			return;

		if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_CONVERT_))  /*Is the second code*/
		{
			tdClearValBit(s_ucRemoteFlag, _RF_NEC_CONVERT_);
			if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_SYSTEMCODE_))  /*Is the system code*/
			{
#ifdef _IR_DEBUG_
				//Printf(" P2= %x\n",s_RemoteData.ucRemoteTemp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -