]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/IRremote/IRremote.h
first commit
[arduino] / books / pdummies / Libraries / IRremote / IRremote.h
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  */
14
15 #ifndef IRremote_h
16 #define IRremote_h
17
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.
23 // #define DEBUG
24 // #define TEST
25
26 // Results returned from the decoder
27 class decode_results {
28 public:
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.
35 };
36
37 // Values for decode_type
38 #define NEC 1
39 #define SONY 2
40 #define RC5 3
41 #define RC6 4
42 #define DISH 5
43 #define SHARP 6
44 #define PANASONIC 7
45 #define JVC 8
46 #define SANYO 9
47 #define MITSUBISHI 10
48 #define UNKNOWN -1
49
50 // Decoded value for NEC when a repeat code is received
51 #define REPEAT 0xffffffff
52
53 // main class for receiving IR
54 class IRrecv
55 {
56 public:
57   IRrecv(int recvpin);
58   void blink13(int blinkflag);
59   int decode(decode_results *results);
60   void enableIRIn();
61   void resume();
62 private:
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);
75
76
77 ;
78
79 // Only used for testing; can remove virtual for shorter code
80 #ifdef TEST
81 #define VIRTUAL virtual
82 #else
83 #define VIRTUAL
84 #endif
85
86 class IRsend
87 {
88 public:
89   IRsend() {}
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.
102   // private:
103   void enableIROut(int khz);
104   VIRTUAL void mark(int usec);
105   VIRTUAL void space(int usec);
106 }
107 ;
108
109 // Some useful constants
110
111 #define USECPERTICK 50  // microseconds per clock interrupt tick
112 #define RAWBUF 100 // Length of raw duration buffer
113
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
117
118 #endif