MCPcopy Create free account
hub / github.com/Arduino-IRremote/Arduino-IRremote / sendExtendedNEC

Function sendExtendedNEC

src/TinyIRSender.hpp:267–332  ·  view source on GitHub ↗

* Send Extended NEC with a forced 16 bit address and 8 or 16 bit command depending on the value of aCommand. * @param aAddress - Send 16 bit address. * @param aCommand - If aCommand < 0x100 send 8 bit command and 8 bit inverted command, else send 16 bit command. * @param aNumberOfRepeats - Number of repeats send at a period of 110 ms. * @param aSendNEC2Repeats - Instead of sending the NEC s

Source from the content-addressed store, hash-verified

265 * @param aSendNEC2Repeats - Instead of sending the NEC special repeat code, send the original frame for repeat.
266 */
267void sendExtendedNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats, bool aSendNEC2Repeats) {
268 pinModeFast(aSendPin, OUTPUT);
269
270#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
271 pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT);
272# if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
273 digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW);
274# else
275 digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH);
276# endif
277#endif
278
279 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
280 while (tNumberOfCommands > 0) {
281 unsigned long tStartOfFrameMillis = millis();
282
283 sendMark(aSendPin, NEC_HEADER_MARK);
284 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
285 // send the NEC special repeat
286 delayMicroseconds (NEC_REPEAT_HEADER_SPACE); // - 2250
287 } else {
288 // send header
289 delayMicroseconds (NEC_HEADER_SPACE);
290 LongUnion tData;
291 tData.UWord.LowWord = aAddress;
292 if (aCommand > 0xFF) {
293 tData.UWord.HighWord = aCommand;
294 } else {
295 tData.UByte.MidHighByte = aCommand;
296 tData.UByte.HighByte = ~aCommand; // LSB first
297 }
298 // Send data
299 for (uint_fast8_t i = 0; i < NEC_BITS; ++i) {
300 sendMark(aSendPin, NEC_BIT_MARK); // constant mark length
301
302 if (tData.ULong & 1) {
303 delayMicroseconds (NEC_ONE_SPACE);
304 } else {
305 delayMicroseconds (NEC_ZERO_SPACE);
306 }
307 tData.ULong >>= 1; // shift command for next bit
308 }
309 } // send stop bit
310 sendMark(aSendPin, NEC_BIT_MARK);
311
312 tNumberOfCommands--;
313 // skip last delay!
314 if (tNumberOfCommands > 0) {
315 /*
316 * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration.
317 */
318 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
319 if (NEC_REPEAT_PERIOD / 1000 > tFrameDurationMillis) {
320 delay(NEC_REPEAT_PERIOD / 1000 - tFrameDurationMillis);
321 }
322 }
323 }
324#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)

Callers

nothing calls this directly

Calls 1

sendMarkFunction · 0.85

Tested by

no test coverage detected