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

📄 rc5decode.h

📁 pci 底层驱动
💻 H
字号:
//
//  File:   rc5decode.h
//  Description: definition of class RC5Decode
//
//  Created:  Wed. Jan 15, 2003
//
//
// Copyright and Disclaimer:
//
//   ---------------------------------------------------------------
//   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
//   EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//   PARTICULAR PURPOSE.
//
//   IN NO EVENT SHALL CONEXANT BE LIABLE TO ANY PARTY FOR DIRECT,
//   INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
//   INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
//   AND ITS DOCUMENTATION, EVEN IF CONEXANT HAS BEEN ADVISED OF THE
//   POSSIBILITY OF SUCH DAMAGE.
//
//   Copyright (c) 2000-2001 Conexant Systems, Inc.
//
//   All Rights Reserved.
//   ---------------------------------------------------------------
//
// Module Revision Id:
//
//

/////////////////////////////////////////////////////////////////////////////////////////
//Class RC5Decode
//
// This class takes samples, a DWORD at a time and converts them to RC5 commands.
// The incoming DWORDs should be inverted from the normal RC5 standard.
//
// The class has only one public function: submitSample.  This function returns the RC5 
// command detected, or 0xFFFFFFFF if no command was detected.  
//

#include "decode.h"
#include "ircommand.h"

//Bits per command is the length of an RC5 command in bits
#define BITS_PER_COMMAND 14

//There are two groups of bits per RC5 commands: A group of 1's followed by
// a group of 0's, or a group of zero's followed by a group of ones.
#define GROUPS_PER_BIT   2

class RC5Decode : public IR_Decode
{
    typedef enum
    {
        GROUP_OF_ZEROS = 0,
            GROUP_OF_ONES = 1
    }GROUP_TYPE;

public:
    RC5Decode(DWORD ir_command_table);

    //Submit a DWORD to be decoded
    virtual ULONG submitSample(DWORD sample);
    virtual IR_Command* getIrCommand();

protected:
    //Get a single bit from the sample
    BYTE getBit(DWORD sample, BYTE index);

    //Called when a group of 0's or 1's is found
    VOID foundGroup(GROUP_TYPE group);
    
    //Called when a long string of 1's is found
    ULONG foundEndOfCommand();

    //Called to resolve the array of groups into a command
    ULONG getCommand();

private:
    //Saves the groups of 0's and 1's found.
    GROUP_TYPE  _group_array[BITS_PER_COMMAND*GROUPS_PER_BIT];
    BYTE        _group_index;

    //The current bit we are checking for, and the number
    // of bits of that type already found
    BYTE        _current_bit;
    BYTE        _bit_count;

    ULONG       _last_command;

    IR_Command  _rc5_command;

    //The minimum and maximum number of bits in a group.
    static const BYTE _min_bits_in_group;
    static const BYTE _max_bits_in_group;
};


/////////////////////////////////////////////////////////////////////////////////////////
//RC5Decode::getBit
//
// Gets a bit from a DWORD given a bit index.
//
inline BYTE RC5Decode::getBit(DWORD sample, BYTE index)
{
    return (BYTE) ((sample >> index) & 1);
}

/////////////////////////////////////////////////////////////////////////////////////////
//RC5Decode::foundGroup
//
// Adds a group of zeros or ones to the group array if it will fit.
//
inline VOID RC5Decode::foundGroup(GROUP_TYPE group)
{
    if(_group_index < (BITS_PER_COMMAND*GROUPS_PER_BIT))
    {
        _group_array[_group_index] = group;
        _group_index++;
    }
}

⌨️ 快捷键说明

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