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
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/
12 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
18 // The following are compile-time library options.
19 // If you change them, recompile the library.
20 // If DEBUG is defined, a lot of debugging output will be printed during decoding.
21 // TEST must be defined for the IRtest unittests to work. It will make some
22 // methods virtual, which will be slightly slower, which is why it is optional.
26 // Results returned from the decoder
27 class decode_results {
29 int decode_type; // NEC, SONY, RC5, UNKNOWN
30 unsigned int panasonicAddress; // This is only used for decoding Panasonic data
31 unsigned long value; // Decoded value
32 int bits; // Number of bits in decoded value
33 volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
34 int rawlen; // Number of records in rawbuf.
37 // Values for decode_type
50 // Decoded value for NEC when a repeat code is received
51 #define REPEAT 0xffffffff
53 // main class for receiving IR
58 void blink13(int blinkflag);
59 int decode(decode_results *results);
63 // These are called by decode
64 int getRClevel(decode_results *results, int *offset, int *used, int t1);
65 long decodeNEC(decode_results *results);
66 long decodeSony(decode_results *results);
67 long decodeSanyo(decode_results *results);
68 long decodeMitsubishi(decode_results *results);
69 long decodeRC5(decode_results *results);
70 long decodeRC6(decode_results *results);
71 long decodePanasonic(decode_results *results);
72 long decodeJVC(decode_results *results);
73 long decodeHash(decode_results *results);
74 int compare(unsigned int oldval, unsigned int newval);
79 // Only used for testing; can remove virtual for shorter code
81 #define VIRTUAL virtual
90 void sendNEC(unsigned long data, int nbits);
91 void sendSony(unsigned long data, int nbits);
92 // Neither Sanyo nor Mitsubishi send is implemented yet
93 // void sendSanyo(unsigned long data, int nbits);
94 // void sendMitsubishi(unsigned long data, int nbits);
95 void sendRaw(unsigned int buf[], int len, int hz);
96 void sendRC5(unsigned long data, int nbits);
97 void sendRC6(unsigned long data, int nbits);
98 void sendDISH(unsigned long data, int nbits);
99 void sendSharp(unsigned long data, int nbits);
100 void sendPanasonic(unsigned int address, unsigned long data);
101 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.
103 void enableIROut(int khz);
104 VIRTUAL void mark(int usec);
105 VIRTUAL void space(int usec);
109 // Some useful constants
111 #define USECPERTICK 50 // microseconds per clock interrupt tick
112 #define RAWBUF 100 // Length of raw duration buffer
114 // Marks tend to be 100us too long, and spaces 100us too short
115 // when received due to sensor lag.
116 #define MARK_EXCESS 100