IRremote
IRremote.hpp
Go to the documentation of this file.
1 
43 /*
44  * This library can be configured at compile time by the following options / macros:
45  * For more details see: https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
46  *
47  * - RAW_BUFFER_LENGTH Buffer size of raw input buffer. Must be even! 100 is sufficient for *regular* protocols of up to 48 bits.
48  * - IR_SEND_PIN If specified (as constant), reduces program size and improves send timing for AVR.
49  * - SEND_PWM_BY_TIMER Disable carrier PWM generation in software and use (restricted) hardware PWM.
50  * - USE_NO_SEND_PWM Use no carrier PWM, just simulate an **active low** receiver signal. Overrides SEND_PWM_BY_TIMER definition.
51  * - USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin!
52  * - EXCLUDE_EXOTIC_PROTOCOLS If activated, BANG_OLUFSEN, BOSEWAVE, WHYNTER, FAST and LEGO_PF are excluded in decode() and in sending with IrSender.write().
53  * - EXCLUDE_UNIVERSAL_PROTOCOLS If activated, the universal decoder for pulse distance protocols and decodeHash (special decoder for all protocols) are excluded in decode().
54  * - DECODE_* Selection of individual protocols to be decoded. See below.
55  * - MARK_EXCESS_MICROS Value is subtracted from all marks and added to all spaces before decoding, to compensate for the signal forming of different IR receiver modules.
56  * - RECORD_GAP_MICROS Minimum gap between IR transmissions, to detect the end of a protocol.
57  * - FEEDBACK_LED_IS_ACTIVE_LOW Required on some boards (like my BluePill and my ESP8266 board), where the feedback LED is active low.
58  * - NO_LED_FEEDBACK_CODE This completely disables the LED feedback code for send and receive.
59  * - IR_INPUT_IS_ACTIVE_HIGH Enable it if you use a RF receiver, which has an active HIGH output signal.
60  * - IR_SEND_DUTY_CYCLE_PERCENT Duty cycle of IR send signal.
61  * - MICROS_PER_TICK Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 us at 38 kHz.
62  * - IR_USE_AVR_TIMER* Selection of timer to be used for generating IR receiving sample interval.
63  */
64 
65 #ifndef _IR_REMOTE_HPP
66 #define _IR_REMOTE_HPP
67 
68 #include "IRVersion.h"
69 
70 // activate it for all cores that does not use the -flto flag, if you get false error messages regarding begin() during compilation.
71 //#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN
72 
73 /*
74  * If activated, BANG_OLUFSEN, BOSEWAVE, MAGIQUEST, WHYNTER, FAST and LEGO_PF are excluded in decoding and in sending with IrSender.write
75  */
76 //#define EXCLUDE_EXOTIC_PROTOCOLS
77 /****************************************************
78  * PROTOCOLS
79  ****************************************************/
80 /*
81  * Supported IR protocols
82  * Each protocol you include costs memory and, during decode, costs time
83  * Copy the lines with the protocols you need in your program before the #include <IRremote.hpp> line
84  * See also SimpleReceiver example
85  */
86 
87 #if !defined(NO_DECODER) // for sending raw only
88 # if (!(defined(DECODE_DENON) || defined(DECODE_JVC) || defined(DECODE_KASEIKYO) \
89 || defined(DECODE_PANASONIC) || defined(DECODE_LG) || defined(DECODE_NEC) || defined(DECODE_ONKYO) || defined(DECODE_SAMSUNG) \
90 || defined(DECODE_SONY) || defined(DECODE_RC5) || defined(DECODE_RC6) \
91 || defined(DECODE_DISTANCE_WIDTH) || defined(DECODE_HASH) || defined(DECODE_BOSEWAVE) \
92 || defined(DECODE_LEGO_PF) || defined(DECODE_MAGIQUEST) || defined(DECODE_FAST) || defined(DECODE_WHYNTER)))
93 /*
94  * If no protocol is explicitly enabled, we enable all protocols
95  */
96 #define DECODE_DENON // Includes Sharp
97 #define DECODE_JVC
98 #define DECODE_KASEIKYO
99 #define DECODE_PANASONIC // alias for DECODE_KASEIKYO
100 #define DECODE_LG
101 #define DECODE_NEC // Includes Apple and Onkyo
102 #define DECODE_SAMSUNG
103 #define DECODE_SONY
104 #define DECODE_RC5
105 #define DECODE_RC6
106 
107 # if !defined(EXCLUDE_EXOTIC_PROTOCOLS) // saves around 2000 bytes program memory
108 #define DECODE_BOSEWAVE
109 #define DECODE_LEGO_PF
110 #define DECODE_MAGIQUEST
111 #define DECODE_WHYNTER
112 #define DECODE_FAST
113 # endif
114 
115 # if !defined(EXCLUDE_UNIVERSAL_PROTOCOLS)
116 #define DECODE_DISTANCE_WIDTH // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory
117 #define DECODE_HASH // special decoder for all protocols - requires up to 250 bytes additional program memory
118 # endif
119 # endif
120 #endif // !defined(NO_DECODER)
121 
122 //#define DECODE_BEO // Bang & Olufsen protocol always must be enabled explicitly. It prevents decoding of SONY!
123 
124 #if defined(DECODE_NEC) && !(~(~DECODE_NEC + 0) == 0 && ~(~DECODE_NEC + 1) == 1)
125 #warning "The macros DECODE_XXX no longer require a value. Decoding is now switched by defining / non defining the macro."
126 #endif
127 
128 //#define DEBUG // Activate this for lots of lovely debug output from the IRremote core.
129 
130 /****************************************************
131  * RECEIVING
132  ****************************************************/
148 #if !defined(MARK_EXCESS_MICROS)
149 // To change this value, you simply can add a line #define "MARK_EXCESS_MICROS <My_new_value>" in your ino file before the line "#include <IRremote.hpp>"
150 #define MARK_EXCESS_MICROS 20
151 #endif
152 
159 #if !defined(RECORD_GAP_MICROS)
160 // To change this value, you simply can add a line #define "RECORD_GAP_MICROS <My_new_value>" in your *.ino file before the line "#include <IRremote.hpp>"
161 // Maximum value for RECORD_GAP_MICROS, which fit into 8 bit buffer, using 50 us as tick, is 12750
162 #define RECORD_GAP_MICROS 8000 // RECS80 (https://www.mikrocontroller.net/articles/IRMP#RECS80) 1 bit space is 7500µs , NEC header space is 4500
163 #endif
164 
167 #if !defined(RECORD_GAP_MICROS_WARNING_THRESHOLD)
168 // To change this value, you simply can add a line #define "RECORD_GAP_MICROS_WARNING_THRESHOLD <My_new_value>" in your *.ino file before the line "#include <IRremote.hpp>"
169 #define RECORD_GAP_MICROS_WARNING_THRESHOLD 15000
170 #endif
171 
173 #define RECORD_GAP_TICKS (RECORD_GAP_MICROS / MICROS_PER_TICK)
174 
175 /*
176  * Activate this line if your receiver has an external output driver transistor / "inverted" output
177  */
178 //#define IR_INPUT_IS_ACTIVE_HIGH
179 #if defined(IR_INPUT_IS_ACTIVE_HIGH)
180 // IR detector output is active high
181 #define INPUT_MARK 1
182 #else
183 // IR detector output is active low
184 #define INPUT_MARK 0
185 #endif
186 /****************************************************
187  * SENDING
188  ****************************************************/
192 //#define SEND_PWM_BY_TIMER // restricts send pin on many platforms to fixed pin numbers
193 #if (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)) || defined(ARDUINO_ARCH_MBED)
194 # if !defined(SEND_PWM_BY_TIMER)
195 #define SEND_PWM_BY_TIMER // the best and default method for ESP32 etc.
196 #warning INFO: For ESP32, RP2040, mbed and particle boards SEND_PWM_BY_TIMER is enabled by default, since we have the resources and timing is more exact than the software generated one. If this is not intended, deactivate the line in IRremote.hpp over this warning message in file IRremote.hpp.
197 # endif
198 #else
199 # if defined(SEND_PWM_BY_TIMER)
200 # if defined(IR_SEND_PIN)
201 #undef IR_SEND_PIN // to avoid warning 3 lines later
202 #warning Since SEND_PWM_BY_TIMER is defined, the existing value of IR_SEND_PIN is discarded and replaced by the value determined by timer used for PWM generation
203 # endif
204 #define IR_SEND_PIN DeterminedByTimer // must be set here, since it is evaluated at IRremoteInt.h, before the include of private/IRTimer.hpp
205 # endif
206 #endif
207 
211 //#define USE_NO_SEND_PWM
212 #if defined(SEND_PWM_BY_TIMER) && defined(USE_NO_SEND_PWM)
213 #warning "SEND_PWM_BY_TIMER and USE_NO_SEND_PWM are both defined -> undefine SEND_PWM_BY_TIMER now!"
214 #undef SEND_PWM_BY_TIMER // USE_NO_SEND_PWM overrides SEND_PWM_BY_TIMER
215 #endif
216 
221 //#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN
222 #if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN)
223 #warning Pin mode OUTPUT_OPEN_DRAIN is not supported on this platform -> mimick open drain mode by switching between INPUT and OUTPUT mode.
224 #endif
225 
230 #if !defined(PULSE_CORRECTION_NANOS)
231 # if defined(F_CPU)
232 // To change this value, you simply can add a line #define "PULSE_CORRECTION_NANOS <My_new_value>" in your ino file before the line "#include <IRremote.hpp>"
233 #define PULSE_CORRECTION_NANOS (48000L / (F_CPU/MICROS_IN_ONE_SECOND)) // 3000 @16MHz, 666 @72MHz
234 # else
235 #define PULSE_CORRECTION_NANOS 600
236 # endif
237 #endif
238 
242 #if ! defined(IR_SEND_DUTY_CYCLE_PERCENT)
243 #define IR_SEND_DUTY_CYCLE_PERCENT 30 // 30 saves power and is compatible to the old existing code
244 #endif
245 
249 #if ! defined(MICROS_PER_TICK)
250 #define MICROS_PER_TICK 50L // must be with L to get 32 bit results if multiplied with rawbuf[] content.
251 #endif
252 
253 #define MILLIS_IN_ONE_SECOND 1000L
254 #define MICROS_IN_ONE_SECOND 1000000L
255 #define MICROS_IN_ONE_MILLI 1000L
256 
257 #include "IRremoteInt.h"
258 /*
259  * We always use digitalWriteFast() and digitalReadFast() functions to have a consistent mapping for pins.
260  * For most non AVR cpu's, it is just a mapping to digitalWrite() and digitalRead() functions.
261  */
262 #include "digitalWriteFast.h"
263 
264 #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
265 #include "private/IRTimer.hpp" // defines IR_SEND_PIN for AVR and SEND_PWM_BY_TIMER
266 
267 # if !defined(NO_LED_FEEDBACK_CODE)
268 # if !defined(LED_BUILTIN)
269 /*
270  * print a warning
271  */
272 #warning INFO: No definition for LED_BUILTIN found -> default LED feedback is disabled.
273 # endif
274 #include "IRFeedbackLED.hpp"
275 # else
276 void disableLEDFeedback() {}; // dummy function for examples
277 # endif
278 
279 #include "LongUnion.h" // used in most decoders
280 
281 /*
282  * Include the sources here to enable compilation with macro values set by user program.
283  */
284 #include "IRProtocol.hpp" // must be first, it includes definition for PrintULL (unsigned long long)
285 #if !defined(DISABLE_CODE_FOR_RECEIVER)
286 #include "IRReceive.hpp"
287 #endif
288 #include "IRSend.hpp"
289 
290 /*
291  * Include the sources of all decoders here to enable compilation with macro values set by user program.
292  */
293 #include "ir_BangOlufsen.hpp"
294 #include "ir_BoseWave.hpp"
295 #include "ir_Denon.hpp"
296 #include "ir_JVC.hpp"
297 #include "ir_Kaseikyo.hpp"
298 #include "ir_Lego.hpp"
299 #include "ir_LG.hpp"
300 #include "ir_MagiQuest.hpp"
301 #include "ir_NEC.hpp"
302 #include "ir_RC5_RC6.hpp"
303 #include "ir_Samsung.hpp"
304 #include "ir_Sony.hpp"
305 #include "ir_FAST.hpp"
306 #include "ir_Others.hpp"
307 #include "ir_Pronto.hpp" // pronto is an universal decoder and encoder
308 # if defined(DECODE_DISTANCE_WIDTH) // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory
310 # endif
311 #endif // #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
312 
316 #define RAWBUF 101 // Maximum length of raw duration buffer
317 #define REPEAT 0xFFFFFFFF
318 #define USECPERTICK MICROS_PER_TICK
319 #define MARK_EXCESS MARK_EXCESS_MICROS
320 
321 #endif // _IR_REMOTE_HPP
IRSend.hpp
IRTimer.hpp
All timer specific definitions are contained in this file. Sets IR_SEND_PIN if required,...
ir_Samsung.hpp
ir_Sony.hpp
ir_MagiQuest.hpp
ir_FAST.hpp
ir_RC5_RC6.hpp
ir_NEC.hpp
ir_BangOlufsen.hpp
ir_Lego.hpp
digitalWriteFast.h
ir_DistanceWidthProtocol.hpp
ir_Others.hpp
ir_LG.hpp
disableLEDFeedback
void disableLEDFeedback()
Definition: IRFeedbackLED.hpp:89
IRProtocol.hpp
LongUnion.h
IRFeedbackLED.hpp
All Feedback LED specific functions are contained in this file.
ir_Denon.hpp
ir_Kaseikyo.hpp
ir_JVC.hpp
IRReceive.hpp
IRVersion.h
ir_BoseWave.hpp
ir_Pronto.hpp
IRremoteInt.h
Contains all declarations required for the interface to IRremote. Could not be named IRremote....