From 1c63589b3d49d0523087781e07e47341402e3757 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Wed, 21 Jun 2017 17:17:21 +0200 Subject: [PATCH] upgraded IRremoteESP8266 from v1.0.2 to v1.2.0. fixes #188 --- lib/IRremoteESP8266/.travis.yml | 9 +- lib/IRremoteESP8266/IRDaikinESP.cpp | 36 +- lib/IRremoteESP8266/IRKelvinator.cpp | 60 +- lib/IRremoteESP8266/IRMitsubishiAC.cpp | 34 +- lib/IRremoteESP8266/IRremoteESP8266.cpp | 846 +++++++++++------- lib/IRremoteESP8266/IRremoteESP8266.h | 68 +- lib/IRremoteESP8266/IRremoteInt.h | 60 +- lib/IRremoteESP8266/README.md | 9 + .../examples/IRServer/IRServer.ino | 2 +- .../examples/IRrecvDumpV2/IRrecvDumpV2.ino | 47 +- .../examples/IRsendDemo/IRsendDemo.ino | 34 +- lib/IRremoteESP8266/library.json | 2 +- lib/IRremoteESP8266/library.properties | 2 +- 13 files changed, 723 insertions(+), 486 deletions(-) diff --git a/lib/IRremoteESP8266/.travis.yml b/lib/IRremoteESP8266/.travis.yml index a4539ffd82..eb09db288c 100644 --- a/lib/IRremoteESP8266/.travis.yml +++ b/lib/IRremoteESP8266/.travis.yml @@ -1,13 +1,14 @@ language: c env: - BD=esp8266:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M + - BD=esp8266:esp8266:d1_mini:CpuFrequency=80,FlashSize=4M3M before_install: - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" - sleep 3 - export DISPLAY=:1.0 - - wget http://downloads.arduino.cc/arduino-1.8.1-linux64.tar.xz - - tar xf arduino-1.8.1-linux64.tar.xz - - sudo mv arduino-1.8.1 /usr/local/share/arduino + - wget http://downloads.arduino.cc/arduino-1.8.2-linux64.tar.xz + - tar xf arduino-1.8.2-linux64.tar.xz + - sudo mv arduino-1.8.2 /usr/local/share/arduino - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino install: - ln -s $PWD /usr/local/share/arduino/libraries/ @@ -25,7 +26,7 @@ script: - arduino --verify --board $BD $PWD/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino - arduino --verify --board $BD $PWD/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino - arduino --verify --board $BD $PWD/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino - - arduino --verify --board $BD $PWD/examples/TurnOnKelvinatorAC/TurnOnMitsubishiAC.ino + - arduino --verify --board $BD $PWD/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino notifications: email: diff --git a/lib/IRremoteESP8266/IRDaikinESP.cpp b/lib/IRremoteESP8266/IRDaikinESP.cpp index 02fd25cf36..c38923fe2e 100644 --- a/lib/IRremoteESP8266/IRDaikinESP.cpp +++ b/lib/IRremoteESP8266/IRDaikinESP.cpp @@ -9,17 +9,17 @@ IRDaikinESP::IRDaikinESP(int pin) : _irsend(pin) { } -void IRDaikinESP::begin() +void ICACHE_FLASH_ATTR IRDaikinESP::begin() { _irsend.begin(); } -void IRDaikinESP::send() +void ICACHE_FLASH_ATTR IRDaikinESP::send() { _irsend.sendDaikin(daikin); } -void IRDaikinESP::checksum() +void ICACHE_FLASH_ATTR IRDaikinESP::checksum() { uint8_t sum = 0; uint8_t i; @@ -36,39 +36,39 @@ void IRDaikinESP::checksum() daikin[26] = sum &0xFF; } -void IRDaikinESP::on() +void ICACHE_FLASH_ATTR IRDaikinESP::on() { //state = ON; daikin[13] |= 0x01; checksum(); } -void IRDaikinESP::off() +void ICACHE_FLASH_ATTR IRDaikinESP::off() { //state = OFF; daikin[13] &= 0xFE; checksum(); } -uint8_t IRDaikinESP::getPower() +uint8_t ICACHE_FLASH_ATTR IRDaikinESP::getPower() { return (daikin[13])&0x01; } // DAIKIN_SILENT or DAIKIN_POWERFUL -void IRDaikinESP::setAux(uint8_t aux) +void ICACHE_FLASH_ATTR IRDaikinESP::setAux(uint8_t aux) { daikin[21] = aux; checksum(); } -uint8_t IRDaikinESP::getAux(){ +uint8_t ICACHE_FLASH_ATTR IRDaikinESP::getAux(){ return daikin[21]; } // Set the temp in deg C -void IRDaikinESP::setTemp(uint8_t temp) +void ICACHE_FLASH_ATTR IRDaikinESP::setTemp(uint8_t temp) { if (temp < 18) temp = 18; @@ -78,13 +78,13 @@ void IRDaikinESP::setTemp(uint8_t temp) checksum(); } -uint8_t IRDaikinESP::getTemp() +uint8_t ICACHE_FLASH_ATTR IRDaikinESP::getTemp() { return (daikin[14])/2; } // Set the speed of the fan, 0-5, 0 is auto, 1-5 is the speed -void IRDaikinESP::setFan(uint8_t fan) +void ICACHE_FLASH_ATTR IRDaikinESP::setFan(uint8_t fan) { // Set the fan speed bits, leave low 4 bits alone uint8_t fanset; @@ -97,7 +97,7 @@ void IRDaikinESP::setFan(uint8_t fan) checksum(); } -uint8_t IRDaikinESP::getFan() +uint8_t ICACHE_FLASH_ATTR IRDaikinESP::getFan() { uint8_t fan = daikin[16] >> 4; fan = fan - 2; @@ -106,7 +106,7 @@ uint8_t IRDaikinESP::getFan() return fan; } -uint8_t IRDaikinESP::getMode() +uint8_t ICACHE_FLASH_ATTR IRDaikinESP::getMode() {/* DAIKIN_COOL DAIKIN_HEAT @@ -117,13 +117,13 @@ uint8_t IRDaikinESP::getMode() return (daikin[13])>>4; } -void IRDaikinESP::setMode(uint8_t mode) +void ICACHE_FLASH_ATTR IRDaikinESP::setMode(uint8_t mode) { daikin[13]=mode<<4 | getPower(); checksum(); } -void IRDaikinESP::setSwingVertical(uint8_t swing) +void ICACHE_FLASH_ATTR IRDaikinESP::setSwingVertical(uint8_t swing) { if (swing) daikin[16] = daikin[16] | 0x0F; @@ -132,12 +132,12 @@ void IRDaikinESP::setSwingVertical(uint8_t swing) checksum(); } -uint8_t IRDaikinESP::getSwingVertical() +uint8_t ICACHE_FLASH_ATTR IRDaikinESP::getSwingVertical() { return (daikin[16])&0x01; } -void IRDaikinESP::setSwingHorizontal(uint8_t swing) +void ICACHE_FLASH_ATTR IRDaikinESP::setSwingHorizontal(uint8_t swing) { if (swing) daikin[17] = daikin[17] | 0x0F; @@ -146,7 +146,7 @@ void IRDaikinESP::setSwingHorizontal(uint8_t swing) checksum(); } -uint8_t IRDaikinESP::getSwingHorizontal() +uint8_t ICACHE_FLASH_ATTR IRDaikinESP::getSwingHorizontal() { return (daikin[17])&0x01; } diff --git a/lib/IRremoteESP8266/IRKelvinator.cpp b/lib/IRremoteESP8266/IRKelvinator.cpp index c4a13199ae..c4a4ca0181 100644 --- a/lib/IRremoteESP8266/IRKelvinator.cpp +++ b/lib/IRremoteESP8266/IRKelvinator.cpp @@ -20,36 +20,36 @@ IRKelvinatorAC::IRKelvinatorAC(int pin) : _irsend(pin) { stateReset(); } -void IRKelvinatorAC::stateReset() { +void ICACHE_FLASH_ATTR IRKelvinatorAC::stateReset() { for (uint8_t i = 0; i < KELVINATOR_STATE_LENGTH; i++) remote_state[i] = 0x0; remote_state[3] = 0x50; remote_state[11] = 0x70; } -void IRKelvinatorAC::begin() { +void ICACHE_FLASH_ATTR IRKelvinatorAC::begin() { _irsend.begin(); } -void IRKelvinatorAC::fixup() { +void ICACHE_FLASH_ATTR IRKelvinatorAC::fixup() { // X-Fan mode is only valid in COOL or DRY modes. if (getMode() != KELVINATOR_COOL && getMode() != KELVINATOR_DRY) setXFan(false); checksum(); // Calculate the checksums } -void IRKelvinatorAC::send() { +void ICACHE_FLASH_ATTR IRKelvinatorAC::send() { fixup(); // Ensure correct settings before sending. _irsend.sendKelvinator(remote_state); } -uint8_t* IRKelvinatorAC::getRaw() { +uint8_t* ICACHE_FLASH_ATTR IRKelvinatorAC::getRaw() { fixup(); // Ensure correct settings before sending. return remote_state; } // Many Bothans died to bring us this information. -void IRKelvinatorAC::checksum() { +void ICACHE_FLASH_ATTR IRKelvinatorAC::checksum() { // For each command + options block. for (uint8_t offset = 0; offset < KELVINATOR_STATE_LENGTH; offset += 8) { uint8_t sum = KELVINATOR_CHECKSUM_START; @@ -68,31 +68,31 @@ void IRKelvinatorAC::checksum() { } } -void IRKelvinatorAC::on() { +void ICACHE_FLASH_ATTR IRKelvinatorAC::on() { //state = ON; remote_state[0] |= KELVINATOR_POWER; remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. } -void IRKelvinatorAC::off() { +void ICACHE_FLASH_ATTR IRKelvinatorAC::off() { //state = OFF; remote_state[0] &= ~KELVINATOR_POWER; remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. } -void IRKelvinatorAC::setPower(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setPower(bool state) { if (state) on(); else off(); } -bool IRKelvinatorAC::getPower() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getPower() { return ((remote_state[0] & KELVINATOR_POWER) != 0); } // Set the temp. in deg C -void IRKelvinatorAC::setTemp(uint8_t temp) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setTemp(uint8_t temp) { temp = max(KELVINATOR_MIN_TEMP, temp); temp = min(KELVINATOR_MAX_TEMP, temp); remote_state[1] = (remote_state[1] & 0xF0U) | (temp - KELVINATOR_MIN_TEMP); @@ -100,12 +100,12 @@ void IRKelvinatorAC::setTemp(uint8_t temp) { } // Return the set temp. in deg C -uint8_t IRKelvinatorAC::getTemp() { +uint8_t ICACHE_FLASH_ATTR IRKelvinatorAC::getTemp() { return ((remote_state[1] & 0xFU) + KELVINATOR_MIN_TEMP); } // Set the speed of the fan, 0-5, 0 is auto, 1-5 is the speed -void IRKelvinatorAC::setFan(uint8_t fan) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setFan(uint8_t fan) { fan = min(KELVINATOR_FAN_MAX, fan); // Bounds check // Only change things if we need to. @@ -122,11 +122,11 @@ void IRKelvinatorAC::setFan(uint8_t fan) { } } -uint8_t IRKelvinatorAC::getFan() { +uint8_t ICACHE_FLASH_ATTR IRKelvinatorAC::getFan() { return ((remote_state[14] & ~KELVINATOR_FAN_MASK) >> KELVINATOR_FAN_OFFSET); } -uint8_t IRKelvinatorAC::getMode() { +uint8_t ICACHE_FLASH_ATTR IRKelvinatorAC::getMode() { /* KELVINATOR_AUTO KELVINATOR_COOL @@ -137,7 +137,7 @@ uint8_t IRKelvinatorAC::getMode() { return (remote_state[0] & ~KELVINATOR_MODE_MASK); } -void IRKelvinatorAC::setMode(uint8_t mode) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setMode(uint8_t mode) { // If we get an unexpected mode, default to AUTO. if (mode > KELVINATOR_HEAT) mode = KELVINATOR_AUTO; remote_state[0] = (remote_state[0] & KELVINATOR_MODE_MASK) | mode; @@ -147,7 +147,7 @@ void IRKelvinatorAC::setMode(uint8_t mode) { setTemp(KELVINATOR_AUTO_TEMP); } -void IRKelvinatorAC::setSwingVertical(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setSwingVertical(bool state) { if (state) { remote_state[0] |= KELVINATOR_VENT_SWING; remote_state[4] |= KELVINATOR_VENT_SWING_V; @@ -160,11 +160,11 @@ void IRKelvinatorAC::setSwingVertical(bool state) { remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. } -bool IRKelvinatorAC::getSwingVertical() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getSwingVertical() { return ((remote_state[4] & KELVINATOR_VENT_SWING_V) != 0); } -void IRKelvinatorAC::setSwingHorizontal(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setSwingHorizontal(bool state) { if (state) { remote_state[0] |= KELVINATOR_VENT_SWING; remote_state[4] |= KELVINATOR_VENT_SWING_H; @@ -177,57 +177,57 @@ void IRKelvinatorAC::setSwingHorizontal(bool state) { remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. } -bool IRKelvinatorAC::getSwingHorizontal() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getSwingHorizontal() { return ((remote_state[4] & KELVINATOR_VENT_SWING_H) != 0); } -void IRKelvinatorAC::setQuiet(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setQuiet(bool state) { remote_state[12] &= ~KELVINATOR_QUIET; remote_state[12] |= (state << KELVINATOR_QUIET_OFFSET); } -bool IRKelvinatorAC::getQuiet() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getQuiet() { return ((remote_state[12] & KELVINATOR_QUIET) != 0); } -void IRKelvinatorAC::setIonFilter(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setIonFilter(bool state) { remote_state[2] &= ~KELVINATOR_ION_FILTER; remote_state[2] |= (state << KELVINATOR_ION_FILTER_OFFSET); remote_state[10] = remote_state[2]; // Duplicate to the 2nd command chunk. } -bool IRKelvinatorAC::getIonFilter() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getIonFilter() { return ((remote_state[2] & KELVINATOR_ION_FILTER) != 0); } -void IRKelvinatorAC::setLight(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setLight(bool state) { remote_state[2] &= ~KELVINATOR_LIGHT; remote_state[2] |= (state << KELVINATOR_LIGHT_OFFSET); remote_state[10] = remote_state[2]; // Duplicate to the 2nd command chunk. } -bool IRKelvinatorAC::getLight() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getLight() { return ((remote_state[2] & KELVINATOR_LIGHT) != 0); } // Note: XFan mode is only valid in Cool or Dry mode. -void IRKelvinatorAC::setXFan(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setXFan(bool state) { remote_state[2] &= ~KELVINATOR_XFAN; remote_state[2] |= (state << KELVINATOR_XFAN_OFFSET); remote_state[10] = remote_state[2]; // Duplicate to the 2nd command chunk. } -bool IRKelvinatorAC::getXFan() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getXFan() { return ((remote_state[2] & KELVINATOR_XFAN) != 0); } // Note: Turbo mode is turned off if the fan speed is changed. -void IRKelvinatorAC::setTurbo(bool state) { +void ICACHE_FLASH_ATTR IRKelvinatorAC::setTurbo(bool state) { remote_state[2] &= ~KELVINATOR_TURBO; remote_state[2] |= (state << KELVINATOR_TURBO_OFFSET); remote_state[10] = remote_state[2]; // Duplicate to the 2nd command chunk. } -bool IRKelvinatorAC::getTurbo() { +bool ICACHE_FLASH_ATTR IRKelvinatorAC::getTurbo() { return ((remote_state[2] & KELVINATOR_TURBO) != 0); } diff --git a/lib/IRremoteESP8266/IRMitsubishiAC.cpp b/lib/IRremoteESP8266/IRMitsubishiAC.cpp index 32c13e1d3e..22d9c440cd 100644 --- a/lib/IRremoteESP8266/IRMitsubishiAC.cpp +++ b/lib/IRremoteESP8266/IRMitsubishiAC.cpp @@ -17,31 +17,31 @@ IRMitsubishiAC::IRMitsubishiAC(int pin) : _irsend(pin) { } // Reset the state of the remote to a known good state/sequence. -void IRMitsubishiAC::stateReset() { +void ICACHE_FLASH_ATTR IRMitsubishiAC::stateReset() { for (uint8_t i = 0; i < MITSUBISHI_AC_STATE_LENGTH; i++) remote_state[i] = known_good_state[i]; checksum(); // Calculate the checksum } // Configure the pin for output. -void IRMitsubishiAC::begin() { +void ICACHE_FLASH_ATTR IRMitsubishiAC::begin() { _irsend.begin(); } // Send the current desired state to the IR LED. -void IRMitsubishiAC::send() { +void ICACHE_FLASH_ATTR IRMitsubishiAC::send() { checksum(); // Ensure correct checksum before sending. _irsend.sendMitsubishiAC(remote_state); } // Return a pointer to the internal state date of the remote. -uint8_t* IRMitsubishiAC::getRaw() { +uint8_t* ICACHE_FLASH_ATTR IRMitsubishiAC::getRaw() { checksum(); return remote_state; } // Calculate the checksum for the current internal state of the remote. -void IRMitsubishiAC::checksum() { +void ICACHE_FLASH_ATTR IRMitsubishiAC::checksum() { uint8_t sum = 0; // Checksum is simple addition of all previous bytes stored // as a 8 bit value. @@ -51,19 +51,19 @@ void IRMitsubishiAC::checksum() { } // Set the requested power state of the A/C to off. -void IRMitsubishiAC::on() { +void ICACHE_FLASH_ATTR IRMitsubishiAC::on() { //state = ON; remote_state[5] |= MITSUBISHI_AC_POWER; } // Set the requested power state of the A/C to off. -void IRMitsubishiAC::off() { +void ICACHE_FLASH_ATTR IRMitsubishiAC::off() { //state = OFF; remote_state[5] &= ~MITSUBISHI_AC_POWER; } // Set the requested power state of the A/C. -void IRMitsubishiAC::setPower(bool state) { +void ICACHE_FLASH_ATTR IRMitsubishiAC::setPower(bool state) { if (state) on(); else @@ -71,25 +71,25 @@ void IRMitsubishiAC::setPower(bool state) { } // Return the requested power state of the A/C. -bool IRMitsubishiAC::getPower() { +bool ICACHE_FLASH_ATTR IRMitsubishiAC::getPower() { return((remote_state[5] & MITSUBISHI_AC_POWER) != 0); } // Set the temp. in deg C -void IRMitsubishiAC::setTemp(uint8_t temp) { +void ICACHE_FLASH_ATTR IRMitsubishiAC::setTemp(uint8_t temp) { temp = max(MITSUBISHI_AC_MIN_TEMP, temp); temp = min(MITSUBISHI_AC_MAX_TEMP, temp); remote_state[7] = temp - MITSUBISHI_AC_MIN_TEMP; } // Return the set temp. in deg C -uint8_t IRMitsubishiAC::getTemp() { +uint8_t ICACHE_FLASH_ATTR IRMitsubishiAC::getTemp() { return(remote_state[7] + MITSUBISHI_AC_MIN_TEMP); } // Set the speed of the fan, 0-6. // 0 is auto, 1-5 is the speed, 6 is silent. -void IRMitsubishiAC::setFan(uint8_t fan) { +void ICACHE_FLASH_ATTR IRMitsubishiAC::setFan(uint8_t fan) { // Bounds check if (fan > MITSUBISHI_AC_FAN_SILENT) fan = MITSUBISHI_AC_FAN_MAX; // Set the fan to maximum if out of range. @@ -103,7 +103,7 @@ void IRMitsubishiAC::setFan(uint8_t fan) { } // Return the requested state of the unit's fan. -uint8_t IRMitsubishiAC::getFan() { +uint8_t ICACHE_FLASH_ATTR IRMitsubishiAC::getFan() { uint8_t fan = remote_state[9] & B111; if (fan == MITSUBISHI_AC_FAN_MAX) return MITSUBISHI_AC_FAN_SILENT; @@ -111,7 +111,7 @@ uint8_t IRMitsubishiAC::getFan() { } // Return the requested climate operation mode of the a/c unit. -uint8_t IRMitsubishiAC::getMode() { +uint8_t ICACHE_FLASH_ATTR IRMitsubishiAC::getMode() { /* MITSUBISHI_AC_AUTO MITSUBISHI_AC_COOL @@ -122,7 +122,7 @@ uint8_t IRMitsubishiAC::getMode() { } // Set the requested climate operation mode of the a/c unit. -void IRMitsubishiAC::setMode(uint8_t mode) { +void ICACHE_FLASH_ATTR IRMitsubishiAC::setMode(uint8_t mode) { // If we get an unexpected mode, default to AUTO. switch (mode) { case MITSUBISHI_AC_AUTO: break; @@ -135,7 +135,7 @@ void IRMitsubishiAC::setMode(uint8_t mode) { } // Set the requested vane operation mode of the a/c unit. -void IRMitsubishiAC::setVane(uint8_t mode) { +void ICACHE_FLASH_ATTR IRMitsubishiAC::setVane(uint8_t mode) { mode = max(mode, B111); // bounds check mode |= B1000; mode <<= 3; @@ -143,6 +143,6 @@ void IRMitsubishiAC::setVane(uint8_t mode) { } // Return the requested vane operation mode of the a/c unit. -uint8_t IRMitsubishiAC::getVane() { +uint8_t ICACHE_FLASH_ATTR IRMitsubishiAC::getVane() { return ((remote_state[9] & B00111000) >> 3); } diff --git a/lib/IRremoteESP8266/IRremoteESP8266.cpp b/lib/IRremoteESP8266/IRremoteESP8266.cpp index 493e8d49ed..592cbb8dfc 100644 --- a/lib/IRremoteESP8266/IRremoteESP8266.cpp +++ b/lib/IRremoteESP8266/IRremoteESP8266.cpp @@ -41,62 +41,10 @@ #include "IRremoteESP8266.h" #include "IRremoteInt.h" +#include "IRDaikinESP.h" #include "IRKelvinator.h" #include "IRMitsubishiAC.h" -// These versions of MATCH, MATCH_MARK, and MATCH_SPACE are only for debugging. -// To use them, set DEBUG in IRremoteInt.h -// Normally macros are used for efficiency -#ifdef DEBUG -int MATCH(int measured, int desired) { - Serial.print("Testing: "); - Serial.print(TICKS_LOW(desired), DEC); - Serial.print(" <= "); - Serial.print(measured, DEC); - Serial.print(" <= "); - Serial.println(TICKS_HIGH(desired), DEC); - return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired); -} - -int MATCH_MARK(int measured_ticks, int desired_us) { - Serial.print("Testing mark "); - Serial.print(measured_ticks * USECPERTICK, DEC); - Serial.print(" vs "); - Serial.print(desired_us, DEC); - Serial.print(": "); - Serial.print(TICKS_LOW(desired_us + MARK_EXCESS), DEC); - Serial.print(" <= "); - Serial.print(measured_ticks, DEC); - Serial.print(" <= "); - Serial.println(TICKS_HIGH(desired_us + MARK_EXCESS), DEC); - return measured_ticks >= TICKS_LOW(desired_us + MARK_EXCESS) && - measured_ticks <= TICKS_HIGH(desired_us + MARK_EXCESS); -} - -int MATCH_SPACE(int measured_ticks, int desired_us) { - Serial.print("Testing space "); - Serial.print(measured_ticks * USECPERTICK, DEC); - Serial.print(" vs "); - Serial.print(desired_us, DEC); - Serial.print(": "); - Serial.print(TICKS_LOW(desired_us - MARK_EXCESS), DEC); - Serial.print(" <= "); - Serial.print(measured_ticks, DEC); - Serial.print(" <= "); - Serial.println(TICKS_HIGH(desired_us - MARK_EXCESS), DEC); - return measured_ticks >= TICKS_LOW(desired_us - MARK_EXCESS) && - measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS); -} -#else -int MATCH(int measured, int desired) {return measured >= TICKS_LOW(desired) && - measured <= TICKS_HIGH(desired);} -int MATCH_MARK(int measured_ticks, int desired_us) - {return MATCH(measured_ticks, (desired_us + MARK_EXCESS));} -int MATCH_SPACE(int measured_ticks, int desired_us) - {return MATCH(measured_ticks, (desired_us - MARK_EXCESS));} -// Debugging versions are in IRremote.cpp -#endif - // IRtimer --------------------------------------------------------------------- // This class performs a simple time in useconds since instantiated. // Handles when the system timer wraps around (once). @@ -105,11 +53,11 @@ IRtimer::IRtimer() { reset(); } -void IRtimer::reset() { +void ICACHE_FLASH_ATTR IRtimer::reset() { start = micros(); } -uint32_t IRtimer::elapsed() { +uint32_t ICACHE_FLASH_ATTR IRtimer::elapsed() { uint32_t now = micros(); if (start <= now) // Check if the system timer has wrapped. return (now - start); // No wrap. @@ -123,14 +71,17 @@ IRsend::IRsend(int IRsendPin) { IRpin = IRsendPin; } -void IRsend::begin() { +void ICACHE_FLASH_ATTR IRsend::begin() { pinMode(IRpin, OUTPUT); + ledOff(); // Turn off the IR LED just to be safe. } + // Generic method for sending data that is common to most protocols. // Default to transmitting the Most Significant Bit (MSB) first. -void IRsend::sendData(uint16_t onemark, uint32_t onespace, - uint16_t zeromark, uint32_t zerospace, - uint32_t data, uint8_t nbits, bool MSBfirst) { +void ICACHE_FLASH_ATTR IRsend::sendData(uint16_t onemark, uint32_t onespace, + uint16_t zeromark, uint32_t zerospace, + uint32_t data, uint8_t nbits, + bool MSBfirst) { if (MSBfirst) // Send the MSB first. for (uint32_t mask = 1UL << (nbits - 1); mask; mask >>= 1) if (data & mask) { // 1 @@ -152,7 +103,7 @@ void IRsend::sendData(uint16_t onemark, uint32_t onespace, } } -void IRsend::sendCOOLIX(unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendCOOLIX(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut(38); // Header @@ -187,7 +138,8 @@ void IRsend::sendCOOLIX(unsigned long data, int nbits) { space(COOLIX_HDR_SPACE); // Pause before repeating } -void IRsend::sendNEC (unsigned long data, int nbits, unsigned int repeat) { +void ICACHE_FLASH_ATTR IRsend::sendNEC (unsigned long data, int nbits, + unsigned int repeat) { // Details about timings can be found at: // http://www.sbprojects.com/knowledge/ir/nec.php @@ -203,7 +155,7 @@ void IRsend::sendNEC (unsigned long data, int nbits, unsigned int repeat) { // Footer mark(NEC_BIT_MARK); // Gap to next command. - space(NEC_MIN_COMMAND_LENGTH - usecs.elapsed()); + space(max(0, NEC_MIN_COMMAND_LENGTH - usecs.elapsed())); // Optional command repeat sequence. for (unsigned int i = 0; i < repeat; i++) { @@ -212,32 +164,34 @@ void IRsend::sendNEC (unsigned long data, int nbits, unsigned int repeat) { space(NEC_RPT_SPACE); mark(NEC_BIT_MARK); // Gap till next command. - space(NEC_MIN_COMMAND_LENGTH - usecs.elapsed()); + space(max(0, NEC_MIN_COMMAND_LENGTH - usecs.elapsed())); } } -void IRsend::sendLG (unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendLG (unsigned long data, int nbits, + unsigned int repeat) { + // Args: + // data: The contents of the command you want to send. + // nbits: The bit size of the command being sent. + // repeat: The number of times you want the command to be repeated. + // Set IR carrier frequency enableIROut(38); - // Header - mark(LG_HDR_MARK); - space(LG_HDR_SPACE); - mark(LG_BIT_MARK); - // Data - for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { - if (data & mask) { // 1 - space(LG_ONE_SPACE); - mark(LG_BIT_MARK); - } else { // 0 - space(LG_ZERO_SPACE); - mark(LG_BIT_MARK); - } + // We always send a command, even for repeat=0, hence '<= repeat'. + for (unsigned int i = 0; i <= repeat; i++) { + // Header + mark(LG_HDR_MARK); + space(LG_HDR_SPACE); + // Data + sendData(LG_BIT_MARK, LG_ONE_SPACE, LG_BIT_MARK, LG_ZERO_SPACE, + data, nbits, true); + // Footer + mark(LG_BIT_MARK); + space(LG_RPT_LENGTH); } - // Footer - ledOff(); } -void IRsend::sendWhynter(unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendWhynter(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut(38); // Header @@ -246,21 +200,15 @@ void IRsend::sendWhynter(unsigned long data, int nbits) { mark(WHYNTER_HDR_MARK); space(WHYNTER_HDR_SPACE); // Data - for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { - if (data & mask) { // 1 - mark(WHYNTER_ONE_MARK); - space(WHYNTER_ONE_SPACE); - } else { // 0 - mark(WHYNTER_ZERO_MARK); - space(WHYNTER_ZERO_SPACE); - } - } + sendData(WHYNTER_ONE_MARK, WHYNTER_ONE_SPACE, WHYNTER_ZERO_MARK, + WHYNTER_ZERO_SPACE, data, nbits, true); // Footer mark(WHYNTER_ZERO_MARK); space(WHYNTER_ZERO_SPACE); } -void IRsend::sendSony(unsigned long data, int nbits, unsigned int repeat) { +void ICACHE_FLASH_ATTR IRsend::sendSony(unsigned long data, int nbits, + unsigned int repeat) { // Send an IR command to a compatible Sony device. // // Args: @@ -293,7 +241,7 @@ void IRsend::sendSony(unsigned long data, int nbits, unsigned int repeat) { // A space() is always performed last, so no need to turn off the LED. } -void IRsend::sendRaw(unsigned int buf[], int len, int hz) { +void ICACHE_FLASH_ATTR IRsend::sendRaw(unsigned int buf[], int len, int hz) { // Set IR carrier frequency enableIROut(hz); for (int i = 0; i < len; i++) { @@ -309,7 +257,7 @@ void IRsend::sendRaw(unsigned int buf[], int len, int hz) { // Global Cache format w/o emitter ID or request ID. Starts from hertz, // followed by number of times to emit (count), // followed by offset for repeats, followed by code as units of periodic time. -void IRsend::sendGC(unsigned int buf[], int len) { +void ICACHE_FLASH_ATTR IRsend::sendGC(unsigned int buf[], int len) { int khz = buf[0]/1000; // GC data starts with frequency in Hz. enableIROut(khz); int periodic_time = 1000/khz; @@ -335,7 +283,7 @@ void IRsend::sendGC(unsigned int buf[], int len) { } // Note: first bit must be a one (start bit) -void IRsend::sendRC5(unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendRC5(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut(36); // Header @@ -357,7 +305,7 @@ void IRsend::sendRC5(unsigned long data, int nbits) { } // Caller needs to take care of flipping the toggle bit -void IRsend::sendRC6(unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendRC6(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut(36); // Header @@ -387,9 +335,45 @@ void IRsend::sendRC6(unsigned long data, int nbits) { ledOff(); } -void IRsend::sendPanasonic(unsigned int address, unsigned long data) { +// Send a Philips RC-MM packet. +// Based on http://www.sbprojects.com/knowledge/ir/rcmm.php +// Args: +// data: The data we want to send. MSB first. +// nbits: The number of bits of data to send. (Typically 12, 24, or 32[Nokia]) +// Status: ALPHA (untested and unconfirmed.) +void ICACHE_FLASH_ATTR IRsend::sendRCMM(uint32_t data, uint8_t nbits) { + // Set IR carrier frequency + enableIROut(36); + IRtimer usecs = IRtimer(); + + // Header + mark(RCMM_HDR_MARK); + space(RCMM_HDR_SPACE); + // Data + uint32_t mask = B11 << (nbits - 2); + // RC-MM sends data 2 bits at a time. + for (uint8_t i = nbits; i > 0; i -= 2) { + mark(RCMM_BIT_MARK); + // Grab the next Most Significant Bits to send. + switch ((data & mask) >> (i - 2)) { + case B00: space(RCMM_BIT_SPACE_0); break; + case B01: space(RCMM_BIT_SPACE_1); break; + case B10: space(RCMM_BIT_SPACE_2); break; + case B11: space(RCMM_BIT_SPACE_3); break; + } + mask >>= 2; + } + // Footer + mark(RCMM_BIT_MARK); + // Protocol requires us to wait at least RCMM_RPT_LENGTH usecs from the start + // or RCMM_MIN_GAP usecs. + space(max(RCMM_RPT_LENGTH - usecs.elapsed(), RCMM_MIN_GAP)); +} + +void ICACHE_FLASH_ATTR IRsend::sendPanasonic(unsigned int address, + unsigned long data) { // Set IR carrier frequency - enableIROut(35); + enableIROut(37); // Header mark(PANASONIC_HDR_MARK); space(PANASONIC_HDR_SPACE); @@ -406,73 +390,67 @@ void IRsend::sendPanasonic(unsigned int address, unsigned long data) { ledOff(); } -void IRsend::sendJVC(unsigned long data, int nbits, int repeat) { +void ICACHE_FLASH_ATTR IRsend::sendJVC(unsigned long data, int nbits, + unsigned int repeat) { + // Args: + // data: The contents of the command you want to send. + // nbits: The bit size of the command being sent. + // repeat: The number of times you want the command to be repeated. + // + // Based on information at: http://www.sbprojects.com/knowledge/ir/jvc.php + // Set IR carrier frequency enableIROut(38); + + IRtimer usecs = IRtimer(); // Header - if (!repeat) { - mark(JVC_HDR_MARK); - space(JVC_HDR_SPACE); - } - // Data - for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { - if (data & mask) { // 1 - mark(JVC_BIT_MARK); - space(JVC_ONE_SPACE); - } else { // 0 - mark(JVC_BIT_MARK); - space(JVC_ZERO_SPACE); - } + mark(JVC_HDR_MARK); + space(JVC_HDR_SPACE); + + // We always send the data & footer at least once, hence '<= repeat'. + for (unsigned int i = 0; i <= repeat; i++) { + // Data + sendData(JVC_BIT_MARK, JVC_ONE_SPACE, JVC_BIT_MARK, JVC_ZERO_SPACE, + data, nbits, true); + // Footer + mark(JVC_BIT_MARK); + // Wait till the end of the repeat time window before we send another code. + space(max(0, JVC_RPT_LENGTH - usecs.elapsed())); + usecs.reset(); } - // Footer - mark(JVC_BIT_MARK); - ledOff(); + // No need to turn off the LED as we will always end with a space(). } -void IRsend::sendSAMSUNG(unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendSAMSUNG(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut(38); // Header mark(SAMSUNG_HDR_MARK); space(SAMSUNG_HDR_SPACE); // Data - for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { - if (data & mask) { // 1 - mark(SAMSUNG_BIT_MARK); - space(SAMSUNG_ONE_SPACE); - } else { // 0 - mark(SAMSUNG_BIT_MARK); - space(SAMSUNG_ZERO_SPACE); - } - } + sendData(SAMSUNG_BIT_MARK, SAMSUNG_ONE_SPACE, SAMSUNG_BIT_MARK, + SAMSUNG_ZERO_SPACE, data, nbits, true); // Footer mark(SAMSUNG_BIT_MARK); ledOff(); } // Denon, from https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp -void IRsend::sendDenon (unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendDenon (unsigned long data, int nbits) { // Set IR carrier frequency enableIROut(38); // Header mark(DENON_HDR_MARK); space(DENON_HDR_SPACE); // Data - for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { - if (data & mask) { // 1 - mark (DENON_BIT_MARK); - space(DENON_ONE_SPACE); - } else { // 0 - mark (DENON_BIT_MARK); - space(DENON_ZERO_SPACE); - } - } + sendData(DENON_BIT_MARK, DENON_ONE_SPACE, DENON_BIT_MARK, DENON_ZERO_SPACE, + data, nbits, true); // Footer mark(DENON_BIT_MARK); ledOff(); } -void IRsend::mark(unsigned int usec) { +void ICACHE_FLASH_ATTR IRsend::mark(unsigned int usec) { // Sends an IR mark for the specified number of microseconds. // The mark output is modulated at the PWM frequency. IRtimer usecTimer = IRtimer(); @@ -485,12 +463,12 @@ void IRsend::mark(unsigned int usec) { } } -void IRsend::ledOff() { +void ICACHE_FLASH_ATTR IRsend::ledOff() { digitalWrite(IRpin, LOW); } /* Leave pin off for time (given in microseconds) */ -void IRsend::space(unsigned long time) { +void ICACHE_FLASH_ATTR IRsend::space(unsigned long time) { // Sends an IR space for the specified number of microseconds. // A space is no output, so the PWM output is disabled. ledOff(); @@ -504,7 +482,7 @@ void IRsend::space(unsigned long time) { } } -void IRsend::enableIROut(int khz) { +void ICACHE_FLASH_ATTR IRsend::enableIROut(int khz) { // Enables IR output. // The khz value controls the modulation frequency in kilohertz. @@ -536,90 +514,84 @@ i.e. use 0x1C10 instead of 0x0000000000001C10 which is listed in the linked LIRC file. */ -void IRsend::sendSharpRaw(unsigned long data, int nbits) { +void ICACHE_FLASH_ATTR IRsend::sendSharpRaw(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut(38); // Sending codes in bursts of 3 (normal, inverted, normal) makes transmission // much more reliable. That's the exact behaviour of CD-S6470 remote control. for (int n = 0; n < 3; n++) { // Data - for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { - if (data & mask) { // 1 - mark(SHARP_BIT_MARK); - space(SHARP_ONE_SPACE); - } else { // 0 - mark(SHARP_BIT_MARK); - space(SHARP_ZERO_SPACE); - } - } + sendData(SHARP_BIT_MARK, SHARP_ONE_SPACE, SHARP_BIT_MARK, SHARP_ZERO_SPACE, + data, nbits, true); // Footer mark(SHARP_BIT_MARK); - space(SHARP_ZERO_SPACE); - delay(40); + space(SHARP_ZERO_SPACE + 40000); data = data ^ SHARP_TOGGLE_MASK; } } // Sharp send compatible with data obtained through decodeSharp -void IRsend::sendSharp(unsigned int address, unsigned int command) { +void ICACHE_FLASH_ATTR IRsend::sendSharp(unsigned int address, + unsigned int command) { sendSharpRaw((address << 10) | (command << 2) | 2, 15); } -void IRsend::sendDISH(unsigned long data, int nbits) { +// Send an IR command to a DISH device. +// Note: Typically a DISH device needs to get a command a total of at least 4 +// times to accept it. +// Args: +// data: The contents of the command you want to send. +// nbits: The bit size of the command being sent. +// repeat: The number of times you want the command to be repeated. +void ICACHE_FLASH_ATTR IRsend::sendDISH(unsigned long data, int nbits, + unsigned int repeat) { // Set IR carrier frequency enableIROut(56); - // Header - mark(DISH_HDR_MARK); - space(DISH_HDR_SPACE); - for (int i = 0; i < nbits; i++) { - if (data & DISH_TOP_BIT) { - mark(DISH_BIT_MARK); - space(DISH_ONE_SPACE); - } else { - mark(DISH_BIT_MARK); - space(DISH_ZERO_SPACE); - } - data <<= 1; + // We always send a command, even for repeat=0, hence '<= repeat'. + for (unsigned int i = 0; i <= repeat; i++) { + // Header + mark(DISH_HDR_MARK); + space(DISH_HDR_SPACE); + // Data + sendData(DISH_BIT_MARK, DISH_ONE_SPACE, DISH_BIT_MARK, DISH_ZERO_SPACE, + data, nbits, true); + // Footer + space(DISH_RPT_SPACE); } - // Footer - ledOff(); } // From https://github.com/mharizanov/Daikin-AC-remote-control-over-the-Internet/tree/master/IRremote -void IRsend::sendDaikin(unsigned char daikin[]) { - sendDaikinChunk(daikin, 8,0); - delay(29); - sendDaikinChunk(daikin, 19,8); -} +void ICACHE_FLASH_ATTR IRsend::sendDaikin(unsigned char data[]) { + // Args: + // data: An array of DAIKIN_COMMAND_LENGTH bytes containing the IR command. -void IRsend::sendDaikinChunk(unsigned char buf[], int len, int start) { - int data2; // Set IR carrier frequency enableIROut(38); - // Header + // Header #1 mark(DAIKIN_HDR_MARK); space(DAIKIN_HDR_SPACE); - // Data - for (int i = start; i < start+len; i++) { - data2=buf[i]; - - for (int j = 0; j < 8; j++) { - if ((1 << j & data2)) { - mark(DAIKIN_ONE_MARK); - space(DAIKIN_ONE_SPACE); - } else { - mark(DAIKIN_ZERO_MARK); - space(DAIKIN_ZERO_SPACE); - } - } - } - // Footer + // Data #1 + for (uint8_t i = 0; i < 8; i++) + sendData(DAIKIN_ONE_MARK, DAIKIN_ONE_SPACE, DAIKIN_ZERO_MARK, + DAIKIN_ZERO_SPACE, data[i], 8, false); + // Footer #1 + mark(DAIKIN_ONE_MARK); + space(DAIKIN_ZERO_SPACE + 29000); + + // Header #2 + mark(DAIKIN_HDR_MARK); + space(DAIKIN_HDR_SPACE); + // Data #2 + for (uint8_t i = 8; i < DAIKIN_COMMAND_LENGTH; i++) + sendData(DAIKIN_ONE_MARK, DAIKIN_ONE_SPACE, DAIKIN_ZERO_MARK, + DAIKIN_ZERO_SPACE, data[i], 8, false); + // Footer #2 mark(DAIKIN_ONE_MARK); space(DAIKIN_ZERO_SPACE); } -void IRsend::sendKelvinator(unsigned char data[]) { +void ICACHE_FLASH_ATTR IRsend::sendKelvinator(unsigned char data[]) { uint8_t i = 0; // Set IR carrier frequency enableIROut(38); @@ -671,26 +643,14 @@ void IRsend::sendKelvinator(unsigned char data[]) { ledOff(); } -void IRsend::sendSherwood(unsigned long data, int nbits, unsigned int repeat) { +void ICACHE_FLASH_ATTR IRsend::sendSherwood(unsigned long data, int nbits, + unsigned int repeat) { // Sherwood remote codes appear to be NEC codes with a manditory repeat code. // i.e. repeat should be >= 1. sendNEC(data, nbits, max(1, repeat)); } -void IRsend::sendMitsubishiACChunk(uint8_t data) { - // send a chunk(byte) of Mitsubishi AC data - for (uint8_t bit = 0; bit < 8; bit++, data >>= 1) { - if (data & B1) { // 1 - mark(MITSUBISHI_AC_BIT_MARK); - space(MITSUBISHI_AC_ONE_SPACE); - } else { // 0 - mark(MITSUBISHI_AC_BIT_MARK); - space(MITSUBISHI_AC_ZERO_SPACE); - } - } -} - -void IRsend::sendMitsubishiAC(unsigned char data[]) { +void ICACHE_FLASH_ATTR IRsend::sendMitsubishiAC(unsigned char data[]) { // Set IR carrier frequency enableIROut(38); // Mitsubishi AC remote sends the packet twice. @@ -700,11 +660,14 @@ void IRsend::sendMitsubishiAC(unsigned char data[]) { space(MITSUBISHI_AC_HDR_SPACE); // Data for (uint8_t i = 0; i < MITSUBISHI_AC_STATE_LENGTH; i++) - sendMitsubishiACChunk(data[i]); + sendData(MITSUBISHI_AC_BIT_MARK, MITSUBISHI_AC_ONE_SPACE, + MITSUBISHI_AC_BIT_MARK, MITSUBISHI_AC_ZERO_SPACE, + data[i], 8, false); // Footer mark(MITSUBISHI_AC_RPT_MARK); space(MITSUBISHI_AC_RPT_SPACE); } + // A space() is always performed last, so no need to turn off the LED. } // --------------------------------------------------------------- @@ -721,10 +684,9 @@ volatile irparams_t irparams; static void ICACHE_RAM_ATTR read_timeout(void *arg __attribute__((unused))) { os_intr_lock(); - if (irparams.rawlen) { + if (irparams.rawlen) irparams.rcvstate = STATE_STOP; - } - os_intr_unlock(); + os_intr_unlock(); } static void ICACHE_RAM_ATTR gpio_intr() { @@ -735,25 +697,32 @@ static void ICACHE_RAM_ATTR gpio_intr() { os_timer_disarm(&timer); GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status); - if (irparams.rawlen >= RAWBUF) { + // Grab a local copy of rawlen to reduce instructions used in IRAM. + // This is an ugly premature optimisation code-wise, but we do everything we + // can to save IRAM. + // It seems referencing the value via the structure uses more instructions. + // Less instructions means faster and less IRAM used. + // N.B. It saves about 13 bytes of IRAM. + uint16_t rawlen = irparams.rawlen; + + if (rawlen >= RAWBUF) { irparams.overflow = true; irparams.rcvstate = STATE_STOP; } - if (irparams.rcvstate == STATE_STOP) { + if (irparams.rcvstate == STATE_STOP) return; - } if (irparams.rcvstate == STATE_IDLE) { - irparams.overflow = false; irparams.rcvstate = STATE_MARK; - irparams.rawbuf[irparams.rawlen++] = 1; + irparams.rawbuf[rawlen] = 1; } else { if (now < start) - irparams.rawbuf[irparams.rawlen++] = (0xFFFFFFFF - start + now) / USECPERTICK + 1; + irparams.rawbuf[rawlen] = (0xFFFFFFFF - start + now) / USECPERTICK + 1; else - irparams.rawbuf[irparams.rawlen++] = (now - start) / USECPERTICK + 1; + irparams.rawbuf[rawlen] = (now - start) / USECPERTICK + 1; } + irparams.rawlen++; start = now; #define ONCE 0 @@ -765,10 +734,9 @@ IRrecv::IRrecv(int recvpin) { } // initialization -void IRrecv::enableIRIn() { +void ICACHE_FLASH_ATTR IRrecv::enableIRIn() { // initialize state machine variables - irparams.rcvstate = STATE_IDLE; - irparams.rawlen = 0; + resume(); // Initialize timer os_timer_disarm(&timer); @@ -778,28 +746,70 @@ void IRrecv::enableIRIn() { attachInterrupt(irparams.recvpin, gpio_intr, CHANGE); } -void IRrecv::disableIRIn() { +void ICACHE_FLASH_ATTR IRrecv::disableIRIn() { os_timer_disarm(&timer); detachInterrupt(irparams.recvpin); } -void IRrecv::resume() { +void ICACHE_FLASH_ATTR IRrecv::resume() { irparams.rcvstate = STATE_IDLE; irparams.rawlen = 0; + irparams.overflow = false; } -// Decodes the received IR message -// Returns true if is data ready -// Results of decoding are stored in results -bool IRrecv::decode(decode_results *results) { - results->rawbuf = irparams.rawbuf; - results->rawlen = irparams.rawlen; - results->overflow = irparams.overflow; +// Make a copy of the interrupt state/data. +// Needed because irparams is marked as volatile, thus memcpy() isn't allowed. +// Only call this when you know the interrupt handlers won't modify anything. +// i.e. In STATE_STOP. +// +// Args: +// dest: Pointer to an irparams_t structure to copy to. +void ICACHE_FLASH_ATTR IRrecv::copyIrParams(irparams_t *dest) { + // Typecast src and dest addresses to (char *) + char *csrc = (char *)&irparams; + char *cdest = (char *)dest; + + // Copy contents of src[] to dest[] + for (int i=0; irawbuf = irparams.rawbuf; + results->rawlen = irparams.rawlen; + results->overflow = irparams.overflow; + } else { + copyIrParams(save); // Duplicate the interrupt's memory. + resume(); // It's now safe to rearm. The IR message won't be overridden. + resumed = true; + // Point the results at the saved copy. + results->rawbuf = save->rawbuf; + results->rawlen = save->rawlen; + results->overflow = save->overflow; + } + #ifdef DEBUG Serial.println("Attempting NEC decode"); #endif @@ -838,6 +848,12 @@ bool IRrecv::decode(decode_results *results) { if (decodeRC6(results)) { return true; } +#ifdef DEBUG + Serial.println("Attempting RC-MM decode"); +#endif + if (decodeRCMM(results)) { + return true; + } #ifdef DEBUG Serial.println("Attempting Panasonic decode"); #endif @@ -868,6 +884,12 @@ bool IRrecv::decode(decode_results *results) { if (decodeWhynter(results)) { return true; } +#ifdef DEBUG + Serial.println("Attempting Denon decode"); +#endif + if (decodeDenon(results)) { + return true; + } // decodeHash returns a hash on any input. // Thus, it needs to be last in the list. // If you add any decodes, add them before this. @@ -875,44 +897,140 @@ bool IRrecv::decode(decode_results *results) { return true; } // Throw away and start over - resume(); + if (!resumed) // Check if we have already resumed. + resume(); return false; } +// Calculate the lower bound of the nr. of ticks. +// +// Args: +// usecs: Nr. of uSeconds. +// tolerance: Percent as an integer. e.g. 10 is 10% +// Returns: +// Nr. of ticks. +uint32_t IRrecv::ticksLow(uint32_t usecs, uint8_t tolerance) { + // max() used to ensure the result can't drop below 0 before the cast. + return((uint32_t) max(usecs * (1.0 - tolerance/100.)/USECPERTICK, 0)); +} + +// Calculate the upper bound of the nr. of ticks. +// +// Args: +// usecs: Nr. of uSeconds. +// tolerance: Percent as an integer. e.g. 10 is 10% +// Returns: +// Nr. of ticks. +uint32_t IRrecv::ticksHigh(uint32_t usecs, uint8_t tolerance) { + return((uint32_t) usecs * (1.0 + tolerance/100.)/USECPERTICK + 1); +} + +// Check if we match a pulse(measured_ticks) with the desired_us within +// +/-tolerance percent. +// +// Args: +// measured_ticks: The recorded period of the signal pulse. +// desired_us: The expected period (in useconds) we are matching against. +// tolerance: A percentage expressed as an integer. e.g. 10 is 10%. +// +// Returns: +// Boolean: true if it matches, false if it doesn't. +bool ICACHE_FLASH_ATTR IRrecv::match(uint32_t measured_ticks, + uint32_t desired_us, + uint8_t tolerance) { + #ifdef DEBUG + Serial.print("Matching: "); + Serial.print(ticksLow(desired_us, tolerance), DEC); + Serial.print(" <= "); + Serial.print(measured_ticks, DEC); + Serial.print(" <= "); + Serial.println(ticksHigh(desired_us, tolerance), DEC); + #endif + return (measured_ticks >= ticksLow(desired_us, tolerance) && + measured_ticks <= ticksHigh(desired_us, tolerance)); +} + +// Check if we match a mark signal(measured_ticks) with the desired_us within +// +/-tolerance percent, after an expected is excess is added. +// +// Args: +// measured_ticks: The recorded period of the signal pulse. +// desired_us: The expected period (in useconds) we are matching against. +// tolerance: A percentage expressed as an integer. e.g. 10 is 10%. +// excess: Nr. of useconds. +// +// Returns: +// Boolean: true if it matches, false if it doesn't. +bool ICACHE_FLASH_ATTR IRrecv::matchMark(uint32_t measured_ticks, + uint32_t desired_us, + uint8_t tolerance, int excess) { + #ifdef DEBUG + Serial.print("Matching MARK "); + Serial.print(measured_ticks * USECPERTICK, DEC); + Serial.print(" vs "); + Serial.print(desired_us, DEC); + Serial.print(". "); + #endif + return match(measured_ticks, desired_us + excess, tolerance); +} +// Check if we match a space signal(measured_ticks) with the desired_us within +// +/-tolerance percent, after an expected is excess is removed. +// +// Args: +// measured_ticks: The recorded period of the signal pulse. +// desired_us: The expected period (in useconds) we are matching against. +// tolerance: A percentage expressed as an integer. e.g. 10 is 10%. +// excess: Nr. of useconds. +// +// Returns: +// Boolean: true if it matches, false if it doesn't. +bool ICACHE_FLASH_ATTR IRrecv::matchSpace(uint32_t measured_ticks, + uint32_t desired_us, + uint8_t tolerance, int excess) { + #ifdef DEBUG + Serial.print("Matching SPACE "); + Serial.print(measured_ticks * USECPERTICK, DEC); + Serial.print(" vs "); + Serial.print(desired_us, DEC); + Serial.print(". "); + #endif + return match(measured_ticks, desired_us - excess, tolerance); +} + // NECs have a repeat only 4 items long -bool IRrecv::decodeNEC(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeNEC(decode_results *results) { long data = 0; int offset = 1; // Skip initial space // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], NEC_HDR_MARK)) { return false; } offset++; // Check for repeat - if (irparams.rawlen == 4 && - MATCH_SPACE(results->rawbuf[offset], NEC_RPT_SPACE) && - MATCH_MARK(results->rawbuf[offset+1], NEC_BIT_MARK)) { + if (results->rawlen == 4 && + matchSpace(results->rawbuf[offset], NEC_RPT_SPACE) && + matchMark(results->rawbuf[offset+1], NEC_BIT_MARK)) { results->bits = 0; results->value = REPEAT; results->decode_type = NEC; return true; } - if (irparams.rawlen < 2 * NEC_BITS + 4) { + if (results->rawlen < 2 * NEC_BITS + 4) { return false; } // Initial space - if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], NEC_HDR_SPACE)) { return false; } offset++; for (int i = 0; i < NEC_BITS; i++) { - if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], NEC_BIT_MARK)) { return false; } offset++; - if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], NEC_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset], NEC_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -926,9 +1044,9 @@ bool IRrecv::decodeNEC(decode_results *results) { return true; } -bool IRrecv::decodeSony(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeSony(decode_results *results) { long data = 0; - if (irparams.rawlen < 2 * SONY_BITS + 2) { + if (results->rawlen < 2 * SONY_BITS + 2) { return false; } int offset = 0; // Dont skip first space, check its size @@ -946,19 +1064,19 @@ bool IRrecv::decodeSony(decode_results *results) { offset++; // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], SONY_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], SONY_HDR_MARK)) { return false; } offset++; - while (offset + 1 < irparams.rawlen) { - if (!MATCH_SPACE(results->rawbuf[offset], SONY_HDR_SPACE)) { + while (offset + 1 < results->rawlen) { + if (!matchSpace(results->rawbuf[offset], SONY_HDR_SPACE)) { break; } offset++; - if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) { + if (matchMark(results->rawbuf[offset], SONY_ONE_MARK)) { data = (data << 1) | 1; - } else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) { + } else if (matchMark(results->rawbuf[offset], SONY_ZERO_MARK)) { data <<= 1; } else { return false; @@ -977,10 +1095,10 @@ bool IRrecv::decodeSony(decode_results *results) { return true; } -bool IRrecv::decodeWhynter(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeWhynter(decode_results *results) { long data = 0; - if (irparams.rawlen < 2 * WHYNTER_BITS + 6) { + if (results->rawlen < 2 * WHYNTER_BITS + 6) { return false; } @@ -988,34 +1106,34 @@ bool IRrecv::decodeWhynter(decode_results *results) { // sequence begins with a bit mark and a zero space - if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], WHYNTER_BIT_MARK)) { return false; } offset++; - if (!MATCH_SPACE(results->rawbuf[offset], WHYNTER_ZERO_SPACE)) { + if (!matchSpace(results->rawbuf[offset], WHYNTER_ZERO_SPACE)) { return false; } offset++; // header mark and space - if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], WHYNTER_HDR_MARK)) { return false; } offset++; - if (!MATCH_SPACE(results->rawbuf[offset], WHYNTER_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], WHYNTER_HDR_SPACE)) { return false; } offset++; // data bits for (int i = 0; i < WHYNTER_BITS; i++) { - if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], WHYNTER_BIT_MARK)) { return false; } offset++; - if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], WHYNTER_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset],WHYNTER_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset],WHYNTER_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -1024,7 +1142,7 @@ bool IRrecv::decodeWhynter(decode_results *results) { } // trailing mark - if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], WHYNTER_BIT_MARK)) { return false; } // Success @@ -1036,9 +1154,9 @@ bool IRrecv::decodeWhynter(decode_results *results) { // I think this is a Sanyo decoder - serial = SA 8650B // Looks like Sony except for timings, 48 chars of data and time/space different -bool IRrecv::decodeSanyo(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeSanyo(decode_results *results) { long data = 0; - if (irparams.rawlen < 2 * SANYO_BITS + 2) { + if (results->rawlen < 2 * SANYO_BITS + 2) { return false; } int offset = 1; // Skip first space @@ -1062,25 +1180,25 @@ bool IRrecv::decodeSanyo(decode_results *results) { offset++; // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], SANYO_HDR_MARK)) { return false; } offset++; // Skip Second Mark - if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], SANYO_HDR_MARK)) { return false; } offset++; - while (offset + 1 < irparams.rawlen) { - if (!MATCH_SPACE(results->rawbuf[offset], SANYO_HDR_SPACE)) { + while (offset + 1 < results->rawlen) { + if (!matchSpace(results->rawbuf[offset], SANYO_HDR_SPACE)) { break; } offset++; - if (MATCH_MARK(results->rawbuf[offset], SANYO_ONE_MARK)) { + if (matchMark(results->rawbuf[offset], SANYO_ONE_MARK)) { data = (data << 1) | 1; - } else if (MATCH_MARK(results->rawbuf[offset], SANYO_ZERO_MARK)) { + } else if (matchMark(results->rawbuf[offset], SANYO_ZERO_MARK)) { data <<= 1; } else { return false; @@ -1100,11 +1218,11 @@ bool IRrecv::decodeSanyo(decode_results *results) { } // Looks like Sony except for timings, 48 chars of data and time/space different -bool IRrecv::decodeMitsubishi(decode_results *results) { - // Serial.print("?!? decoding Mitsubishi:");Serial.print(irparams.rawlen); +bool ICACHE_FLASH_ATTR IRrecv::decodeMitsubishi(decode_results *results) { + // Serial.print("?!? decoding Mitsubishi:");Serial.print(results->rawlen); // Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2); long data = 0; - if (irparams.rawlen < 2 * MITSUBISHI_BITS + 2) { + if (results->rawlen < 2 * MITSUBISHI_BITS + 2) { return false; } int offset = 1; // Skip first space @@ -1132,21 +1250,21 @@ bool IRrecv::decodeMitsubishi(decode_results *results) { // 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7 // Initial Space - if (!MATCH_MARK(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { + if (!matchMark(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { return false; } offset++; - while (offset + 1 < irparams.rawlen) { - if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ONE_MARK)) { + while (offset + 1 < results->rawlen) { + if (matchMark(results->rawbuf[offset], MITSUBISHI_ONE_MARK)) { data = (data << 1) | 1; - } else if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ZERO_MARK)) { + } else if (matchMark(results->rawbuf[offset], MITSUBISHI_ZERO_MARK)) { data <<= 1; } else { // Serial.println("A"); Serial.println(offset); Serial.println(results->rawbuf[offset]); return false; } offset++; - if (!MATCH_SPACE(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { // Serial.println("B"); Serial.println(offset); Serial.println(results->rawbuf[offset]); break; } @@ -1171,8 +1289,8 @@ bool IRrecv::decodeMitsubishi(decode_results *results) { // offset and used are updated to keep track of the current position. // t1 is the time interval for a single bit in microseconds. // Returns -1 for error (measured time interval is not a multiple of t1). -int IRrecv::getRClevel(decode_results *results, int *offset, int *used, - int t1) { +int ICACHE_FLASH_ATTR IRrecv::getRClevel(decode_results *results, int *offset, + int *used, int t1) { if (*offset >= results->rawlen) { // After end of recorded buffer, assume SPACE. return SPACE; @@ -1182,11 +1300,11 @@ int IRrecv::getRClevel(decode_results *results, int *offset, int *used, int correction = (val == MARK) ? MARK_EXCESS : - MARK_EXCESS; int avail; - if (MATCH(width, t1 + correction)) { + if (match(width, t1 + correction)) { avail = 1; - } else if (MATCH(width, 2*t1 + correction)) { + } else if (match(width, 2*t1 + correction)) { avail = 2; - } else if (MATCH(width, 3*t1 + correction)) { + } else if (match(width, 3*t1 + correction)) { avail = 3; } else { return -1; @@ -1207,8 +1325,8 @@ int IRrecv::getRClevel(decode_results *results, int *offset, int *used, return val; } -bool IRrecv::decodeRC5(decode_results *results) { - if (irparams.rawlen < MIN_RC5_SAMPLES + 2) { +bool ICACHE_FLASH_ATTR IRrecv::decodeRC5(decode_results *results) { + if (results->rawlen < MIN_RC5_SAMPLES + 2) { return false; } int offset = 1; // Skip gap space @@ -1219,7 +1337,7 @@ bool IRrecv::decodeRC5(decode_results *results) { if (getRClevel(results, &offset, &used, RC5_T1) != SPACE) return false; if (getRClevel(results, &offset, &used, RC5_T1) != MARK) return false; int nbits; - for (nbits = 0; offset < irparams.rawlen; nbits++) { + for (nbits = 0; offset < results->rawlen; nbits++) { int levelA = getRClevel(results, &offset, &used, RC5_T1); int levelB = getRClevel(results, &offset, &used, RC5_T1); if (levelA == SPACE && levelB == MARK) { @@ -1240,17 +1358,17 @@ bool IRrecv::decodeRC5(decode_results *results) { return true; } -bool IRrecv::decodeRC6(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeRC6(decode_results *results) { if (results->rawlen < MIN_RC6_SAMPLES) { return false; } int offset = 1; // Skip first space // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], RC6_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], RC6_HDR_MARK)) { return false; } offset++; - if (!MATCH_SPACE(results->rawbuf[offset], RC6_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], RC6_HDR_SPACE)) { return false; } offset++; @@ -1289,25 +1407,78 @@ bool IRrecv::decodeRC6(decode_results *results) { return true; } -bool IRrecv::decodePanasonic(decode_results *results) { +// Decode a Philips RC-MM packet (between 12 & 32 bits) if possible. +// Places successful decode information in the results pointer. +// Returns: +// The decode success status. +// Based on http://www.sbprojects.com/knowledge/ir/rcmm.php +// Status: ALPHA (untested and unconfirmed.) +bool ICACHE_FLASH_ATTR IRrecv::decodeRCMM(decode_results *results) { + uint32_t data = 0; + unsigned int offset = 1; // Skip the leading space. + + int bitSize = results->rawlen - 4; + if (bitSize < 12 || bitSize > 32) + return false; + // Header decode + if (!matchMark(results->rawbuf[offset++], RCMM_HDR_MARK)) + return false; + if (!matchSpace(results->rawbuf[offset++], RCMM_HDR_SPACE)) + return false; + // Data decode + // RC-MM has two bits of data per mark/space pair. + for (int i = 0; i < bitSize; i += 2) { + data <<= 2; + // Use non-default tolerance & excess for matching some of the spaces as the + // defaults are too generous and causes mis-matches in some cases. + if (!matchMark(results->rawbuf[offset++], RCMM_BIT_MARK, RCMM_TOLERANCE)) + return false; + if (matchSpace(results->rawbuf[offset], + RCMM_BIT_SPACE_0, TOLERANCE, RCMM_EXCESS)) + data += 0; + else if (matchSpace(results->rawbuf[offset], + RCMM_BIT_SPACE_1, TOLERANCE, RCMM_EXCESS)) + data += 1; + else if (matchSpace(results->rawbuf[offset], + RCMM_BIT_SPACE_2, RCMM_TOLERANCE, RCMM_EXCESS)) + data += 2; + else if (matchSpace(results->rawbuf[offset], + RCMM_BIT_SPACE_3, RCMM_TOLERANCE, RCMM_EXCESS)) + data += 3; + else + return false; + offset++; + } + // Footer decode + if (!matchMark(results->rawbuf[offset], RCMM_BIT_MARK)) + return false; + + // Success + results->value = (unsigned long) data; + results->decode_type = RCMM; + results->bits = bitSize; + return true; +} + +bool ICACHE_FLASH_ATTR IRrecv::decodePanasonic(decode_results *results) { unsigned long long data = 0; int offset = 1; // Dont skip first space - if (!MATCH_MARK(results->rawbuf[offset], PANASONIC_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], PANASONIC_HDR_MARK)) { return false; } offset++; - if (!MATCH_MARK(results->rawbuf[offset], PANASONIC_HDR_SPACE)) { + if (!matchMark(results->rawbuf[offset], PANASONIC_HDR_SPACE)) { return false; } offset++; // decode address for (int i = 0; i < PANASONIC_BITS; i++) { - if (!MATCH(results->rawbuf[offset++], PANASONIC_BIT_MARK)) { + if (!match(results->rawbuf[offset++], PANASONIC_BIT_MARK)) { return false; } - if (MATCH(results->rawbuf[offset],PANASONIC_ONE_SPACE)) { + if (match(results->rawbuf[offset],PANASONIC_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) { + } else if (match(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -1321,31 +1492,31 @@ bool IRrecv::decodePanasonic(decode_results *results) { return true; } -bool IRrecv::decodeLG(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeLG(decode_results *results) { long data = 0; int offset = 1; // Skip first space // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], LG_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], LG_HDR_MARK)) { return false; } offset++; - if (irparams.rawlen < 2 * LG_BITS + 1 ) { + if (results->rawlen < 2 * LG_BITS + 1 ) { return false; } // Initial space - if (!MATCH_SPACE(results->rawbuf[offset], LG_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], LG_HDR_SPACE)) { return false; } offset++; for (int i = 0; i < LG_BITS; i++) { - if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], LG_BIT_MARK)) { return false; } offset++; - if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], LG_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset], LG_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -1353,7 +1524,7 @@ bool IRrecv::decodeLG(decode_results *results) { offset++; } //Stop bit - if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)){ + if (!matchMark(results->rawbuf[offset], LG_BIT_MARK)){ return false; } // Success @@ -1363,39 +1534,39 @@ bool IRrecv::decodeLG(decode_results *results) { return true; } -bool IRrecv::decodeJVC(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeJVC(decode_results *results) { long data = 0; int offset = 1; // Skip first space // Check for repeat - if (irparams.rawlen - 1 == 33 && - MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK) && - MATCH_MARK(results->rawbuf[irparams.rawlen-1], JVC_BIT_MARK)) { + if (results->rawlen - 1 == 33 && + matchMark(results->rawbuf[offset], JVC_BIT_MARK) && + matchMark(results->rawbuf[irparams.rawlen-1], JVC_BIT_MARK)) { results->bits = 0; results->value = REPEAT; results->decode_type = JVC; return true; } // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], JVC_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], JVC_HDR_MARK)) { return false; } offset++; - if (irparams.rawlen < 2 * JVC_BITS + 1 ) { + if (results->rawlen < 2 * JVC_BITS + 1 ) { return false; } // Initial space - if (!MATCH_SPACE(results->rawbuf[offset], JVC_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], JVC_HDR_SPACE)) { return false; } offset++; for (int i = 0; i < JVC_BITS; i++) { - if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], JVC_BIT_MARK)) { return false; } offset++; - if (MATCH_SPACE(results->rawbuf[offset], JVC_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], JVC_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset], JVC_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset], JVC_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -1403,7 +1574,7 @@ bool IRrecv::decodeJVC(decode_results *results) { offset++; } //Stop bit - if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], JVC_BIT_MARK)) { return false; } // Success @@ -1414,39 +1585,39 @@ bool IRrecv::decodeJVC(decode_results *results) { } // SAMSUNGs have a repeat only 4 items long -bool IRrecv::decodeSAMSUNG(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeSAMSUNG(decode_results *results) { long data = 0; int offset = 1; // Dont skip first space // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], SAMSUNG_HDR_MARK)) { return false; } offset++; // Check for repeat - if (irparams.rawlen == 4 && - MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE) && - MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK)) { + if (results->rawlen == 4 && + matchSpace(results->rawbuf[offset], SAMSUNG_RPT_SPACE) && + matchMark(results->rawbuf[offset+1], SAMSUNG_BIT_MARK)) { results->bits = 0; results->value = REPEAT; results->decode_type = SAMSUNG; return true; } - if (irparams.rawlen < 2 * SAMSUNG_BITS + 2) { + if (results->rawlen < 2 * SAMSUNG_BITS + 2) { return false; } // Initial space - if (!MATCH_SPACE(results->rawbuf[offset], SAMSUNG_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], SAMSUNG_HDR_SPACE)) { return false; } offset++; for (int i = 0; i < SAMSUNG_BITS; i++) { - if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset], SAMSUNG_BIT_MARK)) { return false; } offset++; - if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -1462,33 +1633,33 @@ bool IRrecv::decodeSAMSUNG(decode_results *results) { // From https://github.com/mharizanov/Daikin-AC-remote-control-over-the-Internet/tree/master/IRremote // decoding not actually tested -bool IRrecv::decodeDaikin(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeDaikin(decode_results *results) { long data = 0; int offset = 1; // Skip first space - if (irparams.rawlen < 2 * DAIKIN_BITS + 4) { + if (results->rawlen < 2 * DAIKIN_BITS + 4) { //return false; } // Initial mark - if (!MATCH_MARK(results->rawbuf[offset], DAIKIN_HDR_MARK)) { + if (!matchMark(results->rawbuf[offset], DAIKIN_HDR_MARK)) { return false; } offset++; - if (!MATCH_SPACE(results->rawbuf[offset], DAIKIN_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset], DAIKIN_HDR_SPACE)) { return false; } offset++; for (int i = 0; i < 32; i++) { - if (!MATCH_MARK(results->rawbuf[offset], DAIKIN_ONE_MARK)) { + if (!matchMark(results->rawbuf[offset], DAIKIN_ONE_MARK)) { return false; } offset++; - if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], DAIKIN_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset], DAIKIN_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -1509,13 +1680,13 @@ bool IRrecv::decodeDaikin(decode_results *results) { //========== for (int i = 0; i < 32; i++) { - if (!MATCH_MARK(results->rawbuf[offset], DAIKIN_ONE_MARK)) { + if (!matchMark(results->rawbuf[offset], DAIKIN_ONE_MARK)) { return false; } offset++; - if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], DAIKIN_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset], DAIKIN_ZERO_SPACE)) { data <<= 1; } else { return false; @@ -1534,7 +1705,7 @@ bool IRrecv::decodeDaikin(decode_results *results) { //Serial.println (reversed, HEX); //=========== - if (!MATCH_SPACE(results->rawbuf[offset], 29000)) { + if (!matchSpace(results->rawbuf[offset], 29000)) { //Serial.println ("no gap"); return false; } @@ -1548,20 +1719,20 @@ bool IRrecv::decodeDaikin(decode_results *results) { } // Denon, from https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp -bool IRrecv::decodeDenon (decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeDenon (decode_results *results) { unsigned long data = 0; // Somewhere to build our code int offset = 1; // Skip the Gap reading // Check we have the right amount of data - if (irparams.rawlen != 1 + 2 + (2 * DENON_BITS) + 1) { + if (results->rawlen != 1 + 2 + (2 * DENON_BITS) + 1) { return false; } // Check initial Mark+Space match - if (!MATCH_MARK (results->rawbuf[offset++], DENON_HDR_MARK )) { + if (!matchMark (results->rawbuf[offset++], DENON_HDR_MARK )) { return false; } - if (!MATCH_SPACE(results->rawbuf[offset++], DENON_HDR_SPACE)) { + if (!matchSpace(results->rawbuf[offset++], DENON_HDR_SPACE)) { return false; } @@ -1569,14 +1740,14 @@ bool IRrecv::decodeDenon (decode_results *results) { for (int i = 0; i < DENON_BITS; i++) { // Each bit looks like: DENON_MARK + DENON_SPACE_1 -> 1 // or : DENON_MARK + DENON_SPACE_0 -> 0 - if (!MATCH_MARK(results->rawbuf[offset++], DENON_BIT_MARK)) { + if (!matchMark(results->rawbuf[offset++], DENON_BIT_MARK)) { return false; } // IR data is big-endian, so we shuffle it in from the right: - if (MATCH_SPACE(results->rawbuf[offset], DENON_ONE_SPACE)) { + if (matchSpace(results->rawbuf[offset], DENON_ONE_SPACE)) { data = (data << 1) | 1; - } else if (MATCH_SPACE(results->rawbuf[offset], DENON_ZERO_SPACE)) { + } else if (matchSpace(results->rawbuf[offset], DENON_ZERO_SPACE)) { data = (data << 1) | 0; } else { return false; @@ -1609,7 +1780,8 @@ bool IRrecv::decodeDenon (decode_results *results) { // Compare two tick values, returning 0 if newval is shorter, // 1 if newval is equal, and 2 if newval is longer // Use a tolerance of 20% -int IRrecv::compare(unsigned int oldval, unsigned int newval) { +int ICACHE_FLASH_ATTR IRrecv::compare(unsigned int oldval, + unsigned int newval) { if (newval < oldval * .8) { return 0; } else if (oldval < newval * .8) { @@ -1627,7 +1799,7 @@ int IRrecv::compare(unsigned int oldval, unsigned int newval) { * Hopefully this code is unique for each button. * This isn't a "real" decoding, just an arbitrary value. */ -bool IRrecv::decodeHash(decode_results *results) { +bool ICACHE_FLASH_ATTR IRrecv::decodeHash(decode_results *results) { // Require at least 6 samples to prevent triggering on noise if (results->rawlen < 6) { return false; diff --git a/lib/IRremoteESP8266/IRremoteESP8266.h b/lib/IRremoteESP8266/IRremoteESP8266.h index 247920f62d..5aac0f5df6 100644 --- a/lib/IRremoteESP8266/IRremoteESP8266.h +++ b/lib/IRremoteESP8266/IRremoteESP8266.h @@ -32,6 +32,7 @@ #define IRremote_h #include +#include "IRremoteInt.h" // The following are compile-time library options. // If you change them, recompile the library. @@ -68,7 +69,8 @@ enum decode_type_t { DENON, KELVINATOR, SHERWOOD, - MITSUBISHI_AC + MITSUBISHI_AC, + RCMM }; // Results returned from the decoder @@ -89,30 +91,33 @@ class decode_results { // Decoded value for NEC when a repeat code is received #define REPEAT 0xffffffff -#define SEND_PROTOCOL_NEC case NEC: sendNEC(data, nbits); break; -#define SEND_PROTOCOL_SONY case SONY: sendSony(data, nbits); break; -#define SEND_PROTOCOL_RC5 case RC5: sendRC5(data, nbits); break; -#define SEND_PROTOCOL_RC6 case RC6: sendRC6(data, nbits); break; -#define SEND_PROTOCOL_DISH case DISH: sendDISH(data, nbits); break; -#define SEND_PROTOCOL_JVC case JVC: sendJVC(data, nbits, 0); break; -#define SEND_PROTOCOL_SAMSUNG case SAMSUNG: sendSAMSUNG(data, nbits); break; -#define SEND_PROTOCOL_LG case LG: sendLG(data, nbits); break; -#define SEND_PROTOCOL_WHYNTER case WHYNTER: sendWhynter(data, nbits); break; -#define SEND_PROTOCOL_COOLIX case COOLIX: sendCOOLIX(data, nbits); break; -#define SEND_PROTOCOL_DENON case DENON: sendDenon(data, nbits); break; +#define SEND_PROTOCOL_NEC case NEC: sendNEC(data, nbits); break; +#define SEND_PROTOCOL_SONY case SONY: sendSony(data, nbits); break; +#define SEND_PROTOCOL_RC5 case RC5: sendRC5(data, nbits); break; +#define SEND_PROTOCOL_RC6 case RC6: sendRC6(data, nbits); break; +#define SEND_PROTOCOL_DISH case DISH: sendDISH(data, nbits); break; +#define SEND_PROTOCOL_JVC case JVC: sendJVC(data, nbits, 0); break; +#define SEND_PROTOCOL_SAMSUNG case SAMSUNG: sendSAMSUNG(data, nbits); break; +#define SEND_PROTOCOL_LG case LG: sendLG(data, nbits); break; +#define SEND_PROTOCOL_WHYNTER case WHYNTER: sendWhynter(data, nbits); break; +#define SEND_PROTOCOL_COOLIX case COOLIX: sendCOOLIX(data, nbits); break; +#define SEND_PROTOCOL_DENON case DENON: sendDenon(data, nbits); break; #define SEND_PROTOCOL_SHERWOOD case SHERWOOD: sendSherwood(data, nbits); break; +#define SEND_PROTOCOL_RCMM case RCMM: sendRCMM(data, nbits); break; + // main class for receiving IR class IRrecv { public: IRrecv(int recvpin); - bool decode(decode_results *results); + bool decode(decode_results *results, irparams_t *save=NULL); void enableIRIn(); void disableIRIn(); void resume(); private: // These are called by decode + void copyIrParams(irparams_t *dest); int getRClevel(decode_results *results, int *offset, int *used, int t1); bool decodeNEC(decode_results *results); bool decodeSony(decode_results *results); @@ -120,6 +125,7 @@ class IRrecv bool decodeMitsubishi(decode_results *results); bool decodeRC5(decode_results *results); bool decodeRC6(decode_results *results); + bool decodeRCMM(decode_results *results); bool decodePanasonic(decode_results *results); bool decodeLG(decode_results *results); bool decodeJVC(decode_results *results); @@ -131,6 +137,14 @@ class IRrecv bool decodeDaikin(decode_results *results); bool decodeDenon(decode_results *results); int compare(unsigned int oldval, unsigned int newval); + uint32_t ticksLow(uint32_t usecs, uint8_t tolerance=TOLERANCE); + uint32_t ticksHigh(uint32_t usecs, uint8_t tolerance=TOLERANCE); + bool match(uint32_t measured_ticks, uint32_t desired_us, + uint8_t tolerance=TOLERANCE); + bool matchMark(uint32_t measured_ticks, uint32_t desired_us, + uint8_t tolerance=TOLERANCE, int excess=MARK_EXCESS); + bool matchSpace(uint32_t measured_ticks, uint32_t desired_us, + uint8_t tolerance=TOLERANCE, int excess=MARK_EXCESS); }; // Only used for testing; can remove virtual for shorter code @@ -139,6 +153,7 @@ class IRrecv #else #define VIRTUAL #endif + class IRsend { public: @@ -158,12 +173,13 @@ class IRsend SEND_PROTOCOL_COOLIX SEND_PROTOCOL_DENON SEND_PROTOCOL_SHERWOOD + SEND_PROTOCOL_RCMM } }; void sendCOOLIX(unsigned long data, int nbits); void sendWhynter(unsigned long data, int nbits); void sendNEC(unsigned long data, int nbits=32, unsigned int repeat=0); - void sendLG(unsigned long data, int nbits); + void sendLG(unsigned long data, int nbits=28, unsigned int repeat=0); // sendSony() should typically be called with repeat=2 as Sony devices // expect the code to be sent at least 3 times. (code + 2 repeats = 3 codes) // As the legacy use of this procedure was only to send a single code @@ -176,15 +192,19 @@ class IRsend void sendGC(unsigned int buf[], int len); void sendRC5(unsigned long data, int nbits); void sendRC6(unsigned long data, int nbits); - void sendDISH(unsigned long data, int nbits); + void sendRCMM(uint32_t data, uint8_t nbits=24); + // sendDISH() should typically be called with repeat=3 as DISH devices + // expect the code to be sent at least 4 times. (code + 3 repeats = 4 codes) + // As the legacy use of this procedure was only to send a single code + // it defaults to repeat=0 for backward compatiblity. + void sendDISH(unsigned long data, int nbits, unsigned int repeat=0); void sendSharp(unsigned int address, unsigned int command); void sendSharpRaw(unsigned long data, int nbits); void sendPanasonic(unsigned int address, unsigned long data); - void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does. - void sendSAMSUNG(unsigned long data, int nbits); - void sendDaikin(unsigned char daikin[]); - void sendDaikinChunk(unsigned char buf[], int len, int start); - void sendDenon(unsigned long data, int nbits); + void sendJVC(unsigned long data, int nbits, unsigned int repeat=0); + void sendSAMSUNG(unsigned long data, int nbits=32); + void sendDaikin(unsigned char data[]); + void sendDenon(unsigned long data, int nbits=14); void sendKelvinator(unsigned char data[]); void sendSherwood(unsigned long data, int nbits=32, unsigned int repeat=1); void sendMitsubishiAC(unsigned char data[]); @@ -210,12 +230,4 @@ class IRtimer { uint32_t start; }; -// Some useful constants -#define USECPERTICK 50 // microseconds per clock interrupt tick -#define RAWBUF 100 // Length of raw duration buffer - -// Marks tend to be 100us too long, and spaces 100us too short -// when received due to sensor lag. -#define MARK_EXCESS 100 - #endif diff --git a/lib/IRremoteESP8266/IRremoteInt.h b/lib/IRremoteESP8266/IRremoteInt.h index ade21d5db5..44012337cf 100644 --- a/lib/IRremoteESP8266/IRremoteInt.h +++ b/lib/IRremoteESP8266/IRremoteInt.h @@ -60,10 +60,11 @@ #define NEC_RPT_SPACE 2250 #define NEC_MIN_COMMAND_LENGTH 108000UL +// Timings based on http://www.sbprojects.com/knowledge/ir/sirc.php #define SONY_HDR_MARK 2400 #define SONY_HDR_SPACE 600 -#define SONY_ONE_MARK 1200 -#define SONY_ZERO_MARK 600 +#define SONY_ONE_MARK 1250 // Experiments suggest +50 to spec is better. +#define SONY_ZERO_MARK 650 // Experiments suggest +50 to spec is better. #define SONY_RPT_LENGTH 45000 #define SONY_DOUBLE_SPACE_USECS 500 // usually see 713 - not using ticks as get number wrapround @@ -105,6 +106,20 @@ #define RC6_T1 444 #define RC6_RPT_LENGTH 46000 +// http://www.sbprojects.com/knowledge/ir/rcmm.php +#define RCMM_HDR_MARK 416 +#define RCMM_HDR_SPACE 277 +#define RCMM_BIT_MARK 166 +#define RCMM_BIT_SPACE_0 277 +#define RCMM_BIT_SPACE_1 444 +#define RCMM_BIT_SPACE_2 611 +#define RCMM_BIT_SPACE_3 777 +#define RCMM_RPT_LENGTH 27778 +#define RCMM_MIN_GAP 3360 +// Use a tolerance of +/-10% when matching some data spaces. +#define RCMM_TOLERANCE 10 +#define RCMM_EXCESS 50 + #define SHARP_BIT_MARK 245 #define SHARP_ONE_SPACE 1805 #define SHARP_ZERO_SPACE 795 @@ -118,13 +133,13 @@ #define DISH_ONE_SPACE 1700 #define DISH_ZERO_SPACE 2800 #define DISH_RPT_SPACE 6200 -#define DISH_TOP_BIT 0x8000 -#define PANASONIC_HDR_MARK 3502 -#define PANASONIC_HDR_SPACE 1750 -#define PANASONIC_BIT_MARK 502 -#define PANASONIC_ONE_SPACE 1244 -#define PANASONIC_ZERO_SPACE 400 +// Ref: http://www.remotecentral.com/cgi-bin/mboard/rc-pronto/thread.cgi?26152 +#define PANASONIC_HDR_MARK 3456 +#define PANASONIC_HDR_SPACE 1728 +#define PANASONIC_BIT_MARK 432 +#define PANASONIC_ONE_SPACE 1296 +#define PANASONIC_ZERO_SPACE 432 #define JVC_HDR_MARK 8000 #define JVC_HDR_SPACE 4000 @@ -184,15 +199,18 @@ #define KELVINATOR_GAP_SPACE 19950U #define KELVINATOR_CMD_FOOTER 2U -#define TOLERANCE 25 // percent tolerance in measurements -#define LTOL (1.0 - TOLERANCE/100.) -#define UTOL (1.0 + TOLERANCE/100.) +// Some useful constants +#define USECPERTICK 50 // microseconds per clock interrupt tick +#define RAWBUF 100 // Length of raw duration buffer + +// Marks tend to be 100us too long, and spaces 100us too short +// when received due to sensor lag. +#define MARK_EXCESS 100 #define _GAP 5000 // Minimum map between transmissions #define GAP_TICKS (_GAP/USECPERTICK) -#define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK)) -#define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1)) +#define TOLERANCE 25 // default percent tolerance in measurements // receiver states #define STATE_IDLE 2 @@ -200,14 +218,18 @@ #define STATE_SPACE 4 #define STATE_STOP 5 +#define RAWBUF 100 // Length of raw duration buffer + // information for the interrupt handler typedef struct { - uint8_t recvpin; // pin for IR data from detector - uint8_t rcvstate; // state machine - unsigned int timer; // state timer, counts 50uS ticks. - unsigned int rawbuf[RAWBUF]; // raw data - uint8_t rawlen; // counter of entries in rawbuf - uint8_t overflow; + uint8_t recvpin; // pin for IR data from detector + uint8_t rcvstate; // state machine + unsigned int timer; // state timer, counts 50uS ticks. + unsigned int rawbuf[RAWBUF]; // raw data + // uint16_t is used for rawlen as it saves 3 bytes of iram in the interrupt + // handler. Don't ask why, I don't know. It just does. + uint16_t rawlen; // counter of entries in rawbuf. + uint8_t overflow; // Buffer overflow indicator. } irparams_t; diff --git a/lib/IRremoteESP8266/README.md b/lib/IRremoteESP8266/README.md index bb9040cd27..25e53eeb1a 100644 --- a/lib/IRremoteESP8266/README.md +++ b/lib/IRremoteESP8266/README.md @@ -18,6 +18,15 @@ Seb's notes : I also changed the pulse parameters for Samsung, update the Panaso 5. Restart your Arduino ide 6. Check out the examples +###### Using Git to install library ( Linux ) +``` +cd ~/Arduino/libraries +git clone https://github.com/markszabo/IRremoteESP8266.git +``` +###### To Update to the latest version of the library +` +cd ~/Arduino/libraries/IRremoteESP8266 && git pull +` ## Contributing If you want to contribute to this project: - Report bugs and errors diff --git a/lib/IRremoteESP8266/examples/IRServer/IRServer.ino b/lib/IRremoteESP8266/examples/IRServer/IRServer.ino index 94cf929ee9..229f53ade5 100644 --- a/lib/IRremoteESP8266/examples/IRServer/IRServer.ino +++ b/lib/IRremoteESP8266/examples/IRServer/IRServer.ino @@ -26,7 +26,7 @@ void handleIr(){ for (uint8_t i=0; i -int RECV_PIN = 2; //an IR detector/demodulator is connected to GPIO pin 2 +// An IR detector/demodulator is connected to GPIO pin 14(D5 on a NodeMCU board). +int RECV_PIN = 14; IRrecv irrecv(RECV_PIN); -void setup ( ) -{ - Serial.begin(9600); // Status message will be sent to PC at 9600 baud +decode_results results; // Somewhere to store the results +irparams_t save; // A place to copy the interrupt state while decoding. + +void setup() { + Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY); // Status message will be sent to the PC at 115200 baud irrecv.enableIRIn(); // Start the receiver } //+============================================================================= // Display IR code // -void ircode (decode_results *results) -{ +void ircode(decode_results *results) { // Panasonic has an Address if (results->decode_type == PANASONIC) { Serial.print(results->panasonicAddress, HEX); Serial.print(":"); } - // Print Code Serial.print(results->value, HEX); } @@ -35,8 +41,7 @@ void ircode (decode_results *results) //+============================================================================= // Display encoding type // -void encoding (decode_results *results) -{ +void encoding(decode_results *results) { switch (results->decode_type) { default: case UNKNOWN: Serial.print("UNKNOWN"); break ; @@ -54,14 +59,14 @@ void encoding (decode_results *results) case WHYNTER: Serial.print("WHYNTER"); break ; case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ; case PANASONIC: Serial.print("PANASONIC"); break ; + case DENON: Serial.print("DENON"); break ; } } //+============================================================================= // Dump out the decode_results structure. // -void dumpInfo (decode_results *results) -{ +void dumpInfo (decode_results *results) { if (results->overflow) { Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF"); return; @@ -83,8 +88,7 @@ void dumpInfo (decode_results *results) //+============================================================================= // Dump out the decode_results structure. // -void dumpRaw (decode_results *results) -{ +void dumpRaw(decode_results *results) { // Print Raw data Serial.print("Timing["); Serial.print(results->rawlen-1, DEC); @@ -113,8 +117,7 @@ void dumpRaw (decode_results *results) //+============================================================================= // Dump out the decode_results structure. // -void dumpCode (decode_results *results) -{ +void dumpCode (decode_results *results) { // Start declaration Serial.print("unsigned int "); // variable type Serial.print("rawData["); // array name @@ -129,7 +132,7 @@ void dumpCode (decode_results *results) } // End declaration - Serial.print("};"); // + Serial.print("};"); // // Comment Serial.print(" // "); @@ -142,7 +145,6 @@ void dumpCode (decode_results *results) // Now dump "known" codes if (results->decode_type != UNKNOWN) { - // Some protocols have an address if (results->decode_type == PANASONIC) { Serial.print("unsigned int addr = 0x"); @@ -160,15 +162,12 @@ void dumpCode (decode_results *results) //+============================================================================= // The repeating section of the code // -void loop ( ) -{ - decode_results results; // Somewhere to store the results - - if (irrecv.decode(&results)) { // Grab an IR code +void loop() { + // Check if the IR code has been received. + if (irrecv.decode(&results, &save)) { dumpInfo(&results); // Output the results dumpRaw(&results); // Output the results in RAW format dumpCode(&results); // Output the results as source code Serial.println(""); // Blank line between entries - irrecv.resume(); // Prepare for the next value } } diff --git a/lib/IRremoteESP8266/examples/IRsendDemo/IRsendDemo.ino b/lib/IRremoteESP8266/examples/IRsendDemo/IRsendDemo.ino index 449b79a22a..f1b730993d 100644 --- a/lib/IRremoteESP8266/examples/IRsendDemo/IRsendDemo.ino +++ b/lib/IRremoteESP8266/examples/IRsendDemo/IRsendDemo.ino @@ -1,18 +1,40 @@ /* - * IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend - * An IR LED must be connected to ESP8266 pin 0. - * Version 0.1 June, 2015 + * IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend. + * + * An IR LED circuit *MUST* be connected to ESP8266 pin 4 (D2). + * + * TL;DR: The IR LED needs to be driven by a transistor for a good result. + * + * Suggested circuit: + * https://github.com/markszabo/IRremoteESP8266/wiki#ir-sending + * + * Common mistakes & tips: + * * Don't just connect the IR LED directly to the pin, it won't + * have enough current to drive the IR LED effectively. + * * Make sure you have the IR LED polarity correct. + * See: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity + * * Typical digital camera/phones can be used to see if the IR LED is flashed. + * Replace the IR LED with a normal LED if you don't have a digital camera + * when debugging. + * * Avoid using the following pins unless you really know what you are doing: + * * Pin 0/D3: Can interfere with the boot/program mode & support circuits. + * * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will interfere. + * * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere. + * * ESP-01 modules are tricky. We suggest you use a module with more GPIOs + * for your first time. e.g. ESP-12 etc. + * + * Version 1.0 April, 2017 * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com */ #include -IRsend irsend(0); //an IR led is connected to GPIO pin 0 +IRsend irsend(4); //an IR led is connected to GPIO pin 4 (D2) void setup() { irsend.begin(); - Serial.begin(9600); + Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY); } void loop() { @@ -20,6 +42,6 @@ void loop() { irsend.sendNEC(0x00FFE01FUL, 32); delay(2000); Serial.println("Sony"); - irsend.sendSony(0xa90, 12); + irsend.sendSony(0xa90, 12, 2); delay(2000); } diff --git a/lib/IRremoteESP8266/library.json b/lib/IRremoteESP8266/library.json index 776e3c3b67..e07ce2cbe6 100644 --- a/lib/IRremoteESP8266/library.json +++ b/lib/IRremoteESP8266/library.json @@ -1,6 +1,6 @@ { "name": "IRremoteESP8266", - "version": "1.0.2", + "version": "1.2.0", "keywords": "infrared, ir, remote, esp8266", "description": "Send and receive infrared signals with multiple protocols (ESP8266)", "repository": diff --git a/lib/IRremoteESP8266/library.properties b/lib/IRremoteESP8266/library.properties index 403f88cd2d..0f97016fc2 100644 --- a/lib/IRremoteESP8266/library.properties +++ b/lib/IRremoteESP8266/library.properties @@ -1,5 +1,5 @@ name=IRremoteESP8266 -version=1.0.2 +version=1.2.0 author=Sebastien Warin, Mark Szabo, Ken Shirriff, David Conran maintainer=Mark Szabo, David Conran, Sebastien Warin, Roi Dayan, Massimiliano Pinto sentence=Send and receive infrared signals with multiple protocols (ESP8266)