Skip to content

Commit 7c42691

Browse files
committed
Minor changes
1 parent 9492d1b commit 7c42691

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/IRReceive.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ void IRrecv::begin(uint_fast8_t aReceivePin, bool aEnableLEDFeedback, uint_fast8
271271
(void) aEnableLEDFeedback;
272272
(void) aFeedbackLEDPin;
273273
#endif
274-
// Set pin mode once. pinModeFast makes no difference here :-(
275-
pinMode(irparams.IRReceivePin, INPUT);
276274

277275
#if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN)
278276
pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT);
@@ -289,6 +287,8 @@ void IRrecv::setReceivePin(uint_fast8_t aReceivePinNumber) {
289287
irparams.IRReceivePinMask = digitalPinToBitMask(aReceivePinNumber);
290288
irparams.IRReceivePinPortInputRegister = portInputRegister(digitalPinToPort(aReceivePinNumber));
291289
#endif
290+
// Set pin mode once. pinModeFast makes no difference here :-(
291+
pinMode(aReceivePinNumber, INPUT); // Seems to be at least required by ESP32
292292
}
293293

294294
/**

src/IRSend.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,23 @@ void IRsend::space(unsigned int aSpaceMicros) {
920920
* and is (mostly) not extended by the duration of interrupt codes like the millis() interrupt
921921
*/
922922
void IRsend::customDelayMicroseconds(unsigned long aMicroseconds) {
923-
#if defined(__AVR__)
924-
unsigned long start = micros() - (64 / clockCyclesPerMicrosecond()); // - (64 / clockCyclesPerMicrosecond()) for reduced resolution and additional overhead
923+
#if defined(ESP32) || defined(ESP8266)
924+
// from https://github.com/crankyoldgit/IRremoteESP8266/blob/00b27cc7ea2e7ac1e48e91740723c805a38728e0/src/IRsend.cpp#L123
925+
// Invoke a delay(), where possible, to avoid triggering the WDT.
926+
delay(aMicroseconds / 1000UL); // Delay for as many whole milliseconds as we can.
927+
// Delay the remaining sub-millisecond.
928+
delayMicroseconds(static_cast<uint16_t>(aMicroseconds % 1000UL));
925929
#else
930+
931+
# if defined(__AVR__)
932+
unsigned long start = micros() - (64 / clockCyclesPerMicrosecond()); // - (64 / clockCyclesPerMicrosecond()) for reduced resolution and additional overhead
933+
# else
926934
unsigned long start = micros();
927-
#endif
935+
# endif
928936
// overflow invariant comparison :-)
929937
while (micros() - start < aMicroseconds) {
930938
}
939+
#endif
931940
}
932941

933942
/**

src/ir_NEC.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct PulseDistanceWidthProtocolConstants NECProtocolConstants = { NEC, NEC_KHZ
105105
NEC_ONE_SPACE, NEC_BIT_MARK, NEC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, SEND_STOP_BIT, (NEC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI),
106106
&sendNECSpecialRepeat };
107107

108+
// Like NEC but repeat are full frames instead of special NEC repeats
108109
struct PulseDistanceWidthProtocolConstants NEC2ProtocolConstants = { NEC2, NEC_KHZ, NEC_HEADER_MARK, NEC_HEADER_SPACE, NEC_BIT_MARK,
109110
NEC_ONE_SPACE, NEC_BIT_MARK, NEC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, SEND_STOP_BIT, (NEC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), NULL };
110111

@@ -159,6 +160,8 @@ uint32_t IRsend::computeNECRawDataAndChecksum(uint16_t aAddress, uint16_t aComma
159160
}
160161

161162
/**
163+
* NEC Send frame and special repeats
164+
* There is NO delay after the last sent repeat!
162165
* @param aNumberOfRepeats If < 0 then only a special repeat frame without leading and trailing space
163166
* will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction().
164167
*/
@@ -167,10 +170,9 @@ void IRsend::sendNEC(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfR
167170
}
168171

169172
/*
170-
* Repeat commands should be sent in a 110 ms raster.
173+
* NEC2 Send frame and repeat the frame for each requested repeat
171174
* There is NO delay after the last sent repeat!
172-
* @param aNumberOfRepeats If < 0 then only a special repeat frame without leading and trailing space
173-
* will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction().
175+
* @param aNumberOfRepeats If < 0 then nothing is sent.
174176
*/
175177
void IRsend::sendNEC2(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) {
176178
sendPulseDistanceWidth(&NEC2ProtocolConstants, computeNECRawDataAndChecksum(aAddress, aCommand), NEC_BITS, aNumberOfRepeats);

0 commit comments

Comments
 (0)