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  * - USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN Reverts the polarity at the send pin.
50  * - 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!
51  * - SEND_PWM_BY_TIMER Disable carrier PWM generation in software and use (restricted) hardware PWM.
52  * - USE_NO_SEND_PWM Use no carrier PWM, just simulate an **active low** receiver signal. Overrides SEND_PWM_BY_TIMER definition.
53  * - USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM Simulate an **active high** receiver signal instead of an active low signal.
54  * - EXCLUDE_EXOTIC_PROTOCOLS If activated, BANG_OLUFSEN, BOSEWAVE, WHYNTER, FAST and LEGO_PF are excluded in decode() and in sending with IrSender.write().
55  * - EXCLUDE_UNIVERSAL_PROTOCOLS If activated, the universal decoder for pulse distance protocols and decodeHash (special decoder for all protocols) are excluded in decode().
56  * - DECODE_* Selection of individual protocols to be decoded. See below.
57  * - USE_THRESHOLD_DECODER May give slightly better results especially for jittering signals and protocols with short 1 pulses / pauses.
58  * - 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.
59  * - RECORD_GAP_MICROS Minimum gap between IR transmissions, to detect the end of a protocol.
60  * - FEEDBACK_LED_IS_ACTIVE_LOW Required on some boards (like my BluePill and my ESP8266 board), where the feedback LED is active low.
61  * - NO_LED_FEEDBACK_CODE This completely disables the LED feedback code for send and receive.
62  * - NO_LED_RECEIVE_FEEDBACK_CODE This disables the LED feedback code for receive.
63  * - NO_LED_SEND_FEEDBACK_CODE This disables the LED feedback code for send.
64  * - IR_INPUT_IS_ACTIVE_HIGH Enable it if you use a RF receiver, which has an active HIGH output signal.
65  * - IR_SEND_DUTY_CYCLE_PERCENT Duty cycle of IR send signal.
66  * - MICROS_PER_TICK Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 us at 38 kHz.
67  * - IR_USE_AVR_TIMER* Selection of timer to be used for generating IR receiving sample interval.
68  */
69 
70 #ifndef _IR_REMOTE_HPP
71 #define _IR_REMOTE_HPP
72 
73 #include "IRVersion.h"
74 
75 // activate it for all cores that does not use the -flto flag, if you get false error messages regarding begin() during compilation.
76 //#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN
77 
78 #include "IRProtocol.h"
79 
80 //#define DEBUG // Activate this for lots of lovely debug output from the IRremote core.
81 
82 // Helper macro for getting a macro definition as string
83 #if !defined(STR_HELPER) && !defined(STR)
84 #define STR_HELPER(x) #x
85 #define STR(x) STR_HELPER(x)
86 #endif
87 
88 /****************************************************
89  * RECEIVING
90  ****************************************************/
106 #if !defined(MARK_EXCESS_MICROS)
107 # if defined(USE_THRESHOLD_DECODER)
108 #define MARK_EXCESS_MICROS 0 // MARK_EXCESS_MICROS is not very relevant here, so we set it to 0 to save up to 164 bytes programming space
109 # else
110 // To override 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>"
111 #define MARK_EXCESS_MICROS 20 // a value != 0 requires up to 100 bytes program space
112 # endif
113 #endif
114 
122 #if !defined(RECORD_GAP_MICROS)
123 // 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>"
124 // Maximum value for RECORD_GAP_MICROS, which fit into 8 bit buffer, using 50 us as tick, is 12750
125 #define RECORD_GAP_MICROS 8000 // RECS80 (https://www.mikrocontroller.net/articles/IRMP#RECS80) 1 bit space is 7500µs , NEC header space is 4500
126 #endif
127 #define RECORD_GAP_TICKS (RECORD_GAP_MICROS / MICROS_PER_TICK) // 160 for RECORD_GAP_MICROS == 8000
128 
132 #if !defined(MICROS_PER_TICK)
133 #define MICROS_PER_TICK 50 // We do not need it to be 50L!!! It saves 90 bytes for UnitTest compared with 50L :-)
134 #endif
135 
139 #if !defined(RECORD_GAP_MICROS_WARNING_THRESHOLD)
140 // 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>"
141 #define RECORD_GAP_MICROS_WARNING_THRESHOLD 15000
142 #endif
143 
144 /*
145  * Activate this line if your receiver has an external output driver transistor / "inverted" output
146  */
147 //#define IR_INPUT_IS_ACTIVE_HIGH
148 #if defined(IR_INPUT_IS_ACTIVE_HIGH)
149 // IR detector output is active high
150 #define INPUT_MARK 1
151 #else
152 // IR detector output is active low
153 #define INPUT_MARK 0
154 #endif
155 /****************************************************
156  * SENDING
157  ****************************************************/
161 //#define SEND_PWM_BY_TIMER // restricts send pin on many platforms to fixed pin numbers
162 #if (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)) || defined(ARDUINO_ARCH_MBED)
163 # if !defined(SEND_PWM_BY_TIMER)
164 #define SEND_PWM_BY_TIMER // the best and default method for ESP32 etc.
165 #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.
166 # endif
167 #else
168 # if defined(SEND_PWM_BY_TIMER)
169 # if defined(IR_SEND_PIN)
170 #undef IR_SEND_PIN // to avoid warning 3 lines later
171 #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
172 # endif
173 #define IR_SEND_PIN DeterminedByTimer // must be set here, since it is evaluated at IRremoteInt.h, before the include of private/IRTimer.hpp
174 # endif
175 #endif
176 
180 //#define USE_NO_SEND_PWM
181 #if defined(SEND_PWM_BY_TIMER) && defined(USE_NO_SEND_PWM)
182 #warning "SEND_PWM_BY_TIMER and USE_NO_SEND_PWM are both defined -> undefine SEND_PWM_BY_TIMER now!"
183 #undef SEND_PWM_BY_TIMER // USE_NO_SEND_PWM overrides SEND_PWM_BY_TIMER
184 #endif
185 
190 //#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN
191 #if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN)
192 #warning Pin mode OUTPUT_OPEN_DRAIN is not supported on this platform -> mimick open drain mode by switching between INPUT and OUTPUT mode.
193 #endif
194 
199 #if !defined(PULSE_CORRECTION_NANOS)
200 # if defined(F_CPU)
201 // 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>"
202 #define PULSE_CORRECTION_NANOS (48000L / (F_CPU/MICROS_IN_ONE_SECOND)) // 3000 @16MHz, 666 @72MHz
203 # else
204 #define PULSE_CORRECTION_NANOS 600
205 # endif
206 #endif
207 
211 #if ! defined(IR_SEND_DUTY_CYCLE_PERCENT)
212 #define IR_SEND_DUTY_CYCLE_PERCENT 30 // 30 saves power and is compatible to the old existing code
213 #endif
214 
215 #define MILLIS_IN_ONE_SECOND 1000L
216 #define MICROS_IN_ONE_SECOND 1000000L
217 #define MICROS_IN_ONE_MILLI 1000L
218 
219 #if defined(NO_LED_FEEDBACK_CODE)
220 // convert to receive and send macros
221 # if !defined(NO_LED_RECEIVE_FEEDBACK_CODE)
222 #define NO_LED_RECEIVE_FEEDBACK_CODE
223 # endif
224 # if !defined(NO_LED_SEND_FEEDBACK_CODE)
225 #define NO_LED_SEND_FEEDBACK_CODE
226 # endif
227 #endif
228 #if defined(NO_LED_RECEIVE_FEEDBACK_CODE) && defined(NO_LED_SEND_FEEDBACK_CODE) && !defined(NO_LED_FEEDBACK_CODE)
229 #define NO_LED_FEEDBACK_CODE
230 #endif
231 
232 #include "IRremoteInt.h"
233 /*
234  * We always use digitalWriteFast() and digitalReadFast() functions to have a consistent mapping for pins.
235  * For most non AVR cpu's, it is just a mapping to digitalWrite() and digitalRead() functions.
236  */
237 #if !defined(MEGATINYCORE) // megaTinyCore has it own digitalWriteFast function set, except digitalToggleFast().
238 #include "digitalWriteFast.h"
239 #endif
240 
241 #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
242 #include "private/IRTimer.hpp" // defines IR_SEND_PIN for AVR and SEND_PWM_BY_TIMER
243 
244 # if !defined(NO_LED_FEEDBACK_CODE) && !(defined(DISABLE_CODE_FOR_RECEIVER) && defined(NO_LED_SEND_FEEDBACK_CODE))
245 // Led feedback code enabled here
246 # if !defined(LED_BUILTIN)
247 /*
248  * print a warning
249  */
250 #warning INFO: No definition for LED_BUILTIN found -> default LED feedback is disabled.
251 # endif
252 #include "IRFeedbackLED.hpp"
253 # else
254 void disableLEDFeedback() {}; // dummy function for examples
255 # endif
256 
257 #include "LongUnion.h" // used in most decoders
258 
259 /*
260  * Include the sources here to enable compilation with macro values set by user program.
261  */
262 #include "IRProtocol.hpp" // must be first, it includes definition for PrintULL (unsigned long long)
263 #if !defined(DISABLE_CODE_FOR_RECEIVER)
264 #include "IRReceive.hpp"
265 #endif
266 // Get absolute value of difference of two unsigned values
267 #if !defined(uintDifferenceAbs)
268 #define uintDifferenceAbs(a, b) ((a >= b) ? a - b : b - a)
269 #endif
270 #include "IRSend.hpp"
271 
272 /*
273  * Include the sources of all decoders here to enable compilation with macro values set by user program.
274  */
275 #include "ir_BangOlufsen.hpp"
276 #include "ir_BoseWave.hpp"
277 #include "ir_Denon.hpp"
278 #include "ir_JVC.hpp"
279 #include "ir_Kaseikyo.hpp"
280 #include "ir_Lego.hpp"
281 #include "ir_LG.hpp"
282 #include "ir_MagiQuest.hpp"
283 #include "ir_NEC.hpp"
284 #include "ir_OpenLASIR.hpp"
285 #include "ir_RC5_RC6.hpp"
286 #include "ir_Samsung.hpp"
287 #include "ir_Sony.hpp"
288 #include "ir_FAST.hpp"
289 #include "ir_Others.hpp"
290 #include "ir_Pronto.hpp" // pronto is an universal decoder and encoder
291 # if defined(DECODE_DISTANCE_WIDTH) // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory
293 # endif
294 #endif // #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
295 
299 #define RAWBUF 101 // Maximum length of raw duration buffer
300 #define REPEAT 0xFFFFFFFF
301 #define USECPERTICK MICROS_PER_TICK
302 #define MARK_EXCESS MARK_EXCESS_MICROS
303 
304 #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_OpenLASIR.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:84
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
IRProtocol.h
Common declarations for receiving and sending.
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....