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

📄 tirmatsushita.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"

/*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 ucRemotePreBackup;
    Byte ucPreviousCountVal; /*timer count value of last time*/
    Byte ucSystemCode;
    Byte ucRemoteCode;
	Byte ucRemoteLastCode;
    Byte ucOffset;
    Byte ucKeyNum;
} s_RemoteData;


static Void tdIRMA1msTimer(Void)
{
	if (t_RemoteData.wCount)
		t_RemoteData.wCount--;
	else
		s_RemoteData.ucRemoteLastCode = 0;
}

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 tdIRMAService(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 */ 
}

static Void tdRemoteCodeDetect(Byte ucRemoteCode)
{
    IByte ucIndex;
    IByte i;
    
    if(tdTestValBitTrue(s_ucRemoteFlag, _RF_MA_STARTED_))
    {
        if((pMARemote->Remote_Code_0_Min <= ucRemoteCode) && (ucRemoteCode <= pMARemote->Remote_Code_0_Max)) 
        {
            //Check if code "0".
            tdLeftShift1(s_RemoteData.ucRemoteShift);        
        }else
        {
            if((pMARemote->Remote_Code_1_Min <= ucRemoteCode) && ( ucRemoteCode <= pMARemote->Remote_Code_1_Max))   /*code 1*/
            {
                 //Check if code "1".
                 s_RemoteData.ucRemoteTemp += s_RemoteData.ucRemoteShift;
                 tdLeftShift1(s_RemoteData.ucRemoteShift);        
       	    }else
       	    {
                //if error remote code,do not translate, and recheck the sync head pulse.
                tdClearValBit(s_ucRemoteFlag, (_RF_MA_TRANSLATE_|_RF_MA_CONVERT_|_RF_MA_STARTED_));
                goto detect_head;
            }
        }
        if(tdTestValBitTrue(s_ucRemoteFlag, _RF_MA_SYSTEMCODE_))
        {
            //if the code is system code.
            if(s_RemoteData.ucRemoteShift == 1 << pMARemote->System_Bit_Num)
            {
                if(!tdTestValBitTrue(s_ucRemoteFlag, _RF_MA_CONVERT_))   //Is the first system code
                {
                    for(i = 0; i < pMARemote->System_Code_Num; i++)
                    {
                        if(pMARemote->RemoteKeySet[i].ucSystemCode == s_RemoteData.ucRemoteTemp)
                            break;	
                    }
                    if(i == pMARemote->System_Code_Num)
                    {
                        tdClearValBit(s_ucRemoteFlag, (_RF_MA_SYSTEMCODE_|_RF_MA_TRANSLATE_|_RF_MA_STARTED_));
                        goto detect_head;
                    }else
                    {
                        s_RemoteData.ucOffset = pMARemote->RemoteKeySet[i].ucKeySetOffset;
                        s_RemoteData.ucKeyNum = pMARemote->RemoteKeySet[i].ucKeyNum << 1;
                        s_RemoteData.ucSCheckSum = pMARemote->RemoteKeySet[i].ucSCodeCheckSum;
                        s_RemoteData.ucDCheckSum = pMARemote->RemoteKeySet[i].ucDataCheckSum;
                    } 	
                    s_RemoteData.ucRemotePreBackup = s_RemoteData.ucRemoteTemp;
                }else  //Is the second system code
                {
                    if(s_RemoteData.ucSCheckSum && (s_RemoteData.ucRemoteTemp + s_RemoteData.ucRemotePreBackup) != s_RemoteData.ucSCheckSum)
                    {
                        tdClearValBit(s_ucRemoteFlag, (_RF_MA_TRANSLATE_|_RF_MA_STARTED_));
                        goto detect_head;
                    }		
                }
                s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;  
                s_RemoteData.ucRemoteTemp = 0;
                tdClearValBit(s_ucRemoteFlag, _RF_MA_SYSTEMCODE_);
            }
            return;
        }else
        {
            //if the code is data code.
            if(s_RemoteData.ucRemoteShift == 0x40)
            {
                if(!tdTestValBitTrue(s_ucRemoteFlag, _RF_MA_CONVERT_))   //Is the first data code
                {
                    if(pMARemote->System_Code_Num == 0)  /*the protocol hasn't system code*/
                    {
                        s_RemoteData.ucOffset = pMARemote->RemoteKeySet[0].ucKeySetOffset;
                        s_RemoteData.ucKeyNum = pMARemote->RemoteKeySet[0].ucKeyNum << 1;
                        s_RemoteData.ucSCheckSum = pMARemote->RemoteKeySet[0].ucSCodeCheckSum;
                        s_RemoteData.ucDCheckSum = pMARemote->RemoteKeySet[0].ucDataCheckSum;	
                    }
                    s_RemoteData.ucRemoteBackup = s_RemoteData.ucRemoteTemp;
                    tdSetValBit(s_ucRemoteFlag, _RF_MA_SYSTEMCODE_);
                    tdSetValBit(s_ucRemoteFlag, _RF_MA_CONVERT_);
                    s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START;
                    s_RemoteData.ucRemoteTemp = 0;
                }else  //Is the second data code
                {
                    if(s_RemoteData.ucDCheckSum && (s_RemoteData.ucRemoteBackup + s_RemoteData.ucRemoteTemp) == s_RemoteData.ucDCheckSum)
                    {
                        ucIndex = 0; 
                        while ((*((RPByte)pMARemote + s_RemoteData.ucOffset + ucIndex) != (s_RemoteData.ucRemoteBackup & 0x7F)) && (ucIndex < s_RemoteData.ucKeyNum))
                        {
                            ucIndex += 2;
                        }
                        if(ucIndex < s_RemoteData.ucKeyNum)
                        {
                            s_RemoteData.ucRemoteCode = *((RPByte)pMARemote + s_RemoteData.ucOffset + ucIndex + 1);   	//set repeat data.
							if (s_RemoteData.ucRemoteCode == s_RemoteData.ucRemoteLastCode)
							{
								if (t_RemoteData.wCount < t_RemoteData.wRepeatDelay)
								{
					                tdAddVirtualKey(s_RemoteData.ucRemoteCode /*| _VK_STATUS_DOWN_*/);
									t_RemoteData.wCount += t_RemoteData.wRepeatDelay;
								}
							}
							else
							{
						        tdAddVirtualKey(s_RemoteData.ucRemoteCode);
								t_RemoteData.wCount = t_RemoteData.wFirstDelay + t_RemoteData.wRepeatDelay;
							}

							s_RemoteData.ucRemoteLastCode = s_RemoteData.ucRemoteCode;
							s_RemoteData.ucRemoteCode = 0;
                        } 
                    }
                    tdClearValBit(s_ucRemoteFlag, (_RF_MA_TRANSLATE_|_RF_MA_STARTED_));		
		        }
	        }    
	        return;
	    }
    }
detect_head:
     if((pMARemote->Remote_Code_Sync_Min <= ucRemoteCode) && (ucRemoteCode <= pMARemote->Remote_Code_Sync_Max))   //sync code
     {
         //started parsing.
         tdSetValBit(s_ucRemoteFlag, _RF_MA_STARTED_);
          
         //set the initial value of shifing.
         s_RemoteData.ucRemoteShift = REMOTE_SHIFT_START; 
         s_RemoteData.ucRemoteTemp = 0x00;
         
         //set if the system code is needed!	
         if (pMARemote->System_Code_Num)
         {
             tdSetValBit(s_ucRemoteFlag, _RF_MA_SYSTEMCODE_);
         }else
         {
             tdClearValBit(s_ucRemoteFlag, _RF_MA_SYSTEMCODE_);
         }	
         tdClearValBit(s_ucRemoteFlag, (_RF_MA_CONVERT_));
     }else 
     {
         //if error remote code,do not translate.
         tdClearValBit(s_ucRemoteFlag, (_RF_MA_CONVERT_|_RF_MA_STARTED_));
     }	
}

Code RemoteControllerDriver f_IRMADriver = 
{
    tdIRMA1msTimer, tdIRMAService
};

⌨️ 快捷键说明

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