IRremote
IRSend.hpp
Go to the documentation of this file.
1 /*
2  * IRSend.hpp
3  *
4  * Contains common functions for sending
5  *
6  * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
7  *
8  ************************************************************************************
9  * MIT License
10  *
11  * Copyright (c) 2009-2025 Ken Shirriff, Rafi Khan, Armin Joachimsmeyer
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a copy
14  * of this software and associated documentation files (the "Software"), to deal
15  * in the Software without restriction, including without limitation the rights
16  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17  * copies of the Software, and to permit persons to whom the Software is furnished
18  * to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in all
21  * copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  *
30  ************************************************************************************
31  */
32 #ifndef _IR_SEND_HPP
33 #define _IR_SEND_HPP
34 
35 #if defined(DEBUG)
36 #define LOCAL_DEBUG
37 #else
38 //#define LOCAL_DEBUG // This enables debug output only for this file
39 #endif
40 
41 #if defined(TRACE) && !defined(LOCAL_TRACE)
42 #define LOCAL_TRACE
43 #else
44 //#define LOCAL_TRACE // This enables debug output only for this file
45 #endif
46 
47 /*
48  * Low level hardware timing measurement
49  */
50 //#define _IR_MEASURE_TIMING // for mark()
51 //#define _IR_TIMING_TEST_PIN 7 // "pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT);" is executed at begin()
52 //
53 /*
54  * This improves readability of code by avoiding a lot of #if defined clauses
55  */
56 #if defined(IR_SEND_PIN)
57 #define sendPin IR_SEND_PIN
58 #endif
59 
60 #if !defined(NO_LED_SEND_FEEDBACK_CODE)
61 #define LED_SEND_FEEDBACK_CODE // Resolve the double negative
62 #endif
63 
68 // The sender instance
70 
71 IRsend::IRsend() { // @suppress("Class members should be properly initialized")
72 #if !defined(IR_SEND_PIN)
73  sendPin = 0;
74 #endif
75 }
76 
77 /******************************************************************************************************************
78  * LED feedback is always enabled for sending. It can only be disabled by using the macro NO_LED_SEND_FEEDBACK_CODE
79  *****************************************************************************************************************/
80 #if defined(IR_SEND_PIN)
81 
84 void IRsend::begin(){
85 #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
86  pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT);
87 #endif
88 }
89 
94 void IRsend::begin(uint_fast8_t aFeedbackLEDPin) {
95  setLEDFeedbackPin(aFeedbackLEDPin);
96 }
97 
98 #else // defined(IR_SEND_PIN)
99 IRsend::IRsend(uint_fast8_t aSendPin) { // @suppress("Class members should be properly initialized")
100  sendPin = aSendPin;
101 }
102 
107 void IRsend::begin(uint_fast8_t aSendPin) {
108  sendPin = aSendPin;
109 }
110 
111 void IRsend::setSendPin(uint_fast8_t aSendPin) {
112  sendPin = aSendPin;
113 }
114 
120 void IRsend::begin(uint_fast8_t aSendPin, uint_fast8_t aFeedbackLEDPin) {
121 #if defined(IR_SEND_PIN)
122  (void) aSendPin; // for backwards compatibility
123 #else
124  sendPin = aSendPin;
125 #endif
126 
127 #if defined(LED_SEND_FEEDBACK_CODE)
128  setLEDFeedbackPin(aFeedbackLEDPin);
129 #else
130  (void) aFeedbackLEDPin;
131 #endif
132 }
133 #endif // defined(IR_SEND_PIN)
134 
135 // Deprecated
136 void IRsend::begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin) {
137  (void) aEnableLEDFeedback;
138  begin(aSendPin,aFeedbackLEDPin);
139 }
140 
153 size_t IRsend::write(IRData *aIRSendData, int_fast8_t aNumberOfRepeats) {
154 
155  auto tProtocol = aIRSendData->protocol;
156  auto tAddress = aIRSendData->address;
157  auto tCommand = aIRSendData->command;
158  bool tIsRepeat = (aIRSendData->flags & IRDATA_FLAGS_IS_REPEAT);
159  if (tIsRepeat) {
160  aNumberOfRepeats = -1; // if aNumberOfRepeats < 0 then only a special repeat frame will be sent
161  }
162 // switch (tProtocol) { // 26 bytes bigger than if, else if, else
163 // case NEC:
164 // sendNEC(tAddress, tCommand, aNumberOfRepeats, tSendRepeat);
165 // break;
166 // case SAMSUNG:
167 // sendSamsung(tAddress, tCommand, aNumberOfRepeats);
168 // break;
169 // case SONY:
170 // sendSony(tAddress, tCommand, aNumberOfRepeats, aIRSendData->numberOfBits);
171 // break;
172 // case PANASONIC:
173 // sendPanasonic(tAddress, tCommand, aNumberOfRepeats);
174 // break;
175 // case DENON:
176 // sendDenon(tAddress, tCommand, aNumberOfRepeats);
177 // break;
178 // case SHARP:
179 // sendSharp(tAddress, tCommand, aNumberOfRepeats);
180 // break;
181 // case JVC:
182 // sendJVC((uint8_t) tAddress, (uint8_t) tCommand, aNumberOfRepeats); // casts are required to specify the right function
183 // break;
184 // case RC5:
185 // sendRC5(tAddress, tCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
186 // break;
187 // case RC6:
188 // // No toggle for repeats// sendRC6(tAddress, tCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
189 // break;
190 // default:
191 // break;
192 // }
193 
194  /*
195  * Order of protocols is in guessed relevance :-)
196  */
197  if (tProtocol == NEC) {
198  sendNEC(tAddress, tCommand, aNumberOfRepeats);
199 
200  } else if (tProtocol == SAMSUNG) {
201  sendSamsung(tAddress, tCommand, aNumberOfRepeats);
202 
203  } else if (tProtocol == SAMSUNG48) {
204  sendSamsung48(tAddress, tCommand, aNumberOfRepeats);
205 
206  } else if (tProtocol == SAMSUNGLG) {
207  sendSamsungLG(tAddress, tCommand, aNumberOfRepeats);
208 
209  } else if (tProtocol == SONY) {
210  sendSony(tAddress, tCommand, aNumberOfRepeats, aIRSendData->numberOfBits);
211 
212  } else if (tProtocol == PANASONIC) {
213  sendPanasonic(tAddress, tCommand, aNumberOfRepeats);
214 
215  } else if (tProtocol == DENON) {
216  sendDenon(tAddress, tCommand, aNumberOfRepeats);
217 
218  } else if (tProtocol == SHARP) {
219  sendSharp(tAddress, tCommand, aNumberOfRepeats);
220 
221  } else if (tProtocol == LG) {
222  sendLG(tAddress, tCommand, aNumberOfRepeats);
223 
224  } else if (tProtocol == JVC) {
225  sendJVC((uint8_t) tAddress, (uint8_t) tCommand, aNumberOfRepeats); // casts are required to specify the right function
226 
227  } else if (tProtocol == RC5) {
228  sendRC5(tAddress, tCommand, aNumberOfRepeats, !tIsRepeat); // No toggle for repeats
229 
230  } else if (tProtocol == RC6) {
231  sendRC6(tAddress, tCommand, aNumberOfRepeats, !tIsRepeat); // No toggle for repeats
232 
233  } else if (tProtocol == KASEIKYO_JVC) {
234  sendKaseikyo_JVC(tAddress, tCommand, aNumberOfRepeats);
235 
236  } else if (tProtocol == KASEIKYO_DENON) {
237  sendKaseikyo_Denon(tAddress, tCommand, aNumberOfRepeats);
238 
239  } else if (tProtocol == KASEIKYO_SHARP) {
240  sendKaseikyo_Sharp(tAddress, tCommand, aNumberOfRepeats);
241 
242  } else if (tProtocol == KASEIKYO_MITSUBISHI) {
243  sendKaseikyo_Mitsubishi(tAddress, tCommand, aNumberOfRepeats);
244 
245  } else if (tProtocol == NEC2) {
246  sendNEC2(tAddress, tCommand, aNumberOfRepeats);
247 
248  } else if (tProtocol == ONKYO) {
249  sendOnkyo(tAddress, tCommand, aNumberOfRepeats);
250 
251  } else if (tProtocol == APPLE) {
252  sendApple(tAddress, tCommand, aNumberOfRepeats);
253 
254 #if !defined(EXCLUDE_EXOTIC_PROTOCOLS)
255  } else if (tProtocol == BOSEWAVE) {
256  sendBoseWave(tCommand, aNumberOfRepeats);
257 
258  } else if (tProtocol == MAGIQUEST) {
259  // we have a 32 bit ID/address
260  sendMagiQuest(aIRSendData->decodedRawData, tCommand);
261 
262  } else if (tProtocol == FAST) {
263  // We have only 8 bit command
264  sendFAST(tCommand, aNumberOfRepeats);
265 
266  } else if (tProtocol == LEGO_PF) {
267  sendLegoPowerFunctions(tAddress, tCommand, tCommand >> 4, tIsRepeat); // send 5 autorepeats
268 #endif
269 
270  } else {
271  return 0; // Not supported by write. E.g for BANG_OLUFSEN
272  }
273  return 1;
274 }
275 
281 size_t IRsend::write(decode_type_t aProtocol, uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) {
282 
283 // switch (aProtocol) { // 26 bytes bigger than if, else if, else
284 // case NEC:
285 // sendNEC(aAddress, aCommand, aNumberOfRepeats, tSendRepeat);
286 // break;
287 // case SAMSUNG:
288 // sendSamsung(aAddress, aCommand, aNumberOfRepeats);
289 // break;
290 // case SONY:
291 // sendSony(aAddress, aCommand, aNumberOfRepeats, aIRSendData->numberOfBits);
292 // break;
293 // case PANASONIC:
294 // sendPanasonic(aAddress, aCommand, aNumberOfRepeats);
295 // break;
296 // case DENON:
297 // sendDenon(aAddress, aCommand, aNumberOfRepeats);
298 // break;
299 // case SHARP:
300 // sendSharp(aAddress, aCommand, aNumberOfRepeats);
301 // break;
302 // case JVC:
303 // sendJVC((uint8_t) aAddress, (uint8_t) aCommand, aNumberOfRepeats); // casts are required to specify the right function
304 // break;
305 // case RC5:
306 // sendRC5(aAddress, aCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
307 // break;
308 // case RC6:
309 // // No toggle for repeats// sendRC6(aAddress, aCommand, aNumberOfRepeats, !tSendRepeat); // No toggle for repeats
310 // break;
311 // default:
312 // break;
313 // }
314 
315  /*
316  * Order of protocols is in guessed relevance :-)
317  */
318  if (aProtocol == NEC) {
319  sendNEC(aAddress, aCommand, aNumberOfRepeats);
320 
321  } else if (aProtocol == SAMSUNG) {
323 
324  } else if (aProtocol == SAMSUNG48) {
326 
327  } else if (aProtocol == SAMSUNGLG) {
329 
330  } else if (aProtocol == SONY) {
332 
333  } else if (aProtocol == PANASONIC) {
335 
336  } else if (aProtocol == DENON) {
337  sendDenon(aAddress, aCommand, aNumberOfRepeats);
338 
339  } else if (aProtocol == SHARP) {
340  sendSharp(aAddress, aCommand, aNumberOfRepeats);
341 
342  } else if (aProtocol == LG) {
343  sendLG(aAddress, aCommand, aNumberOfRepeats);
344 
345  } else if (aProtocol == JVC) {
346  sendJVC((uint8_t) aAddress, (uint8_t) aCommand, aNumberOfRepeats); // casts are required to specify the right function
347 
348  } else if (aProtocol == RC5) {
349  sendRC5(aAddress, aCommand, aNumberOfRepeats, (aNumberOfRepeats > 0)); // No toggle for repeats
350 
351  } else if (aProtocol == RC6) {
352  sendRC6(aAddress, aCommand, aNumberOfRepeats, (aNumberOfRepeats > 0)); // No toggle for repeats
353 
354  } else if (aProtocol == KASEIKYO_JVC) {
356 
357  } else if (aProtocol == KASEIKYO_DENON) {
359 
360  } else if (aProtocol == KASEIKYO_SHARP) {
362 
363  } else if (aProtocol == KASEIKYO_MITSUBISHI) {
365 
366  } else if (aProtocol == NEC2) {
367  sendNEC2(aAddress, aCommand, aNumberOfRepeats);
368 
369  } else if (aProtocol == ONKYO) {
370  sendOnkyo(aAddress, aCommand, aNumberOfRepeats);
371 
372  } else if (aProtocol == APPLE) {
373  sendApple(aAddress, aCommand, aNumberOfRepeats);
374 
375 #if !defined(EXCLUDE_EXOTIC_PROTOCOLS)
376  } else if (aProtocol == BOSEWAVE) {
378 
379  } else if (aProtocol == FAST) {
380  // We have only 8 bit command
382 
383  } else if (aProtocol == LEGO_PF) {
384  sendLegoPowerFunctions(aAddress, aCommand, aCommand >> 4, (aNumberOfRepeats < 0)); // send 5 autorepeats, except for dedicated repeats
385 #endif
386 
387  } else {
388  return 0; // Not supported by write. E.g for BANG_OLUFSEN
389  }
390  return 1;
391 }
392 
393 /**********************************************************************************************************************
394  * SendRaw functions
395  **********************************************************************************************************************/
396 
401 void IRsend::sendRaw(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) {
402 // Set IR carrier frequency
403  enableIROut(aIRFrequencyKilohertz);
404 
405  /*
406  * Raw data starts with a mark.
407  */
408  for (uint_fast16_t i = 0; i < aLengthOfBuffer; i++) {
409  if (i & 1) {
410  // Odd
411  space(aBufferWithMicroseconds[i]);
412  } else {
413  mark(aBufferWithMicroseconds[i]);
414  }
415  }
416 }
417 
422 void IRsend::sendRaw(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) {
423 // Set IR carrier frequency
424  enableIROut(aIRFrequencyKilohertz);
425 
426  for (uint_fast16_t i = 0; i < aLengthOfBuffer; i++) {
427  if (i & 1) {
428  // Odd
429  space(aBufferWithTicks[i] * MICROS_PER_TICK);
430  } else {
431  mark(aBufferWithTicks[i] * MICROS_PER_TICK);
432  }
433  }
434  IRLedOff(); // Always end with the LED off
435 }
436 
441 void IRsend::sendRaw_P(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer,
442  uint_fast8_t aIRFrequencyKilohertz) {
443 #if !defined(__AVR__)
444  sendRaw(aBufferWithMicroseconds, aLengthOfBuffer, aIRFrequencyKilohertz); // Let the function work for non AVR platforms
445 #else
446 // Set IR carrier frequency
447  enableIROut(aIRFrequencyKilohertz);
448  /*
449  * Raw data starts with a mark
450  */
451  for (uint_fast16_t i = 0; i < aLengthOfBuffer; i++) {
452  auto duration = pgm_read_word(&aBufferWithMicroseconds[i]);
453  if (i & 1) {
454  // Odd
455  space(duration);
456 # if defined(LOCAL_DEBUG)
457  Serial.print(F("S="));
458 # endif
459  } else {
460  mark(duration);
461 # if defined(LOCAL_DEBUG)
462  Serial.print(F("M="));
463 # endif
464  }
465 # if defined(LOCAL_DEBUG)
466  Serial.println(duration);
467 # endif
468  }
469 #endif
470 }
471 
476 void IRsend::sendRaw_P(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) {
477 #if !defined(__AVR__)
478  sendRaw(aBufferWithTicks, aLengthOfBuffer, aIRFrequencyKilohertz); // Let the function work for non AVR platforms
479 #else
480 // Set IR carrier frequency
481  enableIROut(aIRFrequencyKilohertz);
482 
483  uint_fast16_t duration;
484  for (uint_fast16_t i = 0; i < aLengthOfBuffer; i++) {
485  duration = pgm_read_byte(&aBufferWithTicks[i]) * (uint_fast16_t) MICROS_PER_TICK;
486  if (i & 1) {
487  // Odd
488  space(duration);
489 # if defined(LOCAL_DEBUG)
490  Serial.print(F("S="));
491 # endif
492  } else {
493  mark(duration);
494 # if defined(LOCAL_DEBUG)
495  Serial.print(F("M="));
496 # endif
497  }
498  }
499  IRLedOff(); // Always end with the LED off
500 # if defined(LOCAL_DEBUG)
501  Serial.println(duration);
502 # endif
503 #endif
504 }
505 
506 /**********************************************************************************************************************
507  * Core send function
508  **********************************************************************************************************************/
517 void IRsend::sendPulseDistanceWidthData(uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros,
518  uint16_t aZeroSpaceMicros, IRRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags) {
519 
520 #if defined(LOCAL_DEBUG)
521  Serial.print(aData, HEX);
522  Serial.print('|');
523  Serial.println(aNumberOfBits);
524  Serial.flush();
525 #endif
526 
527  // For MSBFirst, send data from MSB to LSB until mask bit is shifted out
528  IRRawDataType tMask = 1ULL << (aNumberOfBits - 1);
529  for (uint_fast8_t i = aNumberOfBits; i > 0; i--) {
530  if (((aFlags & PROTOCOL_IS_MSB_MASK) && (aData & tMask)) || (!(aFlags & PROTOCOL_IS_MSB_MASK) && (aData & 1))) {
531 #if defined(LOCAL_TRACE)
532  Serial.print('1');
533 #endif
534  mark(aOneMarkMicros);
535  space(aOneSpaceMicros);
536  } else {
537 #if defined(LOCAL_TRACE)
538  Serial.print('0');
539 #endif
540  mark(aZeroMarkMicros);
541  space(aZeroSpaceMicros);
542  }
543  if (aFlags & PROTOCOL_IS_MSB_MASK) {
544  tMask >>= 1;
545  } else {
546  aData >>= 1;
547  }
548  }
549  /*
550  * Stop bit is sent for all pulse distance protocols i.e. aOneSpaceMicros != aZeroSpaceMicros.
551  * Therefore it is not sent for Sony :-)
552  * For sending from an array, no intermediate stop bit must be sent for all but last data chunk.
553  */
554  if ((!(aFlags & SUPPRESS_STOP_BIT)) && (abs(aOneSpaceMicros - aZeroSpaceMicros) > (aOneSpaceMicros / 4))) {
555  // Send stop bit here
556 #if defined(LOCAL_TRACE)
557  Serial.print('S');
558 #endif
559  mark(aOneMarkMicros); // Use aOneMarkMicros for stop bits. This seems to be correct for all protocols :-)
560  }
561 #if defined(LOCAL_TRACE)
562  Serial.println();
563 #endif
564 }
565 
566 /**********************************************************************************************************************
567  * Stubs for core send function with PulseDistanceWidthProtocolConstants parameter
568  **********************************************************************************************************************/
569 
579  uint_fast8_t aNumberOfBits) {
580 
582  aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros,
583  aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, aData, aNumberOfBits, aProtocolConstants->Flags);
584 }
585 
587  uint_fast8_t aNumberOfBits) {
588 
589  PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants;
590  memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM,
591  sizeof(tTemporaryPulseDistanceWidthProtocolConstants));
592  sendPulseDistanceWidthData(&tTemporaryPulseDistanceWidthProtocolConstants, aData, aNumberOfBits);
593 }
594 
595 /**********************************************************************************************************************
596  * Send functions with detailed parameters
597  **********************************************************************************************************************/
598 
609 void IRsend::sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros,
610  uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, IRRawDataType aData,
611  uint_fast8_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats,
612  void (*aSpecialSendRepeatFunction)()) {
613 
614  if (aNumberOfRepeats < 0) {
615  if (aSpecialSendRepeatFunction != nullptr) {
616  aSpecialSendRepeatFunction();
617  return;
618  } else {
619  aNumberOfRepeats = 0; // send a plain frame as repeat
620  }
621  }
622 
623  // Set IR carrier frequency
624  enableIROut(aFrequencyKHz);
625 
626  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
627  while (tNumberOfCommands > 0) {
628  unsigned long tStartOfFrameMillis = millis();
629 
630  if (tNumberOfCommands < ((uint_fast8_t) aNumberOfRepeats + 1) && aSpecialSendRepeatFunction != nullptr) {
631  // send special repeat
632  aSpecialSendRepeatFunction();
633  } else {
634  // Header and regular frame
635  mark(aHeaderMarkMicros);
636  space(aHeaderSpaceMicros);
637  sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aData, aNumberOfBits,
638  aFlags);
639  }
640 
641  tNumberOfCommands--;
642  // skip last delay!
643  if (tNumberOfCommands > 0) {
644  /*
645  * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration.
646  */
647  auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
648  if (aRepeatPeriodMillis > tFrameDurationMillis) {
649  delay(aRepeatPeriodMillis - tFrameDurationMillis);
650  }
651  }
652  }
653 }
654 
655 void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros,
656  uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros,
657  IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis,
658  int_fast8_t aNumberOfRepeats) {
659 
660  // Set IR carrier frequency
661  enableIROut(aFrequencyKHz);
662 
663  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
664  uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_RAW_DATA_TYPE) + 1;
665 
666 #if defined(LOCAL_DEBUG)
667  // fist data
668  Serial.print(F("Data[0]=0x"));
669  Serial.print(aDecodedRawDataArray[0], HEX);
670  if (tNumberOf32Or64BitChunks > 1) {
671  Serial.print(F(" Data[1]=0x"));
672  Serial.print(aDecodedRawDataArray[1], HEX);
673  }
674  Serial.print(F(" #="));
675  Serial.println(aNumberOfBits);
676  Serial.flush();
677 #endif
678 
679  while (tNumberOfCommands > 0) {
680  unsigned long tStartOfFrameMillis = millis();
681 
682  // Header
683  mark(aHeaderMarkMicros);
684  space(aHeaderSpaceMicros);
685 
686  for (uint_fast8_t i = 0; i < tNumberOf32Or64BitChunks; ++i) {
687  uint8_t tNumberOfBitsForOneSend;
688 
689  // Manage stop bit
690  uint8_t tFlags;
691  if (i == (tNumberOf32Or64BitChunks - 1)) {
692  // End of data
693  tNumberOfBitsForOneSend = aNumberOfBits;
694  tFlags = aFlags;
695  } else {
696  // intermediate data
697  tNumberOfBitsForOneSend = BITS_IN_RAW_DATA_TYPE;
698  tFlags = aFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data
699  }
700 
701  sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aDecodedRawDataArray[i],
702  tNumberOfBitsForOneSend, tFlags);
703  aNumberOfBits -= BITS_IN_RAW_DATA_TYPE;
704  }
705 
706  tNumberOfCommands--;
707  // skip last delay!
708  if (tNumberOfCommands > 0) {
709  /*
710  * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration.
711  */
712  auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
713  if (aRepeatPeriodMillis > tFrameDurationMillis) {
714  delay(aRepeatPeriodMillis - tFrameDurationMillis);
715  }
716  }
717  }
718 }
719 
720 void IRsend::sendPulseDistanceWidthFromPGMArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros,
721  uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros,
722  IRRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis,
723  int_fast8_t aNumberOfRepeats) {
724 
725  // Set IR carrier frequency
726  enableIROut(aFrequencyKHz);
727 
728  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
729  uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_RAW_DATA_TYPE) + 1;
730 
731 #if defined(LOCAL_DEBUG)
732  // fist data
733  Serial.print(F("Data[0]=0x"));
734  Serial.print(aDecodedRawDataPGMArray[0], HEX);
735  if (tNumberOf32Or64BitChunks > 1) {
736  Serial.print(F(" Data[1]=0x"));
737  Serial.print(aDecodedRawDataPGMArray[1], HEX);
738  }
739  Serial.print(F(" #="));
740  Serial.println(aNumberOfBits);
741  Serial.flush();
742 #endif
743 
744  while (tNumberOfCommands > 0) {
745  unsigned long tStartOfFrameMillis = millis();
746 
747  // Header
748  mark(aHeaderMarkMicros);
749  space(aHeaderSpaceMicros);
750 
751  for (uint_fast8_t i = 0; i < tNumberOf32Or64BitChunks; ++i) {
752  uint8_t tNumberOfBitsForOneSend;
753 
754  // Manage stop bit
755  uint8_t tFlags;
756  if (i == (tNumberOf32Or64BitChunks - 1)) {
757  // End of data
758  tNumberOfBitsForOneSend = aNumberOfBits;
759  tFlags = aFlags;
760  } else {
761  // intermediate data
762  tNumberOfBitsForOneSend = BITS_IN_RAW_DATA_TYPE;
763  tFlags = aFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data
764  }
765 
766  IRRawDataType tDecodedRawData;
767 #if (__INT_WIDTH__ < 32)
768  tDecodedRawData = pgm_read_dword(&aDecodedRawDataPGMArray[i]); // pgm_read_dword reads 32 bit on AVR
769 #else
770  tDecodedRawData = aDecodedRawDataPGMArray[i]; // assume non Harvard architecture here
771 #endif
772  sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, tDecodedRawData,
773  tNumberOfBitsForOneSend, tFlags);
774  aNumberOfBits -= BITS_IN_RAW_DATA_TYPE;
775  }
776 
777  tNumberOfCommands--;
778  // skip last delay!
779  if (tNumberOfCommands > 0) {
780  /*
781  * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration.
782  */
783  auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
784  if (aRepeatPeriodMillis > tFrameDurationMillis) {
785  delay(aRepeatPeriodMillis - tFrameDurationMillis);
786  }
787  }
788  }
789 }
790 
791 /**********************************************************************************************************************
792  * Stubs for send functions
793  **********************************************************************************************************************/
794 
802 void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, DistanceWidthTimingInfoStruct *aDistanceWidthTimingInfo,
803  IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis,
804  int_fast8_t aNumberOfRepeats) {
805  sendPulseDistanceWidthFromArray(aFrequencyKHz, aDistanceWidthTimingInfo->HeaderMarkMicros,
806  aDistanceWidthTimingInfo->HeaderSpaceMicros, aDistanceWidthTimingInfo->OneMarkMicros,
807  aDistanceWidthTimingInfo->OneSpaceMicros, aDistanceWidthTimingInfo->ZeroMarkMicros,
808  aDistanceWidthTimingInfo->ZeroSpaceMicros, aDecodedRawDataArray, aNumberOfBits, aFlags, aRepeatPeriodMillis,
810 }
811 
812 void IRsend::sendPulseDistanceWidthFromArray_P(uint_fast8_t aFrequencyKHz,
813  DistanceWidthTimingInfoStruct const *aDistanceWidthTimingInfoPGM, IRRawDataType *aDecodedRawDataArray,
814  uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) {
815 
816  DistanceWidthTimingInfoStruct tTemporaryDistanceWidthTimingInfo;
817  memcpy_P(&tTemporaryDistanceWidthTimingInfo, aDistanceWidthTimingInfoPGM, sizeof(tTemporaryDistanceWidthTimingInfo));
818  sendPulseDistanceWidthFromArray(aFrequencyKHz, &tTemporaryDistanceWidthTimingInfo, aDecodedRawDataArray, aNumberOfBits, aFlags,
819  aRepeatPeriodMillis, aNumberOfRepeats);
820 }
821 
822 /**********************************************************************************************************************
823  * Send functions with PulseDistanceWidthProtocolConstants parameter
824  **********************************************************************************************************************/
834  uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats) {
835 
836 #if defined(LOCAL_DEBUG)
837  Serial.print(F("Data=0x"));
838  Serial.print(aData, HEX);
839  Serial.print(F(" #="));
840  Serial.println(aNumberOfBits);
841  Serial.flush();
842 #endif
843 
844  if (aNumberOfRepeats < 0) {
845  if (aProtocolConstants->SpecialSendRepeatFunction != nullptr) {
846  /*
847  * Send only a special repeat and return
848  */
849  aProtocolConstants->SpecialSendRepeatFunction();
850  return;
851  } else {
852  // Send only one plain frame (as repeat)
853  aNumberOfRepeats = 0;
854  }
855  }
856 
857  // Set IR carrier frequency
858  enableIROut(aProtocolConstants->FrequencyKHz);
859 
860  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
861  while (tNumberOfCommands > 0) {
862  unsigned long tStartOfFrameMillis = millis();
863 
864  if (tNumberOfCommands < ((uint_fast8_t) aNumberOfRepeats + 1) && aProtocolConstants->SpecialSendRepeatFunction != nullptr) {
865  // send special repeat, if specified and we are not in the first loop
866  aProtocolConstants->SpecialSendRepeatFunction();
867  } else {
868  /*
869  * Send Header and regular frame
870  */
871  mark(aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros);
872  space(aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros);
873  sendPulseDistanceWidthData(aProtocolConstants, aData, aNumberOfBits);
874  }
875 
876  tNumberOfCommands--;
877  // skip last delay!
878  if (tNumberOfCommands > 0) {
879  auto tCurrentFrameDurationMillis = millis() - tStartOfFrameMillis;
880  /*
881  * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration.
882  */
883  if (aProtocolConstants->RepeatPeriodMillis > tCurrentFrameDurationMillis) {
884  delay(aProtocolConstants->RepeatPeriodMillis - tCurrentFrameDurationMillis);
885  }
886  }
887  }
888 }
889 
900  IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) {
901 
902 // Calling sendPulseDistanceWidthFromArray() costs 68 bytes program memory compared to the implementation below
903 // sendPulseDistanceWidthFromArray(aProtocolConstants->FrequencyKHz, aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros,
904 // aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros,
905 // aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros,
906 // aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros,
907 // aDecodedRawDataArray, aNumberOfBits, aProtocolConstants->Flags, aProtocolConstants->RepeatPeriodMillis,
908 // aNumberOfRepeats);
909  // Set IR carrier frequency
910  enableIROut(aProtocolConstants->FrequencyKHz);
911 
912  uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_RAW_DATA_TYPE) + 1;
913 
914 #if defined(LOCAL_DEBUG)
915  // fist data
916  Serial.print(F("Data[0]=0x"));
917  Serial.print(aDecodedRawDataArray[0], HEX);
918  if (tNumberOf32Or64BitChunks > 1) {
919  Serial.print(F(" Data[1]=0x"));
920  Serial.print(aDecodedRawDataArray[1], HEX);
921  }
922  Serial.print(F(" #="));
923  Serial.println(aNumberOfBits);
924  Serial.flush();
925 #endif
926 
927  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
928  while (tNumberOfCommands > 0) {
929  auto tStartOfFrameMillis = millis();
930  auto tNumberOfBits = aNumberOfBits; // refresh value for repeats
931 
932  // Header
933  mark(aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros);
934  space(aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros);
935  uint8_t tOriginalFlags = aProtocolConstants->Flags;
936 
937  for (uint_fast8_t i = 0; i < tNumberOf32Or64BitChunks; ++i) {
938  uint8_t tNumberOfBitsForOneSend;
939 
940  uint8_t tFlags;
941  if (i == (tNumberOf32Or64BitChunks - 1)) {
942  // End of data
943  tNumberOfBitsForOneSend = tNumberOfBits;
944  tFlags = tOriginalFlags;
945  } else {
946  // intermediate data
947  tNumberOfBitsForOneSend = BITS_IN_RAW_DATA_TYPE;
948  tFlags = tOriginalFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data
949  }
950 
952  aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros,
953  aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros,
954  aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, aDecodedRawDataArray[i], tNumberOfBitsForOneSend,
955  tFlags);
956  tNumberOfBits -= BITS_IN_RAW_DATA_TYPE;
957  }
958 
959  tNumberOfCommands--;
960  // skip last delay!
961  if (tNumberOfCommands > 0) {
962  /*
963  * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration.
964  */
965  auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
966  if (aProtocolConstants->RepeatPeriodMillis > tFrameDurationMillis) {
967  delay(aProtocolConstants->RepeatPeriodMillis - tFrameDurationMillis);
968  }
969  }
970  }
971 }
972 
974  IRRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) {
975 
976 // Calling sendPulseDistanceWidthFromArray() costs 68 bytes program memory compared to the implementation below
977 // sendPulseDistanceWidthFromArray(aProtocolConstants->FrequencyKHz, aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros,
978 // aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros,
979 // aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros,
980 // aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros,
981 // aDecodedRawDataArray, aNumberOfBits, aProtocolConstants->Flags, aProtocolConstants->RepeatPeriodMillis,
982 // aNumberOfRepeats);
983  // Set IR carrier frequency
984  enableIROut(aProtocolConstants->FrequencyKHz);
985 
986  uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_RAW_DATA_TYPE) + 1;
987 
988 #if defined(LOCAL_DEBUG)
989  // fist data
990  Serial.print(F("Data[0]=0x"));
991  Serial.print(aDecodedRawDataPGMArray[0], HEX);
992  if (tNumberOf32Or64BitChunks > 1) {
993  Serial.print(F(" Data[1]=0x"));
994  Serial.print(aDecodedRawDataPGMArray[1], HEX);
995  }
996  Serial.print(F(" #="));
997  Serial.println(aNumberOfBits);
998  Serial.flush();
999 #endif
1000 
1001  uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
1002  while (tNumberOfCommands > 0) {
1003  auto tStartOfFrameMillis = millis();
1004  auto tNumberOfBits = aNumberOfBits; // refresh value for repeats
1005 
1006  // Header
1007  mark(aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros);
1008  space(aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros);
1009  uint8_t tOriginalFlags = aProtocolConstants->Flags;
1010 
1011  for (uint_fast8_t i = 0; i < tNumberOf32Or64BitChunks; ++i) {
1012  uint8_t tNumberOfBitsForOneSend;
1013 
1014  uint8_t tFlags;
1015  if (i == (tNumberOf32Or64BitChunks - 1)) {
1016  // End of data
1017  tNumberOfBitsForOneSend = tNumberOfBits;
1018  tFlags = tOriginalFlags;
1019  } else {
1020  // intermediate data
1021  tNumberOfBitsForOneSend = BITS_IN_RAW_DATA_TYPE;
1022  tFlags = tOriginalFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data
1023  }
1024 
1025  IRRawDataType tDecodedRawData;
1026 #if (__INT_WIDTH__ < 32)
1027  tDecodedRawData = pgm_read_dword(&aDecodedRawDataPGMArray[i]); // pgm_read_dword reads 32 bit on AVR
1028 #else
1029  tDecodedRawData = aDecodedRawDataPGMArray[i]; // assume non Harvard architecture here
1030 #endif
1032  aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros,
1033  aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros,
1034  aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, tDecodedRawData, tNumberOfBitsForOneSend, tFlags);
1035  tNumberOfBits -= BITS_IN_RAW_DATA_TYPE;
1036  }
1037 
1038  tNumberOfCommands--;
1039  // skip last delay!
1040  if (tNumberOfCommands > 0) {
1041  /*
1042  * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration.
1043  */
1044  auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
1045  if (aProtocolConstants->RepeatPeriodMillis > tFrameDurationMillis) {
1046  delay(aProtocolConstants->RepeatPeriodMillis - tFrameDurationMillis);
1047  }
1048  }
1049  }
1050 }
1051 
1052 /**********************************************************************************************************************
1053  * Stubs for send functions with PulseDistanceWidthProtocolConstants parameter
1054  **********************************************************************************************************************/
1055 
1057  IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) {
1058 
1059  PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants;
1060  memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM,
1061  sizeof(tTemporaryPulseDistanceWidthProtocolConstants));
1062  sendPulseDistanceWidthFromArray(&tTemporaryPulseDistanceWidthProtocolConstants, aDecodedRawDataArray, aNumberOfBits,
1064 }
1066  IRRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) {
1067 
1068  PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants;
1069  memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM,
1070  sizeof(tTemporaryPulseDistanceWidthProtocolConstants));
1071  sendPulseDistanceWidthFromPGMArray(&tTemporaryPulseDistanceWidthProtocolConstants, aDecodedRawDataPGMArray, aNumberOfBits,
1073 }
1074 
1076  uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats) {
1077  PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants;
1078  memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM,
1079  sizeof(tTemporaryPulseDistanceWidthProtocolConstants));
1080  sendPulseDistanceWidth(&tTemporaryPulseDistanceWidthProtocolConstants, aData, aNumberOfBits, aNumberOfRepeats);
1081 }
1082 
1093 void IRsend::sendBiphaseData(uint16_t aBiphaseTimeUnit, uint32_t aData, uint_fast8_t aNumberOfBits) {
1094 
1095  IR_TRACE_PRINT(F("0x"));
1096  IR_TRACE_PRINT(aData, HEX);
1097 
1098 #if defined(LOCAL_TRACE)
1099  Serial.print('S');
1100 #endif
1101 
1102 // Data - Biphase code MSB first
1103 // prepare for start with sending the start bit, which is 1
1104  uint32_t tMask = 1UL << aNumberOfBits; // mask is now set for the virtual start bit
1105  uint_fast8_t tLastBitValue = 1; // Start bit is a 1
1106  bool tNextBitIsOne = 1; // Start bit is a 1
1107  for (uint_fast8_t i = aNumberOfBits + 1; i > 0; i--) {
1108  bool tCurrentBitIsOne = tNextBitIsOne;
1109  tMask >>= 1;
1110  tNextBitIsOne = ((aData & tMask) != 0) || (i == 1); // true for last bit to avoid extension of mark
1111  if (tCurrentBitIsOne) {
1112 #if defined(LOCAL_TRACE)
1113  Serial.print('1');
1114 #endif
1115  space(aBiphaseTimeUnit);
1116  if (tNextBitIsOne) {
1117  mark(aBiphaseTimeUnit);
1118  } else {
1119  // if next bit is 0, extend the current mark in order to generate a continuous signal without short breaks
1120  mark(2 * aBiphaseTimeUnit);
1121  }
1122  tLastBitValue = 1;
1123 
1124  } else {
1125 #if defined(LOCAL_TRACE)
1126  Serial.print('0');
1127 #endif
1128  if (!tLastBitValue) {
1129  mark(aBiphaseTimeUnit);
1130  }
1131  space(aBiphaseTimeUnit);
1132  tLastBitValue = 0;
1133  }
1134  }
1135  IR_TRACE_PRINTLN();
1136 }
1137 
1153 void IRsend::mark(uint16_t aMarkMicros) {
1154 
1155 #if defined(SEND_PWM_BY_TIMER) || defined(USE_NO_SEND_PWM)
1156 # if defined(LED_SEND_FEEDBACK_CODE)
1157  setFeedbackLED(true);
1158 # endif
1159 #endif
1160 
1161 #if defined(SEND_PWM_BY_TIMER)
1162  /*
1163  * Generate hardware PWM signal
1164  */
1165  enableSendPWMByTimer(); // Enable timer or ledcWrite() generated PWM output
1166  customDelayMicroseconds(aMarkMicros);
1167  IRLedOff(); // disables hardware PWM and manages feedback LED
1168  return;
1169 
1170 #elif defined(USE_NO_SEND_PWM)
1171  /*
1172  * Here we generate no carrier PWM, just simulate an active low receiver signal.
1173  */
1174 # if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN)
1175  // Here we have no hardware supported Open Drain outputs, so we must mimicking it
1176  pinModeFast(sendPin, OUTPUT); // active state for mimicking open drain
1177 # elif defined(USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM) || defined(USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN) // USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN is old and deprecated
1178  digitalWriteFast(sendPin, HIGH); // Set output to active high.
1179 # else
1180  digitalWriteFast(sendPin, LOW); // Set output to active low.
1181 # endif
1182 
1183  customDelayMicroseconds(aMarkMicros);
1184  IRLedOff();
1185 # if defined(LED_SEND_FEEDBACK_CODE)
1186  setFeedbackLED(false);
1187  return;
1188 # endif
1189 
1190 #else // defined(SEND_PWM_BY_TIMER)
1191 
1192  unsigned long tMicrosOfEndOfNextPWMPause = micros();
1193 # if defined(LED_SEND_FEEDBACK_CODE)
1194  unsigned long tStartMicros = tMicrosOfEndOfNextPWMPause + (136 / CLOCKS_PER_MICRO); // To compensate for call duration and activating of LED
1195  bool tFeedbackLedIsActive = false;
1196 #else
1197  unsigned long tStartMicros = tMicrosOfEndOfNextPWMPause + (112 / CLOCKS_PER_MICRO); // To compensate for call duration - 112 is an empirical value
1198 #endif
1199 
1200  /***************************************************************************************************
1201  * Generate the IR PWM with 30% duty cycle with a frequency of e.g. 38 kHz by software / bit banging
1202  **************************************************************************************************/
1203  do {
1204 // digitalToggleFast(_IR_TIMING_TEST_PIN);
1205  /*****************************************
1206  * Output the PWM pulse - IR LED is active
1207  ****************************************/
1208  noInterrupts(); // do not let interrupts extend the short on period
1209 # if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) || defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN)
1210 # if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) || defined(OUTPUT_OPEN_DRAIN)
1211  if (__builtin_constant_p(sendPin)) {
1212  digitalWriteFast(sendPin, LOW); // set output to active low. Also applicable for pin with mode OUTPUT_OPEN_DRAIN :-)
1213  } else {
1214  digitalWrite(sendPin, LOW);
1215  }
1216 # else
1217  pinModeFast(sendPin, OUTPUT); // active state for mimicking open drain
1218 # endif
1219 # else
1220  // 3.5 us from FeedbackLed on to pin setting. 5.7 us from call of mark() to pin setting incl. setting of feedback pin.
1221  // 4.3 us from do{ to pin setting if sendPin is no constant
1222  // check must be here because of MegaTinyCore and its badArg() check
1223  if (__builtin_constant_p(sendPin)) {
1224  digitalWriteFast(sendPin, HIGH);
1225  } else {
1226  digitalWrite(sendPin, HIGH);
1227  }
1228 # endif
1229  /*
1230  * Timing for the on time of the e.g. 38 kHz signal.
1231  * On time is 8 us for 30% duty cycle. This is normally implemented by a blocking wait.
1232  */
1233  delayMicroseconds (periodOnTimeMicros);
1234 
1235  /*******************************************
1236  * Output the PWM pause - IR LED is inactive
1237  ******************************************/
1238 # if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) || defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN)
1239 # if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) || defined(OUTPUT_OPEN_DRAIN)
1240  if (__builtin_constant_p(sendPin)) {
1241  digitalWriteFast(sendPin, HIGH); // Set output to inactive high. Also applicable for pin with mode OUTPUT_OPEN_DRAIN
1242  } else {
1243  digitalWrite(sendPin, HIGH);
1244  }
1245 # else
1246  pinModeFast(sendPin, INPUT); // to mimic the open drain inactive state
1247 # endif
1248 
1249 # else
1250  if (__builtin_constant_p(sendPin)) {
1251  digitalWriteFast(sendPin, LOW);
1252  } else {
1253  digitalWrite(sendPin, LOW);
1254  }
1255 # endif
1256  /*
1257  * Enable interrupts at start of the longer off period. Required at least to keep micros correct.
1258  * If receive interrupt is still active, it takes 3.4 us from now until receive ISR is active (for 7 us + pop's)
1259  */
1260  interrupts();
1261 
1262 # if defined(LED_SEND_FEEDBACK_CODE)
1263  /*
1264  * Delayed call of setFeedbackLED() to get better startup timing, especially required for consecutive marks
1265  */
1266  if (!tFeedbackLedIsActive) {
1267  tFeedbackLedIsActive = true; // do it only once
1268  setFeedbackLED(true);
1269  }
1270 # endif
1271  /********************************************************************************************************************************
1272  * Check for end of the PWM pause with micros() < tMicrosOfEndOfNextPWMPause.
1273  * This generates the timing for the transmit frequency e.g. 38 kHz
1274  * Measured delta between pause duration values are 8 us for a 16 MHz Uno (from 15 to 23), if interrupts are disabled below
1275  * Minimal pause duration is 5.2 us
1276  *******************************************************************************************************************************/
1277  tMicrosOfEndOfNextPWMPause += periodTimeMicros;
1278 #if defined(__AVR__) // micros() for STM sometimes give decreasing values if interrupts are disabled. See https://github.com/stm32duino/Arduino_Core_STM32/issues/1680
1279  noInterrupts(); // disable interrupts (especially the 20 us receive interrupts) only at start of the PWM pause. Otherwise it may extend the pause too much.
1280 #endif
1281  unsigned long tMicros;
1282  do {
1283 #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
1284  digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles
1285 #endif
1286  /*
1287  * For AVR @16MHz we have only 4 us resolution.
1288  * The duration of the micros() call itself is 3 us.
1289  * It takes 0.9 us from signal going low to here.
1290  * The rest of the loop takes 1.2 us
1291  */
1292 #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
1293  digitalWriteFast(_IR_TIMING_TEST_PIN, LOW); // 2 clock cycles
1294 #endif
1295 
1296  /*************************************************
1297  * Check for end of mark duration / PWM generation
1298  ************************************************/
1299  tMicros = micros();
1300  uint16_t tDeltaMicros = tMicros - tStartMicros;
1301  // reset feedback led in the last pause before end
1302 // tDeltaMicros += (160 / CLOCKS_PER_MICRO); // adding this once increases program size, so do it below !
1303  if (tDeltaMicros >= aMarkMicros) {
1304 #if defined(LED_SEND_FEEDBACK_CODE)
1305  setFeedbackLED(false);
1306 #endif
1307 #if defined(__AVR__)
1308  interrupts();
1309 #endif
1310  return;
1311  }
1312  } while (tMicros < tMicrosOfEndOfNextPWMPause); // = End of one PWM period
1313  } while (true);
1314 # endif
1315 }
1316 
1323 #if defined(SEND_PWM_BY_TIMER)
1324  disableSendPWMByTimer(); // Disable PWM output
1325 #elif defined(USE_NO_SEND_PWM)
1326 # if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN)
1327  digitalWriteFast(sendPin, LOW); // prepare for all next active states.
1328  pinModeFast(sendPin, INPUT);// inactive state for open drain
1329 # elif defined(USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM) || defined(USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN) // USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN is old and deprecated
1330  digitalWriteFast(sendPin, LOW); // Set output to inactive low.
1331 # else
1332  digitalWriteFast(sendPin, HIGH); // Set output to inactive high.
1333 # endif
1334 #else
1335 # if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) || defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN)
1336 # if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) || defined(OUTPUT_OPEN_DRAIN)
1337  if (__builtin_constant_p(sendPin)) {
1338  digitalWriteFast(sendPin, HIGH); // set output to inactive high.
1339  } else {
1340  digitalWrite(sendPin, HIGH);
1341  }
1342 # else
1343  pinModeFast(sendPin, INPUT); // inactive state to mimic open drain
1344 # endif
1345 # else
1346  if (__builtin_constant_p(sendPin)) {
1347  digitalWriteFast(sendPin, LOW); // set output to active low.
1348  } else {
1349  digitalWrite(sendPin, LOW);
1350  }
1351 # endif
1352 #endif
1353 
1354 #if defined(LED_SEND_FEEDBACK_CODE)
1355  setFeedbackLED(false);
1356 #endif
1357 }
1358 
1364 void IRsend::space(uint16_t aSpaceMicros) {
1365  customDelayMicroseconds(aSpaceMicros);
1366 }
1367 
1372 void IRsend::customDelayMicroseconds(unsigned long aMicroseconds) {
1373 #if defined(ESP32) || defined(ESP8266)
1374  // from https://github.com/crankyoldgit/IRremoteESP8266/blob/00b27cc7ea2e7ac1e48e91740723c805a38728e0/src/IRsend.cpp#L123
1375  // Invoke a delay(), where possible, to avoid triggering the WDT.
1376  // see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/1114 for the reason of checking for > 16383)
1377  // delayMicroseconds() is only accurate to 16383 us. Ref: https://www.arduino.cc/en/Reference/delayMicroseconds
1378  if (aMicroseconds > 16383) {
1379  delay(aMicroseconds / 1000UL); // Delay for as many whole milliseconds as we can.
1380  // Delay the remaining sub-millisecond.
1381  delayMicroseconds(static_cast<uint16_t>(aMicroseconds % 1000UL));
1382  } else {
1383  delayMicroseconds(aMicroseconds);
1384  }
1385 #else
1386 
1387 # if defined(__AVR__)
1388  unsigned long start = micros() - (64 / clockCyclesPerMicrosecond()); // - (64 / clockCyclesPerMicrosecond()) for reduced resolution and additional overhead
1389 # else
1390  unsigned long start = micros();
1391 # endif
1392 // overflow invariant comparison :-)
1393  while (micros() - start < aMicroseconds) {
1394  }
1395 #endif
1396 }
1397 
1404 void IRsend::enableIROut(uint_fast8_t aFrequencyKHz) {
1405 #if defined(SEND_PWM_BY_TIMER)
1406  timerConfigForSend(aFrequencyKHz); // must set output pin mode and disable receive interrupt if required, e.g. uses the same resource
1407 
1408 #elif defined(USE_NO_SEND_PWM)
1409  (void) aFrequencyKHz;
1410 
1411 #else
1412  periodTimeMicros = (1000U + (aFrequencyKHz / 2)) / aFrequencyKHz; // rounded value -> 26 for 38.46 kHz, 27 for 37.04 kHz, 25 for 40 kHz.
1413 # if defined(IR_SEND_PIN)
1414  periodOnTimeMicros = (((periodTimeMicros * IR_SEND_DUTY_CYCLE_PERCENT) + 50) / 100U); // +50 for rounding -> 830/100 for 30% and 16 MHz
1415 # else
1416 // Heuristics! We require a nanosecond correction for "slow" digitalWrite() functions
1417  periodOnTimeMicros = (((periodTimeMicros * IR_SEND_DUTY_CYCLE_PERCENT) + 50 - (PULSE_CORRECTION_NANOS / 10)) / 100U); // +50 for rounding -> 530/100 for 30% and 16 MHz
1418 # endif
1419 #endif // defined(SEND_PWM_BY_TIMER)
1420 
1421 #if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && defined(OUTPUT_OPEN_DRAIN) // the mode INPUT for mimicking open drain is set at IRLedOff()
1422 # if defined(IR_SEND_PIN)
1423  pinModeFast(IR_SEND_PIN, OUTPUT_OPEN_DRAIN);
1424 # else
1425  pinModeFast(sendPin, OUTPUT_OPEN_DRAIN);
1426 # endif
1427 #else
1428 
1429 // For Non AVR platforms pin mode for SEND_PWM_BY_TIMER must be handled by the timerConfigForSend() function
1430 // because ESP 2.0.2 ledcWrite does not work if pin mode is set, and RP2040 requires gpio_set_function(IR_SEND_PIN, GPIO_FUNC_PWM);
1431 # if defined(__AVR__) || !defined(SEND_PWM_BY_TIMER)
1432 # if defined(IR_SEND_PIN)
1433  pinModeFast(IR_SEND_PIN, OUTPUT);
1434 # else
1435  if (__builtin_constant_p(sendPin)) {
1436  pinModeFast(sendPin, OUTPUT);
1437  } else {
1438  pinMode(sendPin, OUTPUT);
1439  }
1440 # endif
1441 # endif
1442 #endif // defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN)
1443 }
1444 
1445 #if defined(SEND_PWM_BY_TIMER)
1446 // Used for Bang&Olufsen
1447 void IRsend::enableHighFrequencyIROut(uint_fast16_t aFrequencyKHz) {
1448  timerConfigForSend(aFrequencyKHz); // must set output pin mode and disable receive interrupt if required, e.g. uses the same resource
1449  // For Non AVR platforms pin mode for SEND_PWM_BY_TIMER must be handled by the timerConfigForSend() function
1450  // because ESP 2.0.2 ledcWrite does not work if pin mode is set, and RP2040 requires gpio_set_function(IR_SEND_PIN, GPIO_FUNC_PWM);
1451 # if defined(__AVR__)
1452 # if defined(IR_SEND_PIN)
1453  pinModeFast(IR_SEND_PIN, OUTPUT);
1454 # else
1455  pinModeFast(sendPin, OUTPUT);
1456 # endif
1457 # endif
1458 }
1459 #endif
1460 
1462  return PULSE_CORRECTION_NANOS;
1463 }
1464 
1466 #if defined(_IR_MEASURE_TIMING)
1467 #undef _IR_MEASURE_TIMING
1468 #endif
1469 #if defined(LOCAL_TRACE)
1470 #undef LOCAL_TRACE
1471 #endif
1472 #if defined(LOCAL_DEBUG)
1473 #undef LOCAL_DEBUG
1474 #endif
1475 #endif // _IR_SEND_HPP
IRData::address
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
Definition: IRremoteInt.h:152
SUPPRESS_STOP_BIT
#define SUPPRESS_STOP_BIT
Definition: IRProtocol.h:177
MICROS_PER_TICK
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Definition: IRremote.hpp:207
BITS_IN_RAW_DATA_TYPE
#define BITS_IN_RAW_DATA_TYPE
Definition: IRremoteInt.h:106
ONKYO
@ ONKYO
Definition: IRProtocol.h:104
DistanceWidthTimingInfoStruct::HeaderMarkMicros
uint16_t HeaderMarkMicros
Definition: IRProtocol.h:135
IRsend::sendApple
void sendApple(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
Apple: Send NEC with fixed 16 bit Apple address 0x87EE.
Definition: ir_NEC.hpp:212
IRsend::sendMagiQuest
void sendMagiQuest(uint32_t aWandId, uint16_t aMagnitude)
Definition: ir_MagiQuest.hpp:122
KASEIKYO_DENON
@ KASEIKYO_DENON
Definition: IRProtocol.h:107
setLEDFeedbackPin
void setLEDFeedbackPin(uint8_t aFeedbackLEDPin)
Definition: IRFeedbackLED.hpp:53
setFeedbackLED
void setFeedbackLED(bool aSwitchLedOn)
Flash LED while receiving or sending IR data.
Definition: IRFeedbackLED.hpp:82
JVC
@ JVC
Definition: IRProtocol.h:99
IRData::numberOfBits
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
Definition: IRremoteInt.h:161
IRsend::aNumberOfRepeats
void int_fast8_t aNumberOfRepeats
Definition: IRremoteInt.h:538
IRsend::sendPin
uint8_t sendPin
Definition: IRremoteInt.h:726
IRsend::sendJVC
void sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
The JVC protocol repeats by skipping the header mark and space -> this leads to a poor repeat detecti...
Definition: ir_JVC.hpp:93
IRsend::sendKaseikyo_Sharp
void sendKaseikyo_Sharp(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats)
Stub using Kaseikyo with SHARP_VENDOR_ID_CODE.
Definition: ir_Kaseikyo.hpp:185
KASEIKYO_SHARP
@ KASEIKYO_SHARP
Definition: IRProtocol.h:108
FAST
@ FAST
Definition: IRProtocol.h:125
IRsend::setSendPin
void setSendPin(uint_fast8_t aSendPin)
Definition: IRSend.hpp:111
pinModeFast
#define pinModeFast
Definition: digitalWriteFast.h:383
IRsend::sendBoseWave
void sendBoseWave(uint8_t aCommand, int_fast8_t aNumberOfRepeats=NO_REPEATS)
Definition: ir_BoseWave.hpp:57
IRsend::sendSony
void sendSony(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t numberOfBits=12)
Definition: ir_Sony.hpp:103
digitalWriteFast
#define digitalWriteFast
Definition: digitalWriteFast.h:347
PULSE_CORRECTION_NANOS
#define PULSE_CORRECTION_NANOS
Define to disable carrier PWM generation in software and use (restricted) hardware PWM.
Definition: IRremote.hpp:191
IRsend::sendPulseDistanceWidth_P
void sendPulseDistanceWidth_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRRawDataType aData, uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats)
Definition: IRSend.hpp:1075
IRsend::mark
void mark(uint16_t aMarkMicros)
Sends an IR mark for the specified number of microseconds.
Definition: IRSend.hpp:1153
SONY
@ SONY
Definition: IRProtocol.h:118
KASEIKYO_JVC
@ KASEIKYO_JVC
Definition: IRProtocol.h:109
PulseDistanceWidthProtocolConstants::SpecialSendRepeatFunction
void(* SpecialSendRepeatFunction)()
Definition: IRProtocol.h:167
IRsend::sendSamsung48
void sendSamsung48(uint16_t aAddress, uint32_t aCommand, int_fast8_t aNumberOfRepeats)
Here we send Samsung48 We send 2 x (8 bit command and then ~command)
Definition: ir_Samsung.hpp:237
IRsend::sendRC6
void sendRC6(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle=true)
Assemble raw data for RC6 from parameters and toggle state and send We do not wait for the minimal tr...
Definition: ir_RC5_RC6.hpp:355
IRDATA_FLAGS_IS_REPEAT
#define IRDATA_FLAGS_IS_REPEAT
The gap between the preceding frame is as smaller than the maximum gap expected for a repeat....
Definition: IRProtocol.h:147
decode_type_t
decode_type_t
An enum consisting of all supported formats.
Definition: IRProtocol.h:93
IRsend::sendPulseDistanceWidthFromPGMArray
void sendPulseDistanceWidthFromPGMArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, IRRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats)
Definition: IRSend.hpp:720
IRsend::customDelayMicroseconds
static void customDelayMicroseconds(unsigned long aMicroseconds)
Custom delay function that circumvents Arduino's delayMicroseconds 16 bit limit and is (mostly) not e...
Definition: IRSend.hpp:1372
IRsend::sendPulseDistanceWidth
void sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats)
Sends PulseDistance frames and repeats.
Definition: IRSend.hpp:833
IRsend::IRsend
IRsend()
Definition: IRSend.hpp:71
SAMSUNG
@ SAMSUNG
Definition: IRProtocol.h:114
BOSEWAVE
@ BOSEWAVE
Definition: IRProtocol.h:121
DistanceWidthTimingInfoStruct::OneSpaceMicros
uint16_t OneSpaceMicros
Definition: IRProtocol.h:138
IRData::decodedRawData
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send<protocol>Raw functions.
Definition: IRremoteInt.h:155
IRsend::sendRaw_P
void sendRaw_P(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz)
New function using an 8 byte tick (50 us) timing array in FLASH to save program memory Raw data start...
Definition: IRSend.hpp:476
IRsend
Main class for sending IR signals.
Definition: IRremoteInt.h:516
DistanceWidthTimingInfoStruct::ZeroMarkMicros
uint16_t ZeroMarkMicros
Definition: IRProtocol.h:139
IR_TRACE_PRINT
#define IR_TRACE_PRINT(...)
Definition: IRremoteInt.h:197
MAGIQUEST
@ MAGIQUEST
Definition: IRProtocol.h:123
NEC2
@ NEC2
Definition: IRProtocol.h:103
PulseDistanceWidthProtocolConstants::Flags
uint8_t Flags
Definition: IRProtocol.h:165
IRsend::sendDenon
void sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t aSendSharpFrameMarker=0)
Definition: ir_Denon.hpp:131
IRsend::sendSamsung
void sendSamsung(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats)
Here we send Samsung32 If we get a command < 0x100, we send command and then ~command If we get an ad...
Definition: ir_Samsung.hpp:175
DistanceWidthTimingInfoStruct
Definition: IRProtocol.h:134
IRsend::sendRaw
void sendRaw(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz)
Sends an 8 byte tick timing array to save program memory.
Definition: IRSend.hpp:422
PulseDistanceWidthProtocolConstants
Definition: IRProtocol.h:161
IRsend::sendPulseDistanceWidthData_P
void sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Definition: IRSend.hpp:586
PANASONIC
@ PANASONIC
Definition: IRProtocol.h:105
timerConfigForSend
void timerConfigForSend(uint16_t aFrequencyKHz)
IF PWM should be generated not by software, but by a timer, this function sets output pin mode,...
Definition: IRTimer.hpp:136
IRData
Data structure for the user application, available as decodedIRData.
Definition: IRremoteInt.h:150
IR_SEND_PIN
#define IR_SEND_PIN
Definition: TinyIRSender.hpp:67
IRData::flags
uint8_t flags
IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above.
Definition: IRremoteInt.h:162
IRsend::sendSamsungLG
void sendSamsungLG(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats)
Definition: ir_Samsung.hpp:149
DistanceWidthTimingInfoStruct::OneMarkMicros
uint16_t OneMarkMicros
Definition: IRProtocol.h:137
IRsend::sendSharp
void sendSharp(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats)
Definition: ir_Denon.hpp:116
IRsend::sendPulseDistanceWidthFromPGMArray_P
void sendPulseDistanceWidthFromPGMArray_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats)
Definition: IRSend.hpp:1065
IRsend::begin
void begin(uint_fast8_t aSendPin)
Initializes the send pin and enable LED feedback with board specific FEEDBACK_LED_ON() and FEEDBACK_L...
Definition: IRSend.hpp:107
IRsend::sendKaseikyo_JVC
void sendKaseikyo_JVC(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats)
Stub using Kaseikyo with JVC_VENDOR_ID_CODE.
Definition: ir_Kaseikyo.hpp:192
IRsend::sendNEC
void sendNEC(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats)
NEC Send frame and special repeats There is NO delay after the last sent repeat!
Definition: ir_NEC.hpp:182
IRsend::periodOnTimeMicros
uint16_t periodOnTimeMicros
Definition: IRremoteInt.h:729
IRData::command
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
Definition: IRremoteInt.h:153
NEC
@ NEC
Definition: IRProtocol.h:102
IRsend::sendPanasonic
void sendPanasonic(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats)
Stub using Kaseikyo with PANASONIC_VENDOR_ID_CODE.
Definition: ir_Kaseikyo.hpp:164
APPLE
@ APPLE
Definition: IRProtocol.h:97
IRsend::getPulseCorrectionNanos
uint16_t getPulseCorrectionNanos()
Definition: IRSend.hpp:1461
LEGO_PF
@ LEGO_PF
Definition: IRProtocol.h:122
DistanceWidthTimingInfoStruct::ZeroSpaceMicros
uint16_t ZeroSpaceMicros
Definition: IRProtocol.h:140
IRRawDataType
uint32_t IRRawDataType
Definition: IRremoteInt.h:105
IR_TRACE_PRINTLN
#define IR_TRACE_PRINTLN(...)
Definition: IRremoteInt.h:198
KASEIKYO_MITSUBISHI
@ KASEIKYO_MITSUBISHI
Definition: IRProtocol.h:110
IRsend::sendPulseDistanceWidthFromArray_P
void sendPulseDistanceWidthFromArray_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats)
Definition: IRSend.hpp:1056
DENON
@ DENON
Definition: IRProtocol.h:98
enableSendPWMByTimer
void enableSendPWMByTimer()
Enables output of the PWM signal of the timer at the timer pin.
Definition: IRTimer.hpp:142
IrSender
IRsend IrSender
Definition: IRSend.hpp:69
IR_SEND_DUTY_CYCLE_PERCENT
#define IR_SEND_DUTY_CYCLE_PERCENT
Duty cycle in percent for sent signals.
Definition: IRremote.hpp:199
SIRCS_12_PROTOCOL
#define SIRCS_12_PROTOCOL
Definition: IRProtocol.h:130
RC5
@ RC5
Definition: IRProtocol.h:111
PulseDistanceWidthProtocolConstants::DistanceWidthTimingInfo
DistanceWidthTimingInfoStruct DistanceWidthTimingInfo
Definition: IRProtocol.h:164
IRsend::periodTimeMicros
uint16_t periodTimeMicros
Definition: IRremoteInt.h:728
IRsend::space
static void space(uint16_t aSpaceMicros)
Sends an IR space for the specified number of microseconds.
Definition: IRSend.hpp:1364
IRsend::sendRC5
void sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle=true)
Definition: ir_RC5_RC6.hpp:106
disableSendPWMByTimer
void disableSendPWMByTimer()
Disables output of the PWM signal of the timer at the timer pin and set it to inactive.
Definition: IRTimer.hpp:147
IRsend::sendNEC2
void sendNEC2(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats)
NEC2 Send frame !!! and repeat the frame for each requested repeat !!! There is NO delay after the la...
Definition: ir_NEC.hpp:200
IRsend::sendKaseikyo_Mitsubishi
void sendKaseikyo_Mitsubishi(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats)
Stub using Kaseikyo with MITSUBISHI_VENDOR_ID_CODE.
Definition: ir_Kaseikyo.hpp:178
PROTOCOL_IS_MSB_MASK
#define PROTOCOL_IS_MSB_MASK
Definition: IRProtocol.h:180
RC6
@ RC6
Definition: IRProtocol.h:112
IRsend::IRLedOff
void IRLedOff()
Just switch the IR sending LED off to send an IR space A space is "no output", so the PWM output is d...
Definition: IRSend.hpp:1322
IRsend::sendPulseDistanceWidthFromArray
void sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats)
Definition: IRSend.hpp:655
sendFAST
void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats=0)
Definition: TinyIRSender.hpp:351
IRsend::sendPulseDistanceWidthData
void sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, uint_fast8_t aNumberOfBits)
Sends PulseDistance from data contained in parameter using ProtocolConstants structure for timing etc...
Definition: IRSend.hpp:578
IRsend::sendOnkyo
void sendOnkyo(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats)
There is NO delay after the last sent repeat!
Definition: ir_NEC.hpp:191
PulseDistanceWidthProtocolConstants::RepeatPeriodMillis
unsigned int RepeatPeriodMillis
Definition: IRProtocol.h:166
IRsend::sendLegoPowerFunctions
void sendLegoPowerFunctions(uint8_t aChannel, uint8_t tCommand, uint8_t aMode, bool aDoSend5Times=true)
Definition: ir_Lego.hpp:117
IRsend::write
size_t write(decode_type_t aProtocol, uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats=NO_REPEATS)
Interprets and sends a IRData structure.
Definition: IRSend.hpp:153
SAMSUNGLG
@ SAMSUNGLG
Definition: IRProtocol.h:115
IRData::protocol
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
Definition: IRremoteInt.h:151
IRsend::sendBiphaseData
void sendBiphaseData(uint16_t aBiphaseTimeUnit, uint32_t aData, uint_fast8_t aNumberOfBits)
Sends Biphase data MSB first Always send start bit, do not send the trailing space of the start bit 0...
Definition: IRSend.hpp:1093
SAMSUNG48
@ SAMSUNG48
Definition: IRProtocol.h:116
IRsend::sendLG
void sendLG(uint8_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats)
LG uses the NEC repeat.
Definition: ir_LG.hpp:165
PulseDistanceWidthProtocolConstants::FrequencyKHz
uint_fast8_t FrequencyKHz
Definition: IRProtocol.h:163
DistanceWidthTimingInfoStruct::HeaderSpaceMicros
uint16_t HeaderSpaceMicros
Definition: IRProtocol.h:136
IRsend::aCommand
void aCommand
Definition: IRremoteInt.h:688
LG
@ LG
Definition: IRProtocol.h:100
IRsend::enableIROut
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.
Definition: IRSend.hpp:1404
IRsend::sendKaseikyo_Denon
void sendKaseikyo_Denon(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats)
Stub using Kaseikyo with DENON_VENDOR_ID_CODE.
Definition: ir_Kaseikyo.hpp:171
SHARP
@ SHARP
Definition: IRProtocol.h:117