| 
1 |  | -/*  | 
2 |  | - * IRremote  | 
3 |  | - * Version 0.1 July, 2009  | 
4 |  | - * Copyright 2009 Ken Shirriff  | 
5 |  | - * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com  | 
6 |  | - *  | 
7 |  | - * Interrupt code based on NECIRrcv by Joe Knapp  | 
8 |  | - * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556  | 
9 |  | - * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/  | 
10 |  | - */  | 
11 |  | - | 
12 |  | -#ifndef IRremote_h  | 
13 |  | -#define IRremote_h  | 
14 |  | - | 
15 |  | -// The following are compile-time library options.  | 
16 |  | -// If you change them, recompile the library.  | 
17 |  | -// If DEBUG is defined, a lot of debugging output will be printed during decoding.  | 
18 |  | -// TEST must be defined for the IRtest unittests to work.  It will make some  | 
19 |  | -// methods virtual, which will be slightly slower, which is why it is optional.  | 
20 |  | -// #define DEBUG  | 
21 |  | -// #define TEST  | 
22 |  | - | 
23 |  | -// Results returned from the decoder  | 
24 |  | -class decode_results {  | 
25 |  | -public:  | 
26 |  | -  int decode_type; // NEC, SONY, RC5, UNKNOWN  | 
27 |  | -  unsigned long value; // Decoded value  | 
28 |  | -  int bits; // Number of bits in decoded value  | 
29 |  | -  volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks  | 
30 |  | -  int rawlen; // Number of records in rawbuf.  | 
31 |  | -};  | 
32 |  | - | 
33 |  | -// Values for decode_type  | 
34 |  | -#define NEC 1  | 
35 |  | -#define SONY 2  | 
36 |  | -#define RC5 3  | 
37 |  | -#define RC6 4  | 
38 |  | -#define DISH 5  | 
39 |  | -#define SHARP 6  | 
40 |  | -#define UNKNOWN -1  | 
41 |  | - | 
42 |  | -// Decoded value for NEC when a repeat code is received  | 
43 |  | -#define REPEAT 0xffffffff  | 
44 |  | - | 
45 |  | -// main class for receiving IR  | 
46 |  | -class IRrecv  | 
47 |  | -{  | 
48 |  | -public:  | 
49 |  | -  IRrecv(int recvpin);  | 
50 |  | -  void blink13(int blinkflag);  | 
51 |  | -  int decode(decode_results *results);  | 
52 |  | -  void enableIRIn();  | 
53 |  | -  void resume();  | 
54 |  | -private:  | 
55 |  | -  // These are called by decode  | 
56 |  | -  int getRClevel(decode_results *results, int *offset, int *used, int t1);  | 
57 |  | -  long decodeNEC(decode_results *results);  | 
58 |  | -  long decodeSony(decode_results *results);  | 
59 |  | -  long decodeRC5(decode_results *results);  | 
60 |  | -  long decodeRC6(decode_results *results);  | 
61 |  | -  long decodeHash(decode_results *results);  | 
62 |  | -  int compare(unsigned int oldval, unsigned int newval);  | 
63 |  | - | 
64 |  | -}   | 
65 |  | -;  | 
66 |  | - | 
67 |  | -// Only used for testing; can remove virtual for shorter code  | 
68 |  | -#ifdef TEST  | 
69 |  | -#define VIRTUAL virtual  | 
70 |  | -#else  | 
71 |  | -#define VIRTUAL  | 
72 |  | -#endif  | 
73 |  | - | 
74 |  | -class IRsend  | 
75 |  | -{  | 
76 |  | -public:  | 
77 |  | -  IRsend() {}  | 
78 |  | -  void sendNEC(unsigned long data, int nbits);  | 
79 |  | -  void sendSony(unsigned long data, int nbits);  | 
80 |  | -  void sendRaw(unsigned int buf[], int len, int hz);  | 
81 |  | -  void sendRC5(unsigned long data, int nbits);  | 
82 |  | -  void sendRC6(unsigned long data, int nbits);  | 
83 |  | -  void sendDISH(unsigned long data, int nbits);  | 
84 |  | -  void sendSharp(unsigned long data, int nbits);  | 
85 |  | -  // private:  | 
86 |  | -  void enableIROut(int khz);  | 
87 |  | -  VIRTUAL void mark(int usec);  | 
88 |  | -  VIRTUAL void space(int usec);  | 
89 |  | -}  | 
90 |  | -;  | 
91 |  | - | 
92 |  | -// Some useful constants  | 
93 |  | - | 
94 |  | -#define USECPERTICK 50  // microseconds per clock interrupt tick  | 
95 |  | -#define RAWBUF 76 // Length of raw duration buffer  | 
96 |  | - | 
97 |  | -// Marks tend to be 100us too long, and spaces 100us too short  | 
98 |  | -// when received due to sensor lag.  | 
99 |  | -#define MARK_EXCESS 100  | 
100 |  | - | 
101 |  | -#endif  | 
 | 1 | +/*  | 
 | 2 | + * IRremote  | 
 | 3 | + * Version 0.1 July, 2009  | 
 | 4 | + * Copyright 2009 Ken Shirriff  | 
 | 5 | + * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com  | 
 | 6 | + *  | 
 | 7 | + * Interrupt code based on NECIRrcv by Joe Knapp  | 
 | 8 | + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556  | 
 | 9 | + * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/  | 
 | 10 | + */  | 
 | 11 | + | 
 | 12 | +#ifndef IRremote_h  | 
 | 13 | +#define IRremote_h  | 
 | 14 | + | 
 | 15 | +// The following are compile-time library options.  | 
 | 16 | +// If you change them, recompile the library.  | 
 | 17 | +// If DEBUG is defined, a lot of debugging output will be printed during decoding.  | 
 | 18 | +// TEST must be defined for the IRtest unittests to work.  It will make some  | 
 | 19 | +// methods virtual, which will be slightly slower, which is why it is optional.  | 
 | 20 | +// #define DEBUG  | 
 | 21 | +// #define TEST  | 
 | 22 | + | 
 | 23 | +// Results returned from the decoder  | 
 | 24 | +class decode_results {  | 
 | 25 | +public:  | 
 | 26 | +  int decode_type; // NEC, SONY, RC5, UNKNOWN  | 
 | 27 | +  unsigned long value; // Decoded value  | 
 | 28 | +  int bits; // Number of bits in decoded value  | 
 | 29 | +  volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks  | 
 | 30 | +  int rawlen; // Number of records in rawbuf.  | 
 | 31 | +};  | 
 | 32 | + | 
 | 33 | +// Values for decode_type  | 
 | 34 | +#define NEC 1  | 
 | 35 | +#define SONY 2  | 
 | 36 | +#define RC5 3  | 
 | 37 | +#define RC6 4  | 
 | 38 | +#define DISH 5  | 
 | 39 | +#define SHARP 6  | 
 | 40 | +#define UNKNOWN -1  | 
 | 41 | + | 
 | 42 | +// Decoded value for NEC when a repeat code is received  | 
 | 43 | +#define REPEAT 0xffffffff  | 
 | 44 | + | 
 | 45 | +// main class for receiving IR  | 
 | 46 | +class IRrecv  | 
 | 47 | +{  | 
 | 48 | +public:  | 
 | 49 | +  IRrecv(int recvpin);  | 
 | 50 | +  void blink13(int blinkflag);  | 
 | 51 | +  int decode(decode_results *results);  | 
 | 52 | +  void enableIRIn();  | 
 | 53 | +  void resume();  | 
 | 54 | +private:  | 
 | 55 | +  // These are called by decode  | 
 | 56 | +  int getRClevel(decode_results *results, int *offset, int *used, int t1);  | 
 | 57 | +  long decodeNEC(decode_results *results);  | 
 | 58 | +  long decodeSony(decode_results *results);  | 
 | 59 | +  long decodeRC5(decode_results *results);  | 
 | 60 | +  long decodeRC6(decode_results *results);  | 
 | 61 | +  long decodeHash(decode_results *results);  | 
 | 62 | +  int compare(unsigned int oldval, unsigned int newval);  | 
 | 63 | + | 
 | 64 | +}   | 
 | 65 | +;  | 
 | 66 | + | 
 | 67 | +// Only used for testing; can remove virtual for shorter code  | 
 | 68 | +#ifdef TEST  | 
 | 69 | +#define VIRTUAL virtual  | 
 | 70 | +#else  | 
 | 71 | +#define VIRTUAL  | 
 | 72 | +#endif  | 
 | 73 | + | 
 | 74 | +class IRsend  | 
 | 75 | +{  | 
 | 76 | +public:  | 
 | 77 | +  IRsend() {}  | 
 | 78 | +  void sendNEC(unsigned long data, int nbits);  | 
 | 79 | +  void sendSony(unsigned long data, int nbits);  | 
 | 80 | +  void sendRaw(unsigned int buf[], int len, int hz);  | 
 | 81 | +  void sendRC5(unsigned long data, int nbits);  | 
 | 82 | +  void sendRC6(unsigned long data, int nbits);  | 
 | 83 | +  void sendDISH(unsigned long data, int nbits);  | 
 | 84 | +  void sendSharp(unsigned long data, int nbits);  | 
 | 85 | +  // private:  | 
 | 86 | +  void enableIROut(int khz);  | 
 | 87 | +  VIRTUAL void mark(int usec);  | 
 | 88 | +  VIRTUAL void space(int usec);  | 
 | 89 | +}  | 
 | 90 | +;  | 
 | 91 | + | 
 | 92 | +// Some useful constants  | 
 | 93 | + | 
 | 94 | +#define USECPERTICK 50  // microseconds per clock interrupt tick  | 
 | 95 | +#define RAWBUF 76 // Length of raw duration buffer  | 
 | 96 | + | 
 | 97 | +// Marks tend to be 100us too long, and spaces 100us too short  | 
 | 98 | +// when received due to sensor lag.  | 
 | 99 | +#define MARK_EXCESS 100  | 
 | 100 | + | 
 | 101 | +#endif  | 
0 commit comments