155
|
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 * Edited by Mitra to add new controller SANYO
|
|
7 *
|
|
8 * Interrupt code based on NECIRrcv by Joe Knapp
|
|
9 * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
|
|
10 * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
|
|
11 *
|
|
12 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
|
|
13 * LG added by Darryl Smith (based on the JVC protocol)
|
|
14 */
|
|
15
|
|
16 #ifndef IRremote_h
|
|
17 #define IRremote_h
|
|
18
|
|
19 // The following are compile-time library options.
|
|
20 // If you change them, recompile the library.
|
|
21 // If DEBUG is defined, a lot of debugging output will be printed during decoding.
|
|
22 // TEST must be defined for the IRtest unittests to work. It will make some
|
|
23 // methods virtual, which will be slightly slower, which is why it is optional.
|
|
24 // #define DEBUG
|
|
25 // #define TEST
|
|
26
|
|
27 // Results returned from the decoder
|
|
28 class decode_results {
|
|
29 public:
|
|
30 int decode_type; // NEC, SONY, RC5, UNKNOWN
|
|
31 union { // This is used for decoding Panasonic and Sharp data
|
|
32 unsigned int panasonicAddress;
|
|
33 unsigned int sharpAddress;
|
|
34 };
|
|
35 unsigned long value; // Decoded value
|
|
36 int bits; // Number of bits in decoded value
|
|
37 volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
|
|
38 int rawlen; // Number of records in rawbuf.
|
|
39 };
|
|
40
|
|
41 // Values for decode_type
|
|
42 #define NEC 1
|
|
43 #define SONY 2
|
|
44 #define RC5 3
|
|
45 #define RC6 4
|
|
46 #define DISH 5
|
|
47 #define SHARP 6
|
|
48 #define PANASONIC 7
|
|
49 #define JVC 8
|
|
50 #define SANYO 9
|
|
51 #define MITSUBISHI 10
|
|
52 #define SAMSUNG 11
|
|
53 #define LG 12
|
|
54 #define UNKNOWN -1
|
|
55
|
|
56 // Decoded value for NEC when a repeat code is received
|
|
57 #define REPEAT 0xffffffff
|
|
58
|
|
59 // main class for receiving IR
|
|
60 class IRrecv
|
|
61 {
|
|
62 public:
|
|
63 IRrecv(int recvpin);
|
|
64 void blink13(int blinkflag);
|
|
65 int decode(decode_results *results);
|
|
66 void enableIRIn();
|
|
67 void resume();
|
|
68 private:
|
|
69 // These are called by decode
|
|
70 int getRClevel(decode_results *results, int *offset, int *used, int t1);
|
|
71 long decodeNEC(decode_results *results);
|
|
72 long decodeSony(decode_results *results);
|
|
73 long decodeSanyo(decode_results *results);
|
|
74 long decodeMitsubishi(decode_results *results);
|
|
75 long decodeRC5(decode_results *results);
|
|
76 long decodeRC6(decode_results *results);
|
|
77 long decodePanasonic(decode_results *results);
|
|
78 long decodeLG(decode_results *results);
|
|
79 long decodeJVC(decode_results *results);
|
|
80 long decodeSAMSUNG(decode_results *results);
|
|
81 long decodeHash(decode_results *results);
|
|
82 int compare(unsigned int oldval, unsigned int newval);
|
|
83
|
|
84 }
|
|
85 ;
|
|
86
|
|
87 // Only used for testing; can remove virtual for shorter code
|
|
88 #ifdef TEST
|
|
89 #define VIRTUAL virtual
|
|
90 #else
|
|
91 #define VIRTUAL
|
|
92 #endif
|
|
93
|
|
94 class IRsend
|
|
95 {
|
|
96 public:
|
|
97 IRsend() {}
|
|
98 void sendNEC(unsigned long data, int nbits);
|
|
99 void sendSony(unsigned long data, int nbits);
|
|
100 // Neither Sanyo nor Mitsubishi send is implemented yet
|
|
101 // void sendSanyo(unsigned long data, int nbits);
|
|
102 // void sendMitsubishi(unsigned long data, int nbits);
|
|
103 void sendRaw(unsigned int buf[], int len, int hz);
|
|
104 void sendRC5(unsigned long data, int nbits);
|
|
105 void sendRC6(unsigned long data, int nbits);
|
|
106 void sendDISH(unsigned long data, int nbits);
|
|
107 void sendSharp(unsigned int address, unsigned int command);
|
|
108 void sendSharpRaw(unsigned long data, int nbits);
|
|
109 void sendPanasonic(unsigned int address, unsigned long data);
|
|
110 void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does.
|
|
111 // private:
|
|
112 void sendSAMSUNG(unsigned long data, int nbits);
|
|
113 void enableIROut(int khz);
|
|
114 VIRTUAL void mark(int usec);
|
|
115 VIRTUAL void space(int usec);
|
|
116 }
|
|
117 ;
|
|
118
|
|
119 // Some useful constants
|
|
120
|
|
121 #define USECPERTICK 50 // microseconds per clock interrupt tick
|
|
122 #define RAWBUF 100 // Length of raw duration buffer
|
|
123
|
|
124 // Marks tend to be 100us too long, and spaces 100us too short
|
|
125 // when received due to sensor lag.
|
|
126 #define MARK_EXCESS 100
|
|
127
|
|
128 #endif
|