IRremote
IRremote.h
Go to the documentation of this file.
1 
6 //******************************************************************************
7 // IRremote
8 // Version 2.0.1 June, 2015
9 // Copyright 2009 Ken Shirriff
10 // For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
11 // Edited by Mitra to add new controller SANYO
12 //
13 // Interrupt code based on NECIRrcv by Joe Knapp
14 // http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
15 // Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
16 //
17 // JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
18 // LG added by Darryl Smith (based on the JVC protocol)
19 // Whynter A/C ARC-110WD added by Francesco Meschia
20 //******************************************************************************
21 #ifndef IRremote_h
22 #define IRremote_h
23 
24 //------------------------------------------------------------------------------
25 // The ISR header contains several useful macros the user may wish to use
26 //
27 #include "private/IRremoteInt.h"
28 
29 //------------------------------------------------------------------------------
30 // Supported IR protocols
31 // Each protocol you include costs memory and, during decode, costs time
32 // Disable (set to 0) all the protocols you do not need/want!
33 //
34 #define DECODE_RC5 1
35 #define SEND_RC5 1
36 
37 #define DECODE_RC6 1
38 #define SEND_RC6 1
39 
40 #define DECODE_NEC 1
41 #define SEND_NEC 1
42 
43 #define DECODE_SONY 1
44 #define SEND_SONY 1
45 
46 #define DECODE_PANASONIC 1
47 #define SEND_PANASONIC 1
48 
49 #define DECODE_JVC 1
50 #define SEND_JVC 1
51 
52 #define DECODE_SAMSUNG 1
53 #define SEND_SAMSUNG 1
54 
55 #define DECODE_WHYNTER 1
56 #define SEND_WHYNTER 1
57 
58 #define DECODE_AIWA_RC_T501 1
59 #define SEND_AIWA_RC_T501 1
60 
61 #define DECODE_LG 1
62 #define SEND_LG 1
63 
64 #define DECODE_SANYO 1
65 #define SEND_SANYO 0 // NOT WRITTEN
66 
67 #define DECODE_MITSUBISHI 1
68 #define SEND_MITSUBISHI 0 // NOT WRITTEN
69 
70 #define DECODE_DISH 0 // NOT WRITTEN
71 #define SEND_DISH 1
72 
73 #define DECODE_SHARP 1
74 #define SEND_SHARP 1
75 
76 #define DECODE_SHARP_ALT 1
77 #define SEND_SHARP_ALT 1
78 
79 #define DECODE_DENON 1
80 #define SEND_DENON 1
81 
82 #define DECODE_PRONTO 0 // This function does not logically make sense
83 #define SEND_PRONTO 0 // Not tested yet
84 
85 #define DECODE_LEGO_PF 0 // NOT WRITTEN
86 #define SEND_LEGO_PF 1
87 
88 #define DECODE_BOSEWAVE 1
89 #define SEND_BOSEWAVE 1
90 
91 #define DECODE_HASH 1 // special decoder for all protocols
92 
93 //------------------------------------------------------------------------------
94 // When sending a Pronto code we request to send either the "once" code
95 // or the "repeat" code
96 // If the code requested does not exist we can request to fallback on the
97 // other code (the one we did not explicitly request)
98 //
99 // I would suggest that "fallback" will be the standard calling method
100 // The last paragraph on this page discusses the rationale of this idea:
101 // http://www.remotecentral.com/features/irdisp2.htm
102 //
103 #define PRONTO_ONCE false
104 #define PRONTO_REPEAT true
105 #define PRONTO_FALLBACK true
106 #define PRONTO_NOFALLBACK false
107 
112 typedef enum {
113  UNKNOWN = -1,
114  UNUSED = 0,
124  LG,
134 } decode_type_t;
135 
139 #define DEBUG 0
140 
141 //------------------------------------------------------------------------------
142 // Debug directives
143 //
144 #if DEBUG
145 # define DBG_PRINT(...) Serial.print(__VA_ARGS__)
146 # define DBG_PRINTLN(...) Serial.println(__VA_ARGS__)
147 #else
148 
151 # define DBG_PRINT(...) void()
152 
155 # define DBG_PRINTLN(...) void()
156 #endif
157 
158 //------------------------------------------------------------------------------
159 // Helper macro for getting a macro definition as string
160 //
161 #define STR_HELPER(x) #x
162 #define STR(x) STR_HELPER(x)
163 
164 //------------------------------------------------------------------------------
165 // Mark & Space matching functions
166 //
167 int MATCH(int measured, int desired);
168 int MATCH_MARK(int measured_ticks, int desired_us);
169 int MATCH_SPACE(int measured_ticks, int desired_us);
170 
175 public:
177  unsigned int address;
178  unsigned long value;
179  int bits;
180  volatile unsigned int *rawbuf;
181  unsigned int rawlen;
182  int overflow;
183 };
184 
188 #define REPEAT 0xFFFFFFFF
189 
193 class IRrecv {
194 public:
199  IRrecv(int recvpin);
205  IRrecv(int recvpin, int blinkpin);
206 
211  void blink13(int blinkflag);
212 
218  int decode(decode_results *results);
219 
223  void enableIRIn();
224 
228  void disableIRIn();
229 
234  bool isIdle();
235 
239  void resume();
240 
241 private:
242 #if DECODE_HASH
243  long decodeHash(decode_results *results);
244  int compare(unsigned int oldval, unsigned int newval);
245 #endif
246 
247  //......................................................................
248 #if (DECODE_RC5 || DECODE_RC6)
249 
252  int getRClevel(decode_results *results, unsigned int *offset, int *used, int t1);
253 #endif
254 #if DECODE_RC5
255 
260  bool decodeRC5(decode_results *results);
261 #endif
262 #if DECODE_RC6
263  bool decodeRC6(decode_results *results);
264 #endif
265  //......................................................................
266 #if DECODE_NEC
267  bool decodeNEC(decode_results *results);
268 #endif
269  //......................................................................
270 #if DECODE_SONY
271  bool decodeSony(decode_results *results);
272 #endif
273  //......................................................................
274 #if DECODE_PANASONIC
275  bool decodePanasonic(decode_results *results);
276 #endif
277  //......................................................................
278 #if DECODE_JVC
279  bool decodeJVC(decode_results *results);
280 #endif
281  //......................................................................
282 #if DECODE_SAMSUNG
283  bool decodeSAMSUNG(decode_results *results);
284 #endif
285  //......................................................................
286 #if DECODE_WHYNTER
287  bool decodeWhynter(decode_results *results);
288 #endif
289  //......................................................................
290 #if DECODE_AIWA_RC_T501
291  bool decodeAiwaRCT501(decode_results *results);
292 #endif
293  //......................................................................
294 #if DECODE_LG
295  bool decodeLG(decode_results *results);
296 #endif
297  //......................................................................
298 #if DECODE_SANYO
299  bool decodeSanyo(decode_results *results);
300 #endif
301  //......................................................................
302 #if DECODE_MITSUBISHI
303  bool decodeMitsubishi(decode_results *results);
304 #endif
305  //......................................................................
306 #if DECODE_DISH
307  bool decodeDish (decode_results *results) ; // NOT WRITTEN
308 #endif
309  //......................................................................
310 #if DECODE_SHARP
311  bool decodeSharp(decode_results *results); // NOT WRITTEN
312 #endif
313 #if DECODE_SHARP_ALT
314  bool decodeSharpAlt(decode_results *results);
315 #endif
316  //......................................................................
317 #if DECODE_DENON
318  bool decodeDenon(decode_results *results);
319 #endif
320  //......................................................................
321 #if DECODE_LEGO_PF
322  bool decodeLegoPowerFunctions (decode_results *results) ;
323 #endif
324  //......................................................................
325 #if DECODE_BOSEWAVE
326  bool decodeBoseWave(decode_results *results);
327 #endif
328 };
329 
333 class IRsend {
334 public:
335 #if defined(USE_SOFT_CARRIER) || defined(USE_NO_CARRIER)
336  IRsend(int pin = IR_SEND_PIN) {
337  sendPin = pin;
338  }
339 #else
340  IRsend() {
341  }
342 #endif
343 
344  void custom_delay_usec(unsigned long uSecs);
345  void enableIROut(int khz);
346  void mark(unsigned int usec);
347  void space(unsigned int usec);
348  void sendRaw(const unsigned int buf[], unsigned int len, unsigned int hz);
349  void sendRaw_P(const unsigned int buf[], unsigned int len, unsigned int hz);
350 
351  //......................................................................
352 #if SEND_RC5
353  void sendRC5(unsigned long data, int nbits);
354  void sendRC5ext(unsigned long addr, unsigned long cmd, boolean toggle);
355 #endif
356 #if SEND_RC6
357  void sendRC6(unsigned long data, int nbits);
358 #endif
359  //......................................................................
360 #if SEND_NEC
361  void sendNEC(unsigned long data, int nbits);
362 #endif
363  //......................................................................
364 #if SEND_SONY
365  void sendSony(unsigned long data, int nbits);
366 #endif
367  //......................................................................
368 #if SEND_PANASONIC
369  void sendPanasonic(unsigned int address, unsigned long data);
370 #endif
371  //......................................................................
372 #if SEND_JVC
373  // JVC does NOT repeat by sending a separate code (like NEC does).
374  // The JVC protocol repeats by skipping the header.
375  // To send a JVC repeat signal, send the original code value
376  // and set 'repeat' to true
377  void sendJVC(unsigned long data, int nbits, bool repeat);
378 #endif
379  //......................................................................
380 #if SEND_SAMSUNG
381  void sendSAMSUNG(unsigned long data, int nbits);
382 #endif
383  //......................................................................
384 #if SEND_WHYNTER
385  void sendWhynter(unsigned long data, int nbits);
386 #endif
387  //......................................................................
388 #if SEND_AIWA_RC_T501
389  void sendAiwaRCT501(int code);
390 #endif
391  //......................................................................
392 #if SEND_LG
393  void sendLG(unsigned long data, int nbits);
394 #endif
395  //......................................................................
396 #if SEND_SANYO
397  void sendSanyo ( ) ; // NOT WRITTEN
398 #endif
399  //......................................................................
400 #if SEND_MISUBISHI
401  void sendMitsubishi ( ) ; // NOT WRITTEN
402 #endif
403  //......................................................................
404 #if SEND_DISH
405  void sendDISH(unsigned long data, int nbits);
406 #endif
407  //......................................................................
408 #if SEND_SHARP
409  void sendSharpRaw(unsigned long data, int nbits);
410  void sendSharp(unsigned int address, unsigned int command);
411 #endif
412 #if SEND_SHARP_ALT
413  void sendSharpAltRaw(unsigned long data, int nbits);
414  void sendSharpAlt(unsigned int address, unsigned long command);
415 #endif
416  //......................................................................
417 #if SEND_DENON
418  void sendDenon(unsigned long data, int nbits);
419 #endif
420  //......................................................................
421 #if SEND_PRONTO
422  bool sendPronto(char* code, bool repeat, bool fallback);
423 #endif
424  //......................................................................
425 #if SEND_LEGO_PF
426  void sendLegoPowerFunctions(uint16_t data, bool repeat = true);
427 #endif
428  //......................................................................
429 #if SEND_BOSEWAVE
430  void sendBoseWave(unsigned char code);
431 #endif
432 
433 #if defined(USE_SOFT_CARRIER) || defined(USE_NO_CARRIER)
434  private:
435  int sendPin;
436 
437 # if defined(USE_SOFT_CARRIER)
438  unsigned int periodTime;
439  unsigned int periodOnTime;
440 
441  void sleepMicros(unsigned long us);
442  void sleepUntilMicros(unsigned long targetTime);
443 # endif
444 
445 #else
446  const int sendPin = IR_SEND_PIN;
447 #endif
448 };
449 
450 #endif
AIWA_RC_T501
@ AIWA_RC_T501
Definition: IRremote.h:123
UNKNOWN
@ UNKNOWN
Definition: IRremote.h:113
SONY
@ SONY
Definition: IRremote.h:118
IRrecv::resume
void resume()
Called to re-enable IR reception.
Definition: irRecv.cpp:215
IRrecv::disableIRIn
void disableIRIn()
Disable IR reception.
Definition: irRecv.cpp:185
RC5
@ RC5
Definition: IRremote.h:115
IRrecv::enableIRIn
void enableIRIn()
Enable IR reception.
Definition: irRecv.cpp:160
MATCH
int MATCH(int measured, int desired)
Definition: IRremote.cpp:43
IRrecv
Main class for receiving IR.
Definition: IRremote.h:193
MITSUBISHI
@ MITSUBISHI
Definition: IRremote.h:126
decode_results
Results returned from the decoder.
Definition: IRremote.h:174
IRsend::custom_delay_usec
void custom_delay_usec(unsigned long uSecs)
Definition: irSend.cpp:157
MATCH_SPACE
int MATCH_SPACE(int measured_ticks, int desired_us)
Definition: IRremote.cpp:89
DENON
@ DENON
Definition: IRremote.h:130
decode_results::bits
int bits
Number of bits in decoded value.
Definition: IRremote.h:179
IRsend::sendRC5ext
void sendRC5ext(unsigned long addr, unsigned long cmd, boolean toggle)
Definition: ir_RC5_RC6.cpp:86
LEGO_PF
@ LEGO_PF
Definition: IRremote.h:132
IRsend::sendNEC
void sendNEC(unsigned long data, int nbits)
Definition: ir_NEC.cpp:21
decode_results::address
unsigned int address
Used by Panasonic & Sharp [16-bits].
Definition: IRremote.h:177
decode_results::rawbuf
volatile unsigned int * rawbuf
Raw intervals in 50uS ticks.
Definition: IRremote.h:180
IRsend::mark
void mark(unsigned int usec)
Definition: irSend.cpp:69
UNUSED
@ UNUSED
Definition: IRremote.h:114
IRsend
Main class for sending IR.
Definition: IRremote.h:333
IRsend::enableIROut
void enableIROut(int khz)
Definition: irSend.cpp:127
IRsend::sendRC5
void sendRC5(unsigned long data, int nbits)
Definition: ir_RC5_RC6.cpp:63
IRsend::sendDenon
void sendDenon(unsigned long data, int nbits)
Definition: ir_Denon.cpp:33
IRsend::sendPanasonic
void sendPanasonic(unsigned int address, unsigned long data)
Definition: ir_Panasonic.cpp:20
decode_results::decode_type
decode_type_t decode_type
UNKNOWN, NEC, SONY, RC5, ...
Definition: IRremote.h:176
JVC
@ JVC
Definition: IRremote.h:120
SAMSUNG
@ SAMSUNG
Definition: IRremote.h:121
LG
@ LG
Definition: IRremote.h:124
IRsend::sendLegoPowerFunctions
void sendLegoPowerFunctions(uint16_t data, bool repeat=true)
Definition: ir_Lego_PF.cpp:30
decode_type_t
decode_type_t
An enum consisting of all supported formats.
Definition: IRremote.h:112
IRsend::sendSharpAlt
void sendSharpAlt(unsigned int address, unsigned long command)
Definition: ir_Sharp_alt.cpp:54
IRsend::sendLG
void sendLG(unsigned long data, int nbits)
Definition: ir_LG.cpp:72
IRsend::sendRaw_P
void sendRaw_P(const unsigned int buf[], unsigned int len, unsigned int hz)
Definition: irSend.cpp:20
IRsend::sendBoseWave
void sendBoseWave(unsigned char code)
Definition: ir_BoseWave.cpp:70
IRsend::sendJVC
void sendJVC(unsigned long data, int nbits, bool repeat)
Definition: ir_JVC.cpp:26
IRsend::sendRC6
void sendRC6(unsigned long data, int nbits)
Definition: ir_RC5_RC6.cpp:213
IRrecv::decode
int decode(decode_results *results)
Attempt to decode the recently receive IR signal.
Definition: irRecv.cpp:8
BOSEWAVE
@ BOSEWAVE
Definition: IRremote.h:133
RC6
@ RC6
Definition: IRremote.h:116
SANYO
@ SANYO
Definition: IRremote.h:125
SHARP_ALT
@ SHARP_ALT
Definition: IRremote.h:129
SHARP
@ SHARP
Definition: IRremote.h:128
IRsend::sendDISH
void sendDISH(unsigned long data, int nbits)
Definition: ir_Dish.cpp:33
WHYNTER
@ WHYNTER
Definition: IRremote.h:122
IRsend::sendSony
void sendSony(unsigned long data, int nbits)
Definition: ir_Sony.cpp:21
IRsend::sendSharp
void sendSharp(unsigned int address, unsigned int command)
Definition: ir_Sharp.cpp:71
PANASONIC
@ PANASONIC
Definition: IRremote.h:119
PRONTO
@ PRONTO
Definition: IRremote.h:131
IRsend::space
void space(unsigned int usec)
Definition: irSend.cpp:103
IRsend::IRsend
IRsend(int pin=IR_SEND_PIN)
Definition: IRremote.h:336
IRsend::sendWhynter
void sendWhynter(unsigned long data, int nbits)
Definition: ir_Whynter.cpp:22
IRrecv::IRrecv
IRrecv(int recvpin)
Instantiate the IRrecv class.
Definition: irRecv.cpp:144
decode_results::value
unsigned long value
Decoded value [max 32-bits].
Definition: IRremote.h:178
IRrecv::blink13
void blink13(int blinkflag)
TODO: Why is this public???
Definition: irRecv.cpp:197
decode_results::overflow
int overflow
true if IR raw code too long
Definition: IRremote.h:182
IRsend::sendAiwaRCT501
void sendAiwaRCT501(int code)
Definition: ir_Aiwa.cpp:27
NEC
@ NEC
Definition: IRremote.h:117
MATCH_MARK
int MATCH_MARK(int measured_ticks, int desired_us)
Definition: IRremote.cpp:63
IRsend::sendSharpRaw
void sendSharpRaw(unsigned long data, int nbits)
Definition: ir_Sharp.cpp:41
IR_SEND_PIN
#define IR_SEND_PIN
If applicable, pin number for sending IR.
Definition: IRremoteBoardDefs.h:362
IRsend::sendSAMSUNG
void sendSAMSUNG(unsigned long data, int nbits)
Definition: ir_Samsung.cpp:21
IRremoteInt.h
IRsend::sendSharpAltRaw
void sendSharpAltRaw(unsigned long data, int nbits)
Definition: ir_Sharp_alt.cpp:33
DISH
@ DISH
Definition: IRremote.h:127
decode_results::rawlen
unsigned int rawlen
Number of records in rawbuf.
Definition: IRremote.h:181
IRrecv::isIdle
bool isIdle()
Returns status of reception.
Definition: irRecv.cpp:209
IRsend::sendRaw
void sendRaw(const unsigned int buf[], unsigned int len, unsigned int hz)
Definition: irSend.cpp:5