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 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 #define VERSION_IRREMOTE "4.0.0"
69 #define VERSION_IRREMOTE_MAJOR 4
70 #define VERSION_IRREMOTE_MINOR 0
71 #define VERSION_IRREMOTE_PATCH 0
72 
73 /*
74  * Macro to convert 3 version parts into an integer
75  * To be used in preprocessor comparisons, such as #if VERSION_IRREMOTE_HEX >= VERSION_HEX_VALUE(3, 7, 0)
76  */
77 #define VERSION_HEX_VALUE(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
78 #define VERSION_IRREMOTE_HEX VERSION_HEX_VALUE(VERSION_IRREMOTE_MAJOR, VERSION_IRREMOTE_MINOR, VERSION_IRREMOTE_PATCH)
79 
80 // activate it for all cores that does not use the -flto flag, if you get false error messages regarding begin() during compilation.
81 //#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN
82 
83 /*
84  * If activated, BANG_OLUFSEN, BOSEWAVE, MAGIQUEST,WHYNTER and LEGO_PF are excluded in decoding and in sending with IrSender.write
85  */
86 //#define EXCLUDE_EXOTIC_PROTOCOLS
87 /****************************************************
88  * PROTOCOLS
89  ****************************************************/
90 /*
91  * Supported IR protocols
92  * Each protocol you include costs memory and, during decode, costs time
93  * Copy the lines with the protocols you need in your program before the #include <IRremote.hpp> line
94  * See also SimpleReceiver example
95  */
96 
97 #if !defined(NO_DECODER) // for sending raw only
98 # if (!(defined(DECODE_DENON) || defined(DECODE_JVC) || defined(DECODE_KASEIKYO) \
99 || defined(DECODE_PANASONIC) || defined(DECODE_LG) || defined(DECODE_NEC) || defined(DECODE_SAMSUNG) \
100 || defined(DECODE_SONY) || defined(DECODE_RC5) || defined(DECODE_RC6) \
101 || defined(DECODE_DISTANCE_WIDTH) || defined(DECODE_HASH) || defined(DECODE_BOSEWAVE) \
102 || defined(DECODE_LEGO_PF) || defined(DECODE_MAGIQUEST) || defined(DECODE_WHYNTER)))
103 /*
104  * If no protocol is explicitly enabled, we enable all protocols
105  */
106 #define DECODE_DENON // Includes Sharp
107 #define DECODE_JVC
108 #define DECODE_KASEIKYO
109 #define DECODE_PANASONIC // alias for DECODE_KASEIKYO
110 #define DECODE_LG
111 #define DECODE_NEC // Includes Apple and Onkyo
112 #define DECODE_SAMSUNG
113 #define DECODE_SONY
114 #define DECODE_RC5
115 #define DECODE_RC6
116 
117 # if !defined(EXCLUDE_EXOTIC_PROTOCOLS) // saves around 2000 bytes program memory
118 #define DECODE_BOSEWAVE
119 #define DECODE_LEGO_PF
120 #define DECODE_MAGIQUEST // It modifies the RAW_BUFFER_LENGTH from 100 to 112
121 #define DECODE_WHYNTER
122 # endif
123 
124 # if !defined(EXCLUDE_UNIVERSAL_PROTOCOLS)
125 #define DECODE_DISTANCE_WIDTH // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory
126 #define DECODE_HASH // special decoder for all protocols - requires up to 250 bytes additional program memory
127 # endif
128 # endif
129 #endif // !defined(NO_DECODER)
130 
131 //#define DECODE_BEO // Bang & Olufsen protocol always must be enabled explicitly. It prevents decoding of SONY!
132 
133 #if defined(DECODE_NEC) && !(~(~DECODE_NEC + 0) == 0 && ~(~DECODE_NEC + 1) == 1)
134 #warning "The macros DECODE_XXX no longer require a value. Decoding is now switched by defining / non defining the macro."
135 #endif
136 
137 //#define DEBUG // Activate this for lots of lovely debug output from the IRremote core.
138 
139 /****************************************************
140  * RECEIVING
141  ****************************************************/
157 #if !defined(MARK_EXCESS_MICROS)
158 // 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>"
159 #define MARK_EXCESS_MICROS 20
160 #endif
161 
168 #if !defined(RECORD_GAP_MICROS)
169 // 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>"
170 #define RECORD_GAP_MICROS 5000 // FREDRICH28AC / LG2 header space is 9700, NEC header space is 4500
171 #endif
172 
175 #if !defined(RECORD_GAP_MICROS_WARNING_THRESHOLD)
176 // 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>"
177 #define RECORD_GAP_MICROS_WARNING_THRESHOLD 15000
178 #endif
179 
181 #define RECORD_GAP_TICKS (RECORD_GAP_MICROS / MICROS_PER_TICK) // 100
182 
183 /*
184  * Activate this line if your receiver has an external output driver transistor / "inverted" output
185  */
186 //#define IR_INPUT_IS_ACTIVE_HIGH
187 #if defined(IR_INPUT_IS_ACTIVE_HIGH)
188 // IR detector output is active high
189 #define INPUT_MARK 1
190 #else
191 // IR detector output is active low
192 #define INPUT_MARK 0
193 #endif
194 /****************************************************
195  * SENDING
196  ****************************************************/
200 //#define SEND_PWM_BY_TIMER // restricts send pin on many platforms to fixed pin numbers
201 #if (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)) || defined(ARDUINO_ARCH_MBED)
202 # if !defined(SEND_PWM_BY_TIMER)
203 #define SEND_PWM_BY_TIMER // the best and default method for ESP32 etc.
204 #warning INFO: For ESP32, RP2040, mbed and particle boards SEND_PWM_BY_TIMER is enabled by default. If this is not intended, deactivate the line in IRremote.hpp over this warning message in file IRremote.hpp.
205 # endif
206 #else
207 # if defined(SEND_PWM_BY_TIMER)
208 # if defined(IR_SEND_PIN)
209 #undef IR_SEND_PIN // to avoid warning 3 lines later
210 #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
211 # endif
212 #define IR_SEND_PIN DeterminedByTimer // must be set here, since it is evaluated at IRremoteInt.h, before the include of private/IRTimer.hpp
213 # endif
214 #endif
215 
219 //#define USE_NO_SEND_PWM
220 #if defined(SEND_PWM_BY_TIMER) && defined(USE_NO_SEND_PWM)
221 #warning "SEND_PWM_BY_TIMER and USE_NO_SEND_PWM are both defined -> undefine SEND_PWM_BY_TIMER now!"
222 #undef SEND_PWM_BY_TIMER // USE_NO_SEND_PWM overrides SEND_PWM_BY_TIMER
223 #endif
224 
229 //#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN
230 #if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN)
231 #warning Pin mode OUTPUT_OPEN_DRAIN is not supported on this platform -> mimick open drain mode by switching between INPUT and OUTPUT mode.
232 #endif
233 
238 #if !defined(PULSE_CORRECTION_NANOS)
239 # if defined(F_CPU)
240 // 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>"
241 #define PULSE_CORRECTION_NANOS (48000L / (F_CPU/MICROS_IN_ONE_SECOND)) // 3000 @16MHz, 666 @72MHz
242 # else
243 #define PULSE_CORRECTION_NANOS 600
244 # endif
245 #endif
246 
250 #if ! defined(IR_SEND_DUTY_CYCLE_PERCENT)
251 #define IR_SEND_DUTY_CYCLE_PERCENT 30 // 30 saves power and is compatible to the old existing code
252 #endif
253 
257 #if ! defined(MICROS_PER_TICK)
258 #define MICROS_PER_TICK 50
259 #endif
260 
261 #define MILLIS_IN_ONE_SECOND 1000L
262 #define MICROS_IN_ONE_SECOND 1000000L
263 #define MICROS_IN_ONE_MILLI 1000L
264 
265 #include "IRremoteInt.h"
266 /*
267  * We always use digitalWriteFast() and digitalReadFast() functions to have a consistent mapping for pins.
268  * For most non AVR cpu's, it is just a mapping to digitalWrite() and digitalRead() functions.
269  */
270 #include "digitalWriteFast.h"
271 
272 #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
273 #include "private/IRTimer.hpp" // defines IR_SEND_PIN for AVR and SEND_PWM_BY_TIMER
274 
275 # if !defined(NO_LED_FEEDBACK_CODE)
276 # if !defined(LED_BUILTIN)
277 /*
278  * print a warning
279  */
280 #warning INFO: No definition for LED_BUILTIN found -> default LED feedback is disabled.
281 # endif
282 #include "IRFeedbackLED.hpp"
283 # endif
284 
285 #include "LongUnion.h" // used in most decoders
286 
287 /*
288  * Include the sources here to enable compilation with macro values set by user program.
289  */
290 #include "IRProtocol.hpp" // must be first, it includes definition for PrintULL (unsigned long long)
291 #if !defined(DISABLE_CODE_FOR_RECEIVER)
292 #include "IRReceive.hpp"
293 #endif
294 #include "IRSend.hpp"
295 
296 /*
297  * Include the sources of all decoders here to enable compilation with macro values set by user program.
298  */
299 #include "ir_BangOlufsen.hpp"
300 #include "ir_BoseWave.hpp"
301 #include "ir_Denon.hpp"
302 #include "ir_JVC.hpp"
303 #include "ir_Kaseikyo.hpp"
304 #include "ir_Lego.hpp"
305 #include "ir_LG.hpp"
306 #include "ir_MagiQuest.hpp"
307 #include "ir_NEC.hpp"
308 #include "ir_RC5_RC6.hpp"
309 #include "ir_Samsung.hpp"
310 #include "ir_Sony.hpp"
311 #include "ir_Others.hpp"
312 #include "ir_Pronto.hpp" // pronto is an universal decoder and encoder
313 # if defined(DECODE_DISTANCE_WIDTH) // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory
315 # endif
316 
317 #endif // #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
318 
322 #define RAWBUF 101 // Maximum length of raw duration buffer
323 #define REPEAT 0xFFFFFFFF
324 #define USECPERTICK MICROS_PER_TICK
325 #define MARK_EXCESS MARK_EXCESS_MICROS
326 
327 #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_RC5_RC6.hpp
ir_NEC.hpp
ir_BangOlufsen.hpp
ir_Lego.hpp
digitalWriteFast.h
ir_DistanceWidthProtocol.hpp
ir_Others.hpp
ir_LG.hpp
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
ir_BoseWave.hpp
ir_Pronto.hpp
IRremoteInt.h
Contains all declarations required for the interface to IRremote. Could not be named IRremote....