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

📄 tirnec.c.svn-base

📁 最新火热的CX32 源代码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
#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); 
   	}

}

/**
 *    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;
//	tvDebugPrint1("ucRemoteCode = %d\n", ucRemoteCode);
	
	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);
#endif
                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*/ 
    		{
#ifdef _IR_DEBUG_
//			Printf(" P4= %x\n",s_RemoteData.ucRemoteTemp);
#endif
                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) && (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;
#ifdef IR_DEBUG		
//	IR_DATA[IR_Index++] =s_ucRemoteFlag;
#endif
	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_));
#ifdef _IR_DEBUG_
//		IR_DATA[0] = ucRemoteCode;
//		IR_Index = 1;
#endif
    } else 
    {
        if ((pNECRemote->Remote_Code_Leader_Min <= ucRemoteCode) && (ucRemoteCode <= pNECRemote->Remote_Code_Leader_Max))   /*leader code*/
        {
            if (tdTestValBitTrue(s_ucRemoteFlag, _RF_NEC_REPEAT_))
            {
                //set g_KeyInfo.bRemoteKeyDown flag
                g_KeyInfo.bRemoteKeyDown = _TRUE_;
                //clear s_ucTimeOutCount
                s_ucTimeOutCount = 0;
                
                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 user set t_RemoteData.wRepeatDelay less than 110ms, 
                    //t_RemoteData.wCount is already 0, then meet HW Remote_Code_Leader
                    //In this case, it should also respond repeat key
                    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 + -