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

📄 irbutton.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Reurns:                                                                  */
/*  TRUE if a report completed decode with the current event.               */
/****************************************************************************/

static BOOL necEvent( UIREP *report, uint08 port, uint16 event )
{
    IRSTATE *pss = &issN[port];                      /* pointer to IR state */
    uint08   eventDesc;                             /* IR event description */
    
    if( port > 1 )                                  /* limit port to 0 or 1 */
        return FALSE;
    
                        /****************************************************/
                        /* Determine if this is an IR message sync point.   */
                        /*                                                  */
                        /* Start/end of an IR message is indicated by the   */
                        /* IRMSGSYNC constant value.                        */
                        /****************************************************/
                        
    if( event == IRMSGSYNC )                               /* if sync point */
    {
        pss -> fsmState = MS_IDLE;       /* initialize finite state machine */
        
        return FALSE;
    }
                        /****************************************************/
                        /* Generate event description.                      */
                        /*                                                  */
                        /* Width assignment is made if the reported width   */
                        /* is within 25% of nominal.                        */
                        /****************************************************/
    
    eventDesc = ( 0x8000 == ( 0x8000 & event ));          /* high/low state */
    
    event &= 0x7fff;                  /* mask off high/low state indication */
    
    if( ABS( event - WIDTH_ZBIT ) <= ( WIDTH_ZBIT >> 2 ))
        eventDesc |= LO_ZBIT;
        
    else if( ABS( event - WIDTH_OBIT ) <= ( WIDTH_OBIT >> 2 )) 
        eventDesc |= LO_OBIT;
        
    else if( ABS( event - WIDTH_SYN1 ) <= ( WIDTH_SYN1 >> 2 )) 
        eventDesc |= LO_SYN1;                                 /* full-width */
        
    else if( ABS( event - WIDTH_SYN2 ) <= ( WIDTH_SYN2 >> 2 )) 
        eventDesc |= LO_SYN2;                                 /* full-width */
        
    else
        eventDesc |= LO_UNEX;                           /* unexpected width */
    
                        /****************************************************/
                        /* Execute the state machine.                       */
                        /****************************************************/
    
    switch( pss -> fsmState | eventDesc )
    {
        case MS_IDLE | HI_SYN1:
            pss -> fsmState = MS_SYNC;
            pss -> bitCount = 0;                              
            break;
            
        case MS_SYNC | LO_SYN2:
            pss -> fsmState = MS_SBIT;
            break;
            
        case MS_SBIT | HI_ZBIT:
            pss -> fsmState = MS_DBIT;
            break;
            
        case MS_DBIT | LO_ZBIT:
            pss -> fsmState = MS_SBIT;
            pss -> bitRegister = ( pss -> bitRegister >> 1 );          
            pss -> bitCount++; 
            break;
            
        case MS_DBIT | LO_OBIT:
            pss -> fsmState = MS_SBIT;
            pss -> bitRegister = ( pss -> bitRegister >> 1 ) | 0x80000000; 
            pss -> bitCount++; 
            break;
            
        default:
            pss -> fsmState = MS_IDLE;                                         
            return FALSE;
    }
                        /****************************************************/
                        /* Return report when message is complete.          */
                        /****************************************************/
    
    if( 32 == pss -> bitCount )
    {
        pss -> fsmState = MS_IDLE;
        pss -> bitCount = 0;
        
        return testCode( report, pss );
    }
            
    return FALSE;
}



/****************************************************************************/
/* Test message against expected customer code and list of valid key        */
/* functions. Fill *report and return TRUE if a valid code is found.        */
/*                                                                          */
/* Key codes are tested in bit-reversed order as received from the control. */
/****************************************************************************/

static BOOL testCode( UIREP *report, IRSTATE *pss )
{
    uint08     thisScan;                               /* current scan code */
    KCODE_ENUM thisKey;                                 /* current key code */
    uint32     timeSince;            /* time since last key report was sent */
    
    uint08 fCode1 = 
        (uint08)( pss -> bitRegister >> 16 );                   /* function */
        
    uint08 fCode2 = 
        (uint08)( pss -> bitRegister >> 24 );          /* inverted function */
    
    uint16 cCode = 
        (uint16)( pss -> bitRegister );                    /* customer code */
    
    if( cCode != customercode )            /* if not expected customer code */
        return FALSE;

    if( 0xff != ( fCode1 + fCode2 ))     /* if bit inversion does not match */
        return FALSE;
        
    if( keycount != ( thisScan = scanCode( fCode1 )))       /* if valid key */
    {
        thisKey =  keymapN[thisScan].kcode;                /* this key code */
        
        if( thisKey == pss -> keyPrior )        /* if same as last returned */
        {
            timeSince = irfunc_MsecTime() - pss -> keyTime;
            pss -> keyTime = irfunc_MsecTime(); 
            
            if( timeSince < KEYN_SEPARATE )          /* if pressed recently */
            {
                if( pss -> keyRepeat )              /* if key is repeatable */
                {
                    timeSince = irfunc_MsecTime() - pss -> keyFirstTime;
                    
                    if( timeSince > KEYN_REPDELAY )
                        return reportKey( report, pss, thisScan, thisKey );
                }
            }
            
            else                              /* same key, but not recently */
            {
                pss -> keyFirstTime = irfunc_MsecTime();
                return reportKey( report, pss, thisScan, thisKey );
            }
        }
    
        
        else                                          /* return new keycode */
        {
            pss -> keyFirstTime = irfunc_MsecTime();
            return reportKey( report, pss, thisScan, thisKey );
        }
    }
    
    return FALSE;                                       /* no key to report */
}



/****************************************************************************/
/* Report keycode.                                                          */
/****************************************************************************/

static BOOL reportKey( UIREP *report, IRSTATE *pss, uint08 thisScan, KCODE_ENUM thisKey )
{
    pss -> keyPrior  = thisKey;                                  /* keycode */
    pss -> keyRepeat = keymapN[thisScan].repflag;               /* rep flag */
    pss -> keyTime   = irfunc_MsecTime();
        
    report -> key = thisKey;                                     /* keycode */
    report -> mouse = FALSE;                               /* no mouse data */
    report -> mouse_x = 0;
    report -> mouse_y = 0;

    return TRUE;                                     /* indicate key report */
}



/****************************************************************************/
/* Scan keycode table for valid key. Return index.                          */
/****************************************************************************/

static uint08 scanCode( uint08 fCode )
{
    int x;                                                         /* index */
    
    for( x = 0; x < keycount; x++ )                        /* linear search */
        if( fCode == keymapN[x].fcode )                         /* if found */
            break;

    return x;
}

⌨️ 快捷键说明

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