Update IRRemoteESP8266 version to 2.5.5

factorize IR send signal function between the 2 types of receiving
Add new IRRemoteESP8266 protocols
replace pins on mega according schema
remove unecessaries spaces
This commit is contained in:
Florian committed 2019-02-08 16:50:37 +01:00
1 parent 0180a0dbd5
commit f0305236db
149 files changed
+20957 -7850

No files matched your search

+108 -55
View File
@@ -34,9 +34,8 @@
// to change the duty cycle etc.
// Returns:
// An IRsend object.
IRsend::IRsend(uint16_t IRsendPin, bool inverted,
bool use_modulation) : IRpin(IRsendPin),
periodOffset(PERIOD_OFFSET) {
IRsend::IRsend(uint16_t IRsendPin, bool inverted, bool use_modulation)
: IRpin(IRsendPin), periodOffset(kPeriodOffset) {
if (inverted) {
outputOn = LOW;
outputOff = HIGH;
@@ -46,9 +45,9 @@ IRsend::IRsend(uint16_t IRsendPin, bool inverted,
}
modulation = use_modulation;
if (modulation)
_dutycycle = DUTY_DEFAULT;
_dutycycle = kDutyDefault;
else
_dutycycle = DUTY_MAX;
_dutycycle = kDutyMax;
}
// Enable the pin for output.
@@ -82,12 +81,13 @@ void IRsend::ledOn() {
// nr. of uSeconds.
uint32_t IRsend::calcUSecPeriod(uint32_t hz, bool use_offset) {
if (hz == 0) hz = 1; // Avoid Zero hz. Divide by Zero is nasty.
uint32_t period = (1000000UL + hz/2) / hz; // The equiv of round(1000000/hz).
uint32_t period =
(1000000UL + hz / 2) / hz; // The equiv of round(1000000/hz).
// Apply the offset and ensure we don't result in a <= 0 value.
if (use_offset)
return std::max((uint32_t) 1, period + periodOffset);
return std::max((uint32_t)1, period + periodOffset);
else
return std::max((uint32_t) 1, period);
return std::max((uint32_t)1, period);
}
// Set the output frequency modulation and duty cycle.
@@ -104,15 +104,15 @@ uint32_t IRsend::calcUSecPeriod(uint32_t hz, bool use_offset) {
void IRsend::enableIROut(uint32_t freq, uint8_t duty) {
// Set the duty cycle to use if we want freq. modulation.
if (modulation) {
_dutycycle = std::min(duty, (uint8_t) DUTY_MAX);
_dutycycle = std::min(duty, kDutyMax);
} else {
_dutycycle = DUTY_MAX;
_dutycycle = kDutyMax;
}
if (freq < 1000) // Were we given kHz? Supports the old call usage.
freq *= 1000;
uint32_t period = calcUSecPeriod(freq);
// Nr. of uSeconds the LED will be on per pulse.
onTimePeriod = (period * _dutycycle) / DUTY_MAX;
onTimePeriod = (period * _dutycycle) / kDutyMax;
// Nr. of uSeconds the LED will be off per pulse.
offTimePeriod = period - onTimePeriod;
}
@@ -124,7 +124,7 @@ void IRsend::enableIROut(uint32_t freq, uint8_t duty) {
void IRsend::_delayMicroseconds(uint32_t usec) {
// delayMicroseconds() is only accurate to 16383us.
// Ref: https://www.arduino.cc/en/Reference/delayMicroseconds
if (usec <= MAX_ACCURATE_USEC_DELAY) {
if (usec <= kMaxAccurateUsecDelay) {
#ifndef UNIT_TEST
delayMicroseconds(usec);
#endif
@@ -146,9 +146,9 @@ void IRsend::_delayMicroseconds(uint32_t usec) {
// NOTE: Use this only if you know what you are doing as it may cause the WDT
// to reset the ESP8266.
void IRsend::_delayMicroseconds(uint32_t usec) {
for (; usec > MAX_ACCURATE_USEC_DELAY; usec -= MAX_ACCURATE_USEC_DELAY)
for (; usec > kMaxAccurateUsecDelay; usec -= kMaxAccurateUsecDelay)
#ifndef UNIT_TEST
delayMicroseconds(MAX_ACCURATE_USEC_DELAY);
delayMicroseconds(kMaxAccurateUsecDelay);
delayMicroseconds(static_cast<uint16_t>(usec));
#endif // UNIT_TEST
}
@@ -190,14 +190,14 @@ uint16_t IRsend::mark(uint16_t usec) {
ledOn();
// Calculate how long we should pulse on for.
// e.g. Are we to close to the end of our requested mark time (usec)?
_delayMicroseconds(std::min((uint32_t) onTimePeriod, usec - elapsed));
_delayMicroseconds(std::min((uint32_t)onTimePeriod, usec - elapsed));
ledOff();
counter++;
if (elapsed + onTimePeriod >= usec)
return counter; // LED is now off & we've passed our allotted time.
// Wait for the lesser of the rest of the duty cycle, or the time remaining.
_delayMicroseconds(std::min(usec - elapsed - onTimePeriod,
(uint32_t) offTimePeriod));
_delayMicroseconds(
std::min(usec - elapsed - onTimePeriod, (uint32_t)offTimePeriod));
elapsed = usecTimer.elapsed(); // Update & recache the actual elapsed time.
}
return counter;
@@ -238,7 +238,7 @@ int8_t IRsend::calibrate(uint16_t hz) {
uint32_t timeTaken = usecTimer.elapsed(); // Record the time it took.
// While it shouldn't be necessary, assume at least 1 pulse, to avoid a
// divide by 0 situation.
pulses = std::max(pulses, (uint16_t) 1U);
pulses = std::max(pulses, (uint16_t)1U);
uint32_t calcPeriod = calcUSecPeriod(hz); // e.g. @38kHz it should be 26us.
// Assuming 38kHz for the example calculations:
// In a 65535us pulse, we should have 2520.5769 pulses @ 26us periods.
@@ -250,9 +250,9 @@ int8_t IRsend::calibrate(uint16_t hz) {
//
// Calculate the actual period from the actual time & the actual pulses
// generated.
double_t actualPeriod = (double_t) timeTaken / (double_t) pulses;
double_t actualPeriod = (double_t)timeTaken / (double_t)pulses;
// Store the difference between the actual time per period vs. calculated.
periodOffset = (int8_t) ((double_t) calcPeriod - actualPeriod);
periodOffset = (int8_t)((double_t)calcPeriod - actualPeriod);
return periodOffset;
}
@@ -268,9 +268,9 @@ int8_t IRsend::calibrate(uint16_t hz) {
// data: The data to be transmitted.
// nbits: Nr. of bits of data to be sent.
// MSBfirst: Flag for bit transmission order. Defaults to MSB->LSB order.
void IRsend::sendData(uint16_t onemark, uint32_t onespace,
uint16_t zeromark, uint32_t zerospace,
uint64_t data, uint16_t nbits, bool MSBfirst) {
void IRsend::sendData(uint16_t onemark, uint32_t onespace, uint16_t zeromark,
uint32_t zerospace, uint64_t data, uint16_t nbits,
bool MSBfirst) {
if (nbits == 0) // If we are asked to send nothing, just return.
return;
if (MSBfirst) { // Send the MSB first.
@@ -281,7 +281,7 @@ void IRsend::sendData(uint16_t onemark, uint32_t onespace,
nbits--;
}
// Send the supplied data.
for (uint64_t mask = 1ULL << (nbits - 1); mask; mask >>= 1)
for (uint64_t mask = 1ULL << (nbits - 1); mask; mask >>= 1)
if (data & mask) { // Send a 1
mark(onemark);
space(onespace);
@@ -376,10 +376,10 @@ void IRsend::sendGeneric(const uint16_t headermark, const uint32_t headerspace,
const uint16_t onemark, const uint32_t onespace,
const uint16_t zeromark, const uint32_t zerospace,
const uint16_t footermark, const uint32_t gap,
const uint32_t mesgtime,
const uint64_t data, const uint16_t nbits,
const uint16_t frequency, const bool MSBfirst,
const uint16_t repeat, const uint8_t dutycycle) {
const uint32_t mesgtime, const uint64_t data,
const uint16_t nbits, const uint16_t frequency,
const bool MSBfirst, const uint16_t repeat,
const uint8_t dutycycle) {
// Setup
enableIROut(frequency, dutycycle);
IRtimer usecs = IRtimer();
@@ -389,14 +389,14 @@ void IRsend::sendGeneric(const uint16_t headermark, const uint32_t headerspace,
usecs.reset();
// Header
if (headermark) mark(headermark);
if (headerspace) space(headerspace);
if (headermark) mark(headermark);
if (headerspace) space(headerspace);
// Data
sendData(onemark, onespace, zeromark, zerospace, data, nbits, MSBfirst);
// Footer
if (footermark) mark(footermark);
if (footermark) mark(footermark);
uint32_t elapsed = usecs.elapsed();
// Avoid potential unsigned integer underflow. e.g. when mesgtime is 0.
if (elapsed >= mesgtime)
@@ -445,16 +445,16 @@ void IRsend::sendGeneric(const uint16_t headermark, const uint32_t headerspace,
// We always send a message, even for repeat=0, hence '<= repeat'.
for (uint16_t r = 0; r <= repeat; r++) {
// Header
if (headermark) mark(headermark);
if (headerspace) space(headerspace);
if (headermark) mark(headermark);
if (headerspace) space(headerspace);
// Data
for (uint16_t i = 0; i < nbytes; i++)
sendData(onemark, onespace, zeromark, zerospace,
*(dataptr + i), 8, MSBfirst);
sendData(onemark, onespace, zeromark, zerospace, *(dataptr + i), 8,
MSBfirst);
// Footer
if (footermark) mark(footermark);
if (footermark) mark(footermark);
space(gap);
}
}
@@ -492,61 +492,114 @@ void IRsend::sendRaw(uint16_t buf[], uint16_t len, uint16_t hz) {
void IRsend::send(uint16_t type, uint64_t data, uint16_t nbits) {
switch (type) {
#if SEND_NEC
case NEC: sendNEC(data, nbits); break;
case NEC:
sendNEC(data, nbits);
break;
#endif
#if SEND_SONY
case SONY: sendSony(data, nbits); break;
case SONY:
sendSony(data, nbits);
break;
#endif
#if SEND_RC5
case RC5: sendRC5(data, nbits); break;
case RC5:
sendRC5(data, nbits);
break;
#endif
#if SEND_RC6
case RC6: sendRC6(data, nbits); break;
case RC6:
sendRC6(data, nbits);
break;
#endif
#if SEND_DISH
case DISH: sendDISH(data, nbits); break;
case DISH:
sendDISH(data, nbits);
break;
#endif
#if SEND_JVC
case JVC: sendJVC(data, nbits); break;
case JVC:
sendJVC(data, nbits);
break;
#endif
#if SEND_SAMSUNG
case SAMSUNG: sendSAMSUNG(data, nbits); break;
case SAMSUNG:
sendSAMSUNG(data, nbits);
break;
#endif
#if SEND_LG
case LG: sendLG(data, nbits); break;
case LG:
sendLG(data, nbits);
break;
#endif
#if SEND_LG
case LG2:
sendLG2(data, nbits);
break;
#endif
#if SEND_WHYNTER
case WHYNTER: sendWhynter(data, nbits); break;
case WHYNTER:
sendWhynter(data, nbits);
break;
#endif
#if SEND_COOLIX
case COOLIX: sendCOOLIX(data, nbits); break;
case COOLIX:
sendCOOLIX(data, nbits);
break;
#endif
#if SEND_DENON
case DENON: sendDenon(data, nbits); break;
case DENON:
sendDenon(data, nbits);
break;
#endif
#if SEND_SHERWOOD
case SHERWOOD: sendSherwood(data, nbits); break;
case SHERWOOD:
sendSherwood(data, nbits);
break;
#endif
#if SEND_RCMM
case RCMM: sendRCMM(data, nbits); break;
case RCMM:
sendRCMM(data, nbits);
break;
#endif
#if SEND_MITSUBISHI
case MITSUBISHI: sendMitsubishi(data, nbits); break;
case MITSUBISHI:
sendMitsubishi(data, nbits);
break;
#endif
#if SEND_MITSUBISHI2
case MITSUBISHI2: sendMitsubishi2(data, nbits); break;
case MITSUBISHI2:
sendMitsubishi2(data, nbits);
break;
#endif
#if SEND_SHARP
case SHARP: sendSharpRaw(data, nbits); break;
case SHARP:
sendSharpRaw(data, nbits);
break;
#endif
#if SEND_AIWA_RC_T501
case AIWA_RC_T501: sendAiwaRCT501(data, nbits); break;
case AIWA_RC_T501:
sendAiwaRCT501(data, nbits);
break;
#endif
#if SEND_MIDEA
case MIDEA: sendMidea(data, nbits); break;
case MIDEA:
sendMidea(data, nbits);
break;
#endif
#if SEND_GICABLE
case GICABLE: sendGICable(data, nbits); break;
case GICABLE:
sendGICable(data, nbits);
break;
#endif
#if SEND_PIONEER
case PIONEER:
sendPioneer(data, nbits);
break;
#endif
#if SEND_VESTEL_AC
case VESTEL_AC:
sendVestelAC(data, nbits);
break;
#endif
}
}