source: trunk/Arduino/libraries/Adafruit_Circuit_Playground/utility/IRLib_P11_RCMM.h

Last change on this file was 3, checked in by markus, 7 years ago

Setup project structure

File size: 5.1 KB
Line 
1/* IRLib_P11_RCMM.h
2 * Part of IRLib Library for Arduino receiving, decoding, and sending
3 * infrared signals. See COPYRIGHT.txt and LICENSE.txt for more information.
4 */
5/* This module implements the Phillips RC-MM also known as Nokia Protocol. Is used by
6 * AT&T U-Verse cable boxes. There are three different varieties that are 12, 24, or 32 bits.
7 * According to http://www.hifi-remote.com/johnsfine/DecodeIR.html#Nokia
8 * The IRP notation for these protocols are:
9 * Nokia 12 bit: {36k,msb}<164,-276|164,-445|164,-614|164,-783>(412,-276,D:4,F:8,164,-???)+
10 * Nokia 24-bit: {36k,msb}<164,-276|164,-445|164,-614|164,-783>(412,-276,D:8,S:8,F:8,164,-???)+
11 * Nokia 32 bit: {36k,msb}<164,-276|164,-445|164,-614|164,-783>(412,-276,D:8,S:8,T:1X:7,F:8,164,^100m)+
12 * Slightly different timing values are documented at
13 * http://www.sbprojects.com/knowledge/ir/rcmm.php
14 * We will use the timing from the latter reference.
15 * Unlike most protocols which defined sequences for a logical "0" and "1", this protocol
16 * encodes 2 bits per pulse. Therefore it encodes a logical "2" and "3" as well.
17 * The length of the mark is constant but the length of the space denotes the bit values.
18 * Note the 32-bit version uses a toggle bit of 0x8000 and as usual it is up to the end-user
19 * to implement it outside the library routines.
20 */
21#define RCMM_HEAD_MARK 417
22#define RCMM_DATA_MARK 167
23#define RCMM_ZERO      278
24#define RCMM_ONE       444
25#define RCMM_TWO       611
26#define RCMM_THREE     778
27
28#ifndef IRLIB_PROTOCOL_11_H
29#define IRLIB_PROTOCOL_11_H
30#define IR_SEND_PROTOCOL_11             case 11: IRsendRCMM::send(data,data2); break;//data2 is the number of bits
31#define IR_DECODE_PROTOCOL_11   if(IRdecodeRCMM::decode()) return true;
32#ifdef IRLIB_HAVE_COMBO
33        #define PV_IR_DECODE_PROTOCOL_11 ,public virtual IRdecodeRCMM
34        #define PV_IR_SEND_PROTOCOL_11   ,public virtual IRsendRCMM
35#else
36        #define PV_IR_DECODE_PROTOCOL_11  public virtual IRdecodeRCMM
37        #define PV_IR_SEND_PROTOCOL_11    public virtual IRsendRCMM
38#endif
39
40#ifdef IRLIBSENDBASE_H
41class IRsendRCMM: public virtual IRsendBase {
42  public:
43    void send(uint32_t data, uint8_t nBits= 12) {
44      if (nBits==0) nBits=12;
45      extent=0;
46      data <<= (32 - nBits);
47      nBits=nBits/2;
48      enableIROut(36);
49      mark(RCMM_HEAD_MARK); space(RCMM_ZERO);//Send header
50      for (uint8_t i = 0; i < nBits; i++) {
51        mark(RCMM_DATA_MARK);
52        switch (data & 0xC0000000UL) {//use the leftmost two bits
53          case 0x00000000UL: space(RCMM_ZERO); break;
54          case 0x40000000UL: space(RCMM_ONE); break;
55          case 0x80000000UL: space(RCMM_TWO); break;
56          case 0xC0000000UL: space(RCMM_THREE); break;
57        }
58        data <<= 2;
59      };
60      mark(RCMM_DATA_MARK); 
61      space(27778-extent);
62    };
63};
64#endif  //IRLIBSENDBASE_H
65
66#ifdef IRLIBDECODEBASE_H
67/*
68 * Normally IRLib uses a plus or minus percentage to determine if an interval matches the
69 * desired value. However this protocol uses extremely long intervals of similar length.
70 * For example using the default 25% tolerance the RCMM_TWO value 611 would be accepted for
71 * anything between 458 and 763. The low end is actually closer to RCMM_ONE value of 444
72 * and the upper range is closer to RCM_THREE value of 778. To implement this protocol
73 * we created a new match routine ABS_MATCH which allows you to specify an absolute
74 * number of microseconds of tolerance for comparison.
75 */ 
76#define RCMM_TOLERANCE 80
77class IRdecodeRCMM: public virtual IRdecodeBase {
78  public:
79    bool decode(void) {
80      resetDecoder();//This used to be in the receiver getResults.
81      IRLIB_ATTEMPT_MESSAGE(F("RCMM"));
82      if ( (recvGlobal.decodeLength!=(12+4)) && (recvGlobal.decodeLength!=(24+4)) && (recvGlobal.decodeLength!=(32+4)) ) return RAW_COUNT_ERROR;
83      if (!ignoreHeader) if (!MATCH(recvGlobal.decodeBuffer[1],RCMM_HEAD_MARK)) return HEADER_MARK_ERROR(RCMM_HEAD_MARK);
84      if (!MATCH(recvGlobal.decodeBuffer[2],RCMM_ZERO)) return HEADER_SPACE_ERROR(RCMM_ZERO);
85      offset=3; uint32_t data=0;
86      while (offset < (recvGlobal.decodeLength-1)) {
87        if (!ABS_MATCH(recvGlobal.decodeBuffer[offset],RCMM_DATA_MARK,RCMM_TOLERANCE)) return DATA_MARK_ERROR(RCMM_DATA_MARK);
88        offset++;
89        if (ABS_MATCH(recvGlobal.decodeBuffer[offset],RCMM_ZERO, RCMM_TOLERANCE) ) { //Logical "0"
90          data <<= 2;
91        } 
92        else if (ABS_MATCH(recvGlobal.decodeBuffer[offset],RCMM_ONE, RCMM_TOLERANCE) ) { //Logical "1"
93          data = (data<<2) + 1;
94        } 
95        else if (ABS_MATCH(recvGlobal.decodeBuffer[offset],RCMM_TWO, RCMM_TOLERANCE) ) { //Logical "2"
96          data = (data<<2) + 2;
97        } 
98        else if (ABS_MATCH(recvGlobal.decodeBuffer[offset],RCMM_THREE, RCMM_TOLERANCE) ) { //Logical "3"
99          data = (data<<2) + 3;
100        } 
101        else return DATA_SPACE_ERROR(RCMM_ZERO);
102        offset++;
103      }
104      if (!MATCH(recvGlobal.decodeBuffer[offset],RCMM_DATA_MARK))  return DATA_MARK_ERROR(RCMM_DATA_MARK);
105      bits = recvGlobal.decodeLength-4;//set bit length
106      value = data;//put remaining bits in value
107      protocolNum=RCMM;
108      return true;
109    }
110};
111#endif //IRLIBDECODEBASE_H
112
113#define IRLIB_HAVE_COMBO
114
115#endif //IRLIB_PROTOCOL_11_H
Note: See TracBrowser for help on using the repository browser.