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

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

Setup project structure

File size: 4.5 KB
Line 
1/* IRLib_P10_DirecTV.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/*
6 * This module implements the protocol used by DirecTV. It comes in six different
7 * varieties. It uses three different frequencies 38, 40, or 57 kHz. It also
8 * uses two different varieties lead out times either 9000us or 30000us. The
9 * default is 38 kHz and 30000us. Because the decoder does not usually detect
10 * frequency and does not record the lead out time, you may have difficulty
11 * determining which variety your device uses.
12 *
13 * According to http://www.hifi-remote.com/johnsfine/DecodeIR.html#DirecTV
14 * The IRP notation for this protocol is:
15 *  {38k,600,msb}<1,-1|1,-2|2,-1|2,-2>(5,(5,-2,D:4,F:8,C:4,1,-50)+)
16 *   {C=7*(F:2:6)+5*(F:2:4)+3*(F:2:2)+(F:2)}
17 * Unlike most protocols which use a fixed length mark and a variable length or
18 * a variable length mark a fixed length space, this protocol varies both the
19 * mark and the space. The stream is still a series of marks and spaces but the
20 * length of either of those denotes a one or zero. A length of 1200us=logical 1
21 * and length 600us=logical 0. So whereas the normal protocol requires both a mark
22 * and a space to encode a single bit, this protocol encodes one bit in each mark
23 * and space.  It also makes changes to the length of the header mark to devote
24 * repeat codes. The first header mark should be 6000us but repeat codes should
25 * only be 3000us. The decode routine sets "address=true" if it is a first
26 * and "address=false" otherwise.
27 */
28
29#ifndef IRLIB_PROTOCOL_10_H
30#define IRLIB_PROTOCOL_10_H
31/* When used with IRLibCombo.h the data2 value is a flag for repeat frame.
32 * You can also optionally change the frequency. To change the lead out
33 * time after you have created the instance of your sending object such as
34 *    IRsend My_Send;
35 * you can change the leadout with
36 *    My_Send.longLeadOut= false;
37 * The default value is true.
38 */
39#define IR_SEND_PROTOCOL_10             case 10: IRsendDirecTV::send(data,data2,khz); break;
40#define IR_DECODE_PROTOCOL_10   if(IRdecodeDirecTV::decode()) return true;
41#ifdef IRLIB_HAVE_COMBO
42        #define PV_IR_DECODE_PROTOCOL_10 ,public virtual IRdecodeDirecTV
43        #define PV_IR_SEND_PROTOCOL_10   ,public virtual IRsendDirecTV
44#else
45        #define PV_IR_DECODE_PROTOCOL_10  public virtual IRdecodeDirecTV
46        #define PV_IR_SEND_PROTOCOL_10    public virtual IRsendDirecTV
47#endif
48
49#ifdef IRLIBSENDBASE_H
50class IRsendDirecTV: public virtual IRsendBase {
51  public:
52    IRsendDirecTV(void):longLeadOut(true){};
53    void send(uint32_t data, bool first=true, uint8_t khz=38) {
54      enableIROut(khz);
55      if(first) mark(6000); else mark(3000); 
56      space(1200);//Send header
57      for (uint8_t i = 0; i < 8; i++) {
58        if (data & 0x8000) mark(1200); else mark(600); 
59        data <<= 1;
60        if (data & 0x8000) space(1200); else space(600);
61        data <<= 1;
62      };
63      mark(600); 
64      space(longLeadOut?50*600:15*600);
65    };
66    bool longLeadOut;
67};
68#endif  //IRLIBSENDBASE_H
69
70#ifdef IRLIBDECODEBASE_H
71class IRdecodeDirecTV: public virtual IRdecodeBase {
72  public:
73    bool decode(void) {
74      resetDecoder();//This used to be in the receiver getResults.
75      IRLIB_ATTEMPT_MESSAGE(F("DirecTV"));
76      if (recvGlobal.decodeLength != 20) return RAW_COUNT_ERROR;
77      //We use the "address" value as a repeat flag
78      if(!ignoreHeader) {
79        if (MATCH(recvGlobal.decodeBuffer[1],3000)) {
80          address=false;
81        } else {
82          if (!MATCH(recvGlobal.decodeBuffer[1],6000)) {
83            return HEADER_MARK_ERROR(6000);
84          } else {
85            address=true;
86          }
87        }
88      }
89      if (!MATCH(recvGlobal.decodeBuffer[2],1200)) return HEADER_SPACE_ERROR(1200);
90      uint32_t data=0; offset=3; 
91      while (offset < 18) {
92        if (MATCH(recvGlobal.decodeBuffer[offset],1200)) {
93          data = (data << 1) | 1;
94        } else {
95          if (MATCH(recvGlobal.decodeBuffer[offset],600)) {
96            data <<= 1;
97          } else {
98            return DATA_MARK_ERROR(1200);
99          }
100        }
101        offset++;
102        if (MATCH(recvGlobal.decodeBuffer[offset],1200)) {
103          data = (data << 1) | 1;
104        } else {
105          if (MATCH (recvGlobal.decodeBuffer[offset],600)) {
106            data <<= 1;
107          } else {
108            return DATA_SPACE_ERROR(1200);
109          }
110        }
111        offset++;
112      }
113      bits = 16;
114      value = data;
115      protocolNum=DIRECTV;
116      return true;
117    }
118};
119#endif //IRLIBDECODEBASE_H
120
121#define IRLIB_HAVE_COMBO
122
123#endif //IRLIB_PROTOCOL_10_H
Note: See TracBrowser for help on using the repository browser.