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

📄 tirsharp.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:
 *  20/01/2005     Created by Lewis 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;
static Byte RemoteCodeSaved = 0;
static Dword dwRemoteShift = REMOTE_SHIFT_START; /*used to count shift times and generate s_RemoteData.ucRemoteTemp*/
static Dword dwKeyCode = 0;
/*the following two global variables are used by remote routines*/
static Void tdRemoteCodeDetect(Byte ucRemoteCode);

static Gdata struct tagRemoteData
{
    Dword dwRemoteTemp;      /*store the temporary value of receiving word*/
    Dword dwFirstCode;
    Byte  ucPreviousCountVal; /*timer count value of last time*/
    Byte  ucRemoteCode;       /*the key code converted from receiving code*/
    Byte  ucOffset;
    Byte  ucKeyNum;
} s_RemoteData;

/*******************************1ms counter***********************************/
/*****************************************************************************/

static Void tdIRSHARP1msTimer(Void)
{
    if (t_RemoteData.wCount == t_RemoteData.wFirstDelay)
    {
        t_RemoteData.wCount = t_RemoteData.wFirstDelay - 1;
        tdAddVirtualKey(s_RemoteData.ucRemoteCode);
        tdClearValBit(s_ucRemoteFlag, _RF_SHARP_REPEAT_);
    }
    else if (t_RemoteData.wCount) 
    {
        t_RemoteData.wCount--;
        if (t_RemoteData.wCount == 0)
        {  
            if (tdTestValBitTrue(s_ucRemoteFlag, _RF_SHARP_REPEAT_))
            {
                t_RemoteData.wCount = t_RemoteData.wRepeatDelay - 1;
                tdAddVirtualKey(s_RemoteData.ucRemoteCode /*| _VK_STATUS_DOWN_*/);
                tdClearValBit(s_ucRemoteFlag, _RF_SHARP_REPEAT_);
            }
        }
    }
    return;
}

/*******************************get interval time*****************************/
/*****************************************************************************/

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

/******************************interrupt service******************************/
/*****************************************************************************/

static Void tdIRSHARPService(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
*******************************************************************/
 
 //Defined for SHARP Remote Protocol.

 //Byte SharpRecord[256];
 //Byte SharpNumber=0;
static Void tdRemoteCodeDetect(Byte ucRemoteCode)
{

    IByte ucIndex;
    IByte i;
    IWord CurrentSystemCode;
    
    //get "1" and "0"           
    if ((pSHARPRemote->Remote_Code_0_Min <= ucRemoteCode) && (ucRemoteCode <= pSHARPRemote->Remote_Code_0_Max)) /*code 0*/
    {
        dwRemoteShift <<= 2;
    } else if (pSHARPRemote->Remote_Code_1_Min <= ucRemoteCode && (ucRemoteCode <= pSHARPRemote->Remote_Code_1_Max))   /*code 1*/
    {
        s_RemoteData.dwRemoteTemp += dwRemoteShift;
        dwRemoteShift <<= 2; 
    } else if (pSHARPRemote->Remote_Code_1_Max <= ucRemoteCode)
    {   // not 0 and not 1
        s_RemoteData.dwRemoteTemp += dwRemoteShift + dwRemoteShift * 2;
        dwRemoteShift <<= 2; 
    }

    if (dwRemoteShift == 0)
    {
        if (s_ucRemoteFlag & _IR_SHARP_FLAG_FIRSTCODE_)
        {
            //Check system code
            for (i = 0; i < pSHARPRemote->System_Code_Num; i++)
            {
                CurrentSystemCode = tdGetWord(*(RPWord)&pSHARPRemote->RemoteKeySet[i].ucSystemCode_H);
                if (((Word)(s_RemoteData.dwFirstCode & 0xFFC) == CurrentSystemCode) && ((Word)(s_RemoteData.dwRemoteTemp & 0xFFC) == CurrentSystemCode))
                    break;
            }
            
            if (i < pSHARPRemote->System_Code_Num)   // header matches
            {
                //Get keynumber and offset in structure
                s_RemoteData.ucKeyNum = pSHARPRemote->RemoteKeySet[i].ucKeyNum * 3;
		        s_RemoteData.ucOffset = pSHARPRemote->RemoteKeySet[i].ucKeySetOffset;
                
                //Analyze received data
                if (((s_RemoteData.dwRemoteTemp + s_RemoteData.dwFirstCode) & 0xFFFFF000) == 0x55555000) // reverse bit matches
                {
                    Dword dwKeyCode;
                    //Get virtual value
                    if ((s_RemoteData.dwFirstCode & 0xC0000000) == 0)
                        dwKeyCode = s_RemoteData.dwFirstCode;
                    else
                        dwKeyCode = s_RemoteData.dwRemoteTemp;

                    ucIndex = 0;
                    while((tdGetWord(*(RPWord)((RPByte)pSHARPRemote + s_RemoteData.ucOffset + ucIndex)) \
                           != (Word)(dwKeyCode >> 12))&& (ucIndex < s_RemoteData.ucKeyNum))
                    {
                        ucIndex += 3;
                    }

                    if (ucIndex < s_RemoteData.ucKeyNum)
                    {
                        s_RemoteData.ucRemoteCode = *((RPByte)pSHARPRemote + s_RemoteData.ucOffset + ucIndex + 2);      /*set repeat data*/
                    }
                    else
                        goto NextBit;
                                      
                    // add flag here    
                    if (s_RemoteData.ucRemoteCode != RemoteCodeSaved)
                    {
                        t_RemoteData.wCount = t_RemoteData.wFirstDelay;
                    }
                    else if((s_ucRemoteFlag & _IR_SHARP_FLAG_IRNewOrCorrupt_) != 0)
                    {
                        t_RemoteData.wCount = t_RemoteData.wFirstDelay;
                    }
                    else
                        s_ucRemoteFlag |= _RF_SHARP_REPEAT_;
                    
                    // reset for next code
                    RemoteCodeSaved = s_RemoteData.ucRemoteCode;
                    s_RemoteData.dwRemoteTemp = 0;
                    dwRemoteShift = REMOTE_SHIFT_START;
                    s_ucRemoteFlag &= ~_IR_SHARP_FLAG_FIRSTCODE_;
                    s_ucRemoteFlag &= ~_IR_SHARP_FLAG_IRNewOrCorrupt_;
                   
                    return;
                }
            }
           
NextBit:    // wait for another bit
            s_RemoteData.dwFirstCode >>= 2;
            s_RemoteData.dwFirstCode += (s_RemoteData.dwRemoteTemp & 3) << 30;
            s_RemoteData.dwRemoteTemp >>= 2;
            dwRemoteShift = 0x40000000;
            s_ucRemoteFlag |= _IR_SHARP_FLAG_IRNewOrCorrupt_;
        
        } else
        {
            s_ucRemoteFlag |= _IR_SHARP_FLAG_FIRSTCODE_;
            s_RemoteData.dwFirstCode = s_RemoteData.dwRemoteTemp;
            s_RemoteData.dwRemoteTemp = 0;
            dwRemoteShift = REMOTE_SHIFT_START;
        }
    }
}

//driver function structure.
Code RemoteControllerDriver f_IRSHARPDriver = 
{
    tdIRSHARP1msTimer, tdIRSHARPService
};

⌨️ 快捷键说明

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