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 /****************************************************
83  * RECEIVING
84  ****************************************************/
100 #if !defined(MARK_EXCESS_MICROS)
101 # if defined(USE_THRESHOLD_DECODER)
102 #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
103 # else
104 // 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>"
105 #define MARK_EXCESS_MICROS 20 // a value != 0 requires up to 100 bytes program space
106 # endif
107 #endif
108 
115 #if !defined(RECORD_GAP_MICROS)
116 // 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>"
117 // Maximum value for RECORD_GAP_MICROS, which fit into 8 bit buffer, using 50 us as tick, is 12750
118 #define RECORD_GAP_MICROS 8000 // RECS80 (https://www.mikrocontroller.net/articles/IRMP#RECS80) 1 bit space is 7500µs , NEC header space is 4500
119 #endif
120 
123 #if !defined(RECORD_GAP_MICROS_WARNING_THRESHOLD)
124 // 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>"
125 #define RECORD_GAP_MICROS_WARNING_THRESHOLD 15000
126 #endif
127 
129 #define RECORD_GAP_TICKS (RECORD_GAP_MICROS / MICROS_PER_TICK)
130 
131 /*
132  * Activate this line if your receiver has an external output driver transistor / "inverted" output
133  */
134 //#define IR_INPUT_IS_ACTIVE_HIGH
135 #if defined(IR_INPUT_IS_ACTIVE_HIGH)
136 // IR detector output is active high
137 #define INPUT_MARK 1
138 #else
139 // IR detector output is active low
140 #define INPUT_MARK 0
141 #endif
142 /****************************************************
143  * SENDING
144  ****************************************************/
148 //#define SEND_PWM_BY_TIMER // restricts send pin on many platforms to fixed pin numbers
149 #if (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)) || defined(ARDUINO_ARCH_MBED)
150 # if !defined(SEND_PWM_BY_TIMER)
151 #define SEND_PWM_BY_TIMER // the best and default method for ESP32 etc.
152 #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.
153 # endif
154 #else
155 # if defined(SEND_PWM_BY_TIMER)
156 # if defined(IR_SEND_PIN)
157 #undef IR_SEND_PIN // to avoid warning 3 lines later
158 #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
159 # endif
160 #define IR_SEND_PIN DeterminedByTimer // must be set here, since it is evaluated at IRremoteInt.h, before the include of private/IRTimer.hpp
161 # endif
162 #endif
163 
167 //#define USE_NO_SEND_PWM
168 #if defined(SEND_PWM_BY_TIMER) && defined(USE_NO_SEND_PWM)
169 #warning "SEND_PWM_BY_TIMER and USE_NO_SEND_PWM are both defined -> undefine SEND_PWM_BY_TIMER now!"
170 #undef SEND_PWM_BY_TIMER // USE_NO_SEND_PWM overrides SEND_PWM_BY_TIMER
171 #endif
172 
177 //#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN
178 #if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN)
179 #warning Pin mode OUTPUT_OPEN_DRAIN is not supported on this platform -> mimick open drain mode by switching between INPUT and OUTPUT mode.
180 #endif
181 
186 #if !defined(PULSE_CORRECTION_NANOS)
187 # if defined(F_CPU)
188 // 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>"
189 #define PULSE_CORRECTION_NANOS (48000L / (F_CPU/MICROS_IN_ONE_SECOND)) // 3000 @16MHz, 666 @72MHz
190 # else
191 #define PULSE_CORRECTION_NANOS 600
192 # endif
193 #endif
194 
198 #if ! defined(IR_SEND_DUTY_CYCLE_PERCENT)
199 #define IR_SEND_DUTY_CYCLE_PERCENT 30 // 30 saves power and is compatible to the old existing code
200 #endif
201 
202 
206 #if ! defined(MICROS_PER_TICK)
207 #define MICROS_PER_TICK 50L // must be with L to get 32 bit results if multiplied with rawbuf[] content.
208 #endif
209 
210 #define MILLIS_IN_ONE_SECOND 1000L
211 #define MICROS_IN_ONE_SECOND 1000000L
212 #define MICROS_IN_ONE_MILLI 1000L
213 
214 #if defined(NO_LED_FEEDBACK_CODE)
215 // convert to receive and send macros
216 # if !defined(NO_LED_RECEIVE_FEEDBACK_CODE)
217 #define NO_LED_RECEIVE_FEEDBACK_CODE
218 # endif
219 # if !defined(NO_LED_SEND_FEEDBACK_CODE)
220 #define NO_LED_SEND_FEEDBACK_CODE
221 # endif
222 #endif
223 #if defined(NO_LED_RECEIVE_FEEDBACK_CODE) && defined(NO_LED_SEND_FEEDBACK_CODE) && !defined(NO_LED_FEEDBACK_CODE)
224 #define NO_LED_FEEDBACK_CODE
225 #endif
226 
227 #include "IRremoteInt.h"
228 /*
229  * We always use digitalWriteFast() and digitalReadFast() functions to have a consistent mapping for pins.
230  * For most non AVR cpu's, it is just a mapping to digitalWrite() and digitalRead() functions.
231  */
232 #if !defined(MEGATINYCORE) // megaTinyCore has it own digitalWriteFast function set, except digitalToggleFast().
233 #include "digitalWriteFast.h"
234 #endif
235 
236 #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
237 #include "private/IRTimer.hpp" // defines IR_SEND_PIN for AVR and SEND_PWM_BY_TIMER
238 
239 # if !defined(NO_LED_FEEDBACK_CODE) && !(defined(DISABLE_CODE_FOR_RECEIVER) && defined(NO_LED_SEND_FEEDBACK_CODE))
240 // Led feedback code enabled here
241 # if !defined(LED_BUILTIN)
242 /*
243  * print a warning
244  */
245 #warning INFO: No definition for LED_BUILTIN found -> default LED feedback is disabled.
246 # endif
247 #include "IRFeedbackLED.hpp"
248 # else
249 void disableLEDFeedback() {}; // dummy function for examples
250 # endif
251 
252 #include "LongUnion.h" // used in most decoders
253 
254 /*
255  * Include the sources here to enable compilation with macro values set by user program.
256  */
257 #include "IRProtocol.hpp" // must be first, it includes definition for PrintULL (unsigned long long)
258 #if !defined(DISABLE_CODE_FOR_RECEIVER)
259 #include "IRReceive.hpp"
260 #endif
261 #include "IRSend.hpp"
262 
263 /*
264  * Include the sources of all decoders here to enable compilation with macro values set by user program.
265  */
266 #include "ir_BangOlufsen.hpp"
267 #include "ir_BoseWave.hpp"
268 #include "ir_Denon.hpp"
269 #include "ir_JVC.hpp"
270 #include "ir_Kaseikyo.hpp"
271 #include "ir_Lego.hpp"
272 #include "ir_LG.hpp"
273 #include "ir_MagiQuest.hpp"
274 #include "ir_NEC.hpp"
275 #include "ir_RC5_RC6.hpp"
276 #include "ir_Samsung.hpp"
277 #include "ir_Sony.hpp"
278 #include "ir_FAST.hpp"
279 #include "ir_Others.hpp"
280 #include "ir_Pronto.hpp" // pronto is an universal decoder and encoder
281 # if defined(DECODE_DISTANCE_WIDTH) // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory
283 # endif
284 #endif // #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE)
285 
289 #define RAWBUF 101 // Maximum length of raw duration buffer
290 #define REPEAT 0xFFFFFFFF
291 #define USECPERTICK MICROS_PER_TICK
292 #define MARK_EXCESS MARK_EXCESS_MICROS
293 
294 #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:70
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....