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

📄 tirnec_0.c.svn-base

📁 最新火热的CX32 源代码
💻 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:
 *  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"

Byte	 Factory_Data[4];
/*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 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;

static Void tdIRNEC1msTimer(Void)
{
    if (t_RemoteData.wCount == t_RemoteData.wFirstDelay)
    {
#ifdef _NEW_REPEATKEY_FUNC_
		t_bFastRepeatKeyEnable = _FALSE_;
#endif        
        tdAddVirtualKey(s_RemoteData.ucRemoteCode/* | _VK_STATUS_DOWN_*/);
        t_RemoteData.wCount--;
    } 
    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)
                	tdAddVirtualKey(s_RemoteData.ucRemoteCode);
#else
                tdAddVirtualKey(s_RemoteData.ucRemoteCode | _VK_STATUS_DOWN_);
#endif                
                tdClearValBit(s_ucRemoteFlag, _RF_NEC_LEADERCODE_);
                t_RemoteData.wCount = t_RemoteData.wRepeatDelay - 1;
            }
        } 
    }
    /*else
    {
    	tdAddVirtualKey(s_RemoteData.ucRemoteCode);
    }*/
}

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);        
        } else if ((pNECRemote->Remote_Code_1_Min <= ucRemoteCode) && ( ucRemoteCode <= pNECRemote->Remote_Code_1_Max))   /*code 1*/
        {
            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*/
            {
            	//Printf("SYSCODE:%x\n",s_RemoteData.ucRemoteTemp);
                tdClearValBit(s_ucRemoteFlag, _RF_NEC_SYSTEMCODE_);
                if (s_RemoteData.ucSCheckSum && (s_RemoteData.ucRemoteTemp + s_RemoteData.ucRemoteBackup) != s_RemoteData.ucSCheckSum)
                {
                    tdClearValBit(s_ucRemoteFlag, (_RF_NEC_TRANSLATE_|_RF_NEC_STARTED_));
                    goto detect_head;
                }
                s_RemoteData.ucSystemCode = s_RemoteData.ucRemoteBackup; 
            } else  /*Is the data code*/ 
            {
                if (s_RemoteData.ucDCheckSum && (s_RemoteData.ucRemoteTemp + s_RemoteData.ucRemoteBackup) == s_RemoteData.ucDCheckSum)
                {
                    ucIndex = 0;
                    while ((*((RPByte)pNECRemote + s_RemoteData.ucOffset + ucIndex) != (s_RemoteData.ucRemoteBackup & 0x7F)) && (ucIndex < s_RemoteData.ucKeyNum))
                    {
	                    j = *((RPByte)pNECRemote + s_RemoteData.ucOffset + ucIndex);
			            ucIndex += 2;
                    }
                    if (ucIndex < s_RemoteData.ucKeyNum)
                    {
                        s_RemoteData.ucRemoteTemp = *((RPByte)pNECRemote + s_RemoteData.ucOffset + ucIndex + 1);      /*set repeat data*/
                        tdSetValBit(s_ucRemoteFlag, (_RF_NEC_REPEAT_|_RF_NEC_FIRSTREPEAT_));                               /*set repeat flag*/
                        s_RemoteData.ucRemoteCode = s_RemoteData.ucRemoteTemp;
                        t_RemoteData.wCount = t_RemoteData.wFirstDelay;
                    } 
                }
                tdClearValBit(s_ucRemoteFlag, (_RF_NEC_TRANSLATE_|_RF_NEC_STARTED_));
                return;
            }
        } else /*Is the first code*/
        {
            if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_SYSTEMCODE_))  /*Is the system code*/
            {	
                for (i = 0; i < pNECRemote->System_Code_Num; i++)
                {
                    if (pNECRemote->RemoteKeySet[i].ucSystemCode == s_RemoteData.ucRemoteTemp)
                        break;
                }
                if (i == pNECRemote->System_Code_Num)
                {
                    tdClearValBit(s_ucRemoteFlag, (_RF_NEC_SYSTEMCODE_|_RF_NEC_TRANSLATE_|_RF_NEC_STARTED_));
                    goto detect_head;
                }
                else
                {
                    s_RemoteData.ucKeyNum = pNECRemote->RemoteKeySet[i].ucKeyNum << 1;
		                  s_RemoteData.ucOffset = pNECRemote->RemoteKeySet[i].ucKeySetOffset;
		                  s_RemoteData.ucSCheckSum = pNECRemote->RemoteKeySet[i].ucSCodeCheckSum;
                    s_RemoteData.ucDCheckSum = pNECRemote->RemoteKeySet[i].ucDataCheckSum;
                }     
            }
            else if (pNECRemote->System_Code_Num == 0)  /*the protocol hasn't system code*/
            {
                s_RemoteData.ucOffset = pNECRemote->RemoteKeySet[0].ucKeySetOffset;
                s_RemoteData.ucKeyNum = pNECRemote->RemoteKeySet[0].ucKeyNum << 1;
                s_RemoteData.ucSCheckSum = pNECRemote->RemoteKeySet[0].ucSCodeCheckSum;
                s_RemoteData.ucDCheckSum = pNECRemote->RemoteKeySet[0].ucDataCheckSum;	
            }	 	
            tdSetValBit(s_ucRemoteFlag, _RF_NEC_CONVERT_);
        }    
        s_RemoteData.ucRemoteBackup = s_RemoteData.ucRemoteTemp;
        s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;
        s_RemoteData.ucRemoteTemp = 0;
        return;
    } 

detect_head:
    if ((pNECRemote->Remote_Code_Sync_Min <= ucRemoteCode) && (ucRemoteCode <= pNECRemote->Remote_Code_Sync_Max))   /*sync code*/
    {
        tdSetValBit(s_ucRemoteFlag, _RF_NEC_STARTED_);   /*started parsing*/
        s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;          /*0x01*/
        s_RemoteData.ucRemoteTemp = 0x00;
        if (pNECRemote->System_Code_Num)
            tdSetValBit(s_ucRemoteFlag, _RF_NEC_SYSTEMCODE_);   /*the following is the system code*/
        else
            tdClearValBit(s_ucRemoteFlag, _RF_NEC_SYSTEMCODE_); /*the protocol hasn't system code*/
        tdClearValBit(s_ucRemoteFlag, (_RF_NEC_CONVERT_|_RF_NEC_REPEAT_));
    } else 
    {
        if ((pNECRemote->Remote_Code_Leader_Min <= ucRemoteCode) && (ucRemoteCode <= pNECRemote->Remote_Code_Leader_Max))   /*leader code*/
        {
            if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_REPEAT_))
            {
                if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_FIRSTREPEAT_))
                {
                    tdClearValBit(s_ucRemoteFlag, (_RF_NEC_FIRSTREPEAT_|_RF_NEC_TRANSLATE_|_RF_NEC_CONVERT_|_RF_NEC_STARTED_));
                    return;
                } else if (t_RemoteData.wCount < t_RemoteData.wRepeatDelay)
                {
                    /* process repeat code */
                    if(t_RemoteData.wCount ==0)
                    {
                        t_RemoteData.wCount = 1;
                    }
                    tdSetValBit(s_ucRemoteFlag, _RF_NEC_LEADERCODE_);
                }
            }
        } 
        /*if error remote code,do not translate.*/
        tdClearValBit(s_ucRemoteFlag, (_RF_NEC_CONVERT_|_RF_NEC_STARTED_));
    }
}

Code RemoteControllerDriver f_IRNECDriver = 
{
    tdIRNEC1msTimer, tdIRNECService
};

⌨️ 快捷键说明

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