From b52c5a884fcf5bfbe4ed9407f03a0a4f75c8cccb Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sun, 23 Apr 2017 20:50:37 +0200 Subject: [PATCH] now no longer a submodule. lib/IRremoteESP8266 upstream version v1.0.2 --- .gitmodules | 3 - lib/IRremoteESP8266 | 1 - lib/IRremoteESP8266/.travis.yml | 33 + lib/IRremoteESP8266/Contributors.md | 13 + lib/IRremoteESP8266/IRDaikinESP.cpp | 152 ++ lib/IRremoteESP8266/IRDaikinESP.h | 100 + lib/IRremoteESP8266/IRKelvinator.cpp | 233 +++ lib/IRremoteESP8266/IRKelvinator.h | 160 ++ lib/IRremoteESP8266/IRMitsubishiAC.cpp | 148 ++ lib/IRremoteESP8266/IRMitsubishiAC.h | 52 + lib/IRremoteESP8266/IRremoteESP8266.cpp | 1647 +++++++++++++++++ lib/IRremoteESP8266/IRremoteESP8266.h | 221 +++ lib/IRremoteESP8266/IRremoteInt.h | 237 +++ lib/IRremoteESP8266/LICENSE.txt | 458 +++++ lib/IRremoteESP8266/README.md | 29 + .../examples/IRGCSendDemo/IRGCSendDemo.ino | 26 + .../examples/IRGCTCPServer/IRGCTCPServer.ino | 85 + .../examples/IRServer/IRServer.ino | 88 + .../examples/IRrecvDemo/IRrecvDemo.ino | 28 + .../examples/IRrecvDump/IRrecvDump.ino | 89 + .../examples/IRrecvDumpV2/IRrecvDumpV2.ino | 174 ++ .../examples/IRsendDemo/IRsendDemo.ino | 25 + .../JVCPanasonicSendDemo.ino | 29 + .../TurnOnDaikinAC/TurnOnDaikinAC.ino | 27 + .../TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino | 52 + .../TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino | 42 + lib/IRremoteESP8266/keywords.txt | 68 + lib/IRremoteESP8266/library.json | 44 + lib/IRremoteESP8266/library.properties | 9 + 29 files changed, 4269 insertions(+), 4 deletions(-) delete mode 160000 lib/IRremoteESP8266 create mode 100644 lib/IRremoteESP8266/.travis.yml create mode 100644 lib/IRremoteESP8266/Contributors.md create mode 100644 lib/IRremoteESP8266/IRDaikinESP.cpp create mode 100644 lib/IRremoteESP8266/IRDaikinESP.h create mode 100644 lib/IRremoteESP8266/IRKelvinator.cpp create mode 100644 lib/IRremoteESP8266/IRKelvinator.h create mode 100644 lib/IRremoteESP8266/IRMitsubishiAC.cpp create mode 100644 lib/IRremoteESP8266/IRMitsubishiAC.h create mode 100644 lib/IRremoteESP8266/IRremoteESP8266.cpp create mode 100644 lib/IRremoteESP8266/IRremoteESP8266.h create mode 100644 lib/IRremoteESP8266/IRremoteInt.h create mode 100644 lib/IRremoteESP8266/LICENSE.txt create mode 100644 lib/IRremoteESP8266/README.md create mode 100644 lib/IRremoteESP8266/examples/IRGCSendDemo/IRGCSendDemo.ino create mode 100644 lib/IRremoteESP8266/examples/IRGCTCPServer/IRGCTCPServer.ino create mode 100644 lib/IRremoteESP8266/examples/IRServer/IRServer.ino create mode 100644 lib/IRremoteESP8266/examples/IRrecvDemo/IRrecvDemo.ino create mode 100644 lib/IRremoteESP8266/examples/IRrecvDump/IRrecvDump.ino create mode 100644 lib/IRremoteESP8266/examples/IRrecvDumpV2/IRrecvDumpV2.ino create mode 100644 lib/IRremoteESP8266/examples/IRsendDemo/IRsendDemo.ino create mode 100644 lib/IRremoteESP8266/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino create mode 100644 lib/IRremoteESP8266/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino create mode 100644 lib/IRremoteESP8266/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino create mode 100644 lib/IRremoteESP8266/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino create mode 100644 lib/IRremoteESP8266/keywords.txt create mode 100644 lib/IRremoteESP8266/library.json create mode 100644 lib/IRremoteESP8266/library.properties diff --git a/.gitmodules b/.gitmodules index da6e4db35..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "lib/IRremoteESP8266"] - path = lib/IRremoteESP8266 - url = https://github.com/markszabo/IRremoteESP8266.git diff --git a/lib/IRremoteESP8266 b/lib/IRremoteESP8266 deleted file mode 160000 index a7ad7b08b..000000000 --- a/lib/IRremoteESP8266 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a7ad7b08b67763eb1efe5e97b199a88e471fcd9b diff --git a/lib/IRremoteESP8266/.travis.yml b/lib/IRremoteESP8266/.travis.yml new file mode 100644 index 000000000..a4539ffd8 --- /dev/null +++ b/lib/IRremoteESP8266/.travis.yml @@ -0,0 +1,33 @@ +language: c +env: + - BD=esp8266:esp8266:nodemcuv2: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 + - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino +install: + - ln -s $PWD /usr/local/share/arduino/libraries/ + - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs + - arduino --install-boards esp8266:esp8266 + - arduino --board $BD --save-prefs + - arduino --pref "compiler.warning_level=all" --save-prefs +script: + - arduino --verify --board $BD $PWD/examples/IRrecvDemo/IRrecvDemo.ino + - arduino --verify --board $BD $PWD/examples/IRGCSendDemo/IRGCSendDemo.ino + - arduino --verify --board $BD $PWD/examples/IRGCTCPServer/IRGCTCPServer.ino + - arduino --verify --board $BD $PWD/examples/IRServer/IRServer.ino + - arduino --verify --board $BD $PWD/examples/IRrecvDumpV2/IRrecvDumpV2.ino + - arduino --verify --board $BD $PWD/examples/IRsendDemo/IRsendDemo.ino + - 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 + +notifications: + email: + on_success: change + on_failure: change diff --git a/lib/IRremoteESP8266/Contributors.md b/lib/IRremoteESP8266/Contributors.md new file mode 100644 index 000000000..92717ee10 --- /dev/null +++ b/lib/IRremoteESP8266/Contributors.md @@ -0,0 +1,13 @@ +## Contributors of this project +### Main contributors & maintainers +- [Mark Szabo](https://github.com/markszabo/) : Initial IR sending on ESP8266 +- [Sébastien Warin](https://github.com/sebastienwarin/) (http://sebastien.warin.fr) : Initial IR receiving on ESP8266 +- [David Conran](https://github.com/crankyoldgit/) +- [Roi Dayan](https://github.com/roidayan/) +- [Marcos de Alcântara Marinho](https://github.com/marcosamarinho/) +- [Massimiliano Pinto](https://github.com/pintomax/) +- [Darsh Patel](https://github.com/darshkpatel/) + +All contributors can be found on the [contributors site](https://github.com/markszabo/IRremoteESP8266/graphs/contributors). + +### Contributors of the [original project](https://github.com/z3t0/Arduino-IRremote) can be found on the [original project's contributors page](https://github.com/z3t0/Arduino-IRremote/blob/master/Contributors.md) diff --git a/lib/IRremoteESP8266/IRDaikinESP.cpp b/lib/IRremoteESP8266/IRDaikinESP.cpp new file mode 100644 index 000000000..02fd25cf3 --- /dev/null +++ b/lib/IRremoteESP8266/IRDaikinESP.cpp @@ -0,0 +1,152 @@ +/* +An Arduino sketch to emulate IR Daikin ARC433** remote control unit +Read more on http://harizanov.com/2012/02/control-daikin-air-conditioner-over-the-internet/ +*/ + +#include + +IRDaikinESP::IRDaikinESP(int pin) : _irsend(pin) +{ +} + +void IRDaikinESP::begin() +{ + _irsend.begin(); +} + +void IRDaikinESP::send() +{ + _irsend.sendDaikin(daikin); +} + +void IRDaikinESP::checksum() +{ + uint8_t sum = 0; + uint8_t i; + + for(i = 0; i <= 6; i++){ + sum += daikin[i]; + } + + daikin[7] = sum &0xFF; + sum=0; + for(i = 8; i <= 25; i++){ + sum += daikin[i]; + } + daikin[26] = sum &0xFF; +} + +void IRDaikinESP::on() +{ + //state = ON; + daikin[13] |= 0x01; + checksum(); +} + +void IRDaikinESP::off() +{ + //state = OFF; + daikin[13] &= 0xFE; + checksum(); +} + +uint8_t IRDaikinESP::getPower() +{ + return (daikin[13])&0x01; +} + +// DAIKIN_SILENT or DAIKIN_POWERFUL +void IRDaikinESP::setAux(uint8_t aux) +{ + daikin[21] = aux; + checksum(); +} + +uint8_t IRDaikinESP::getAux(){ + return daikin[21]; +} + + +// Set the temp in deg C +void IRDaikinESP::setTemp(uint8_t temp) +{ + if (temp < 18) + temp = 18; + else if (temp > 32) + temp = 32; + daikin[14] = (temp)*2; + checksum(); +} + +uint8_t 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) +{ + // Set the fan speed bits, leave low 4 bits alone + uint8_t fanset; + daikin[16] = daikin[16] & 0x0F; + if (fan >= 1 && fan <= 5) + fanset = 0x20 + (0x10 * fan); + else + fanset = 0xA0; + daikin[16] = daikin[16] | fanset; + checksum(); +} + +uint8_t IRDaikinESP::getFan() +{ + uint8_t fan = daikin[16] >> 4; + fan = fan - 2; + if (fan > 5) + fan = 0; + return fan; +} + +uint8_t IRDaikinESP::getMode() +{/* + DAIKIN_COOL + DAIKIN_HEAT + DAIKIN_FAN + DAIKIN_AUTO + DAIKIN_DRY + */ + return (daikin[13])>>4; +} + +void IRDaikinESP::setMode(uint8_t mode) +{ + daikin[13]=mode<<4 | getPower(); + checksum(); +} + +void IRDaikinESP::setSwingVertical(uint8_t swing) +{ + if (swing) + daikin[16] = daikin[16] | 0x0F; + else + daikin[16] = daikin[16] & 0xF0; + checksum(); +} + +uint8_t IRDaikinESP::getSwingVertical() +{ + return (daikin[16])&0x01; +} + +void IRDaikinESP::setSwingHorizontal(uint8_t swing) +{ + if (swing) + daikin[17] = daikin[17] | 0x0F; + else + daikin[17] = daikin[17] & 0xF0; + checksum(); +} + +uint8_t IRDaikinESP::getSwingHorizontal() +{ + return (daikin[17])&0x01; +} diff --git a/lib/IRremoteESP8266/IRDaikinESP.h b/lib/IRremoteESP8266/IRDaikinESP.h new file mode 100644 index 000000000..59327675f --- /dev/null +++ b/lib/IRremoteESP8266/IRDaikinESP.h @@ -0,0 +1,100 @@ + +#include +#include + +#define DAIKIN_COOL B011 +#define DAIKIN_HEAT B100 +#define DAIKIN_FAN B110 +#define DAIKIN_AUTO B000 +#define DAIKIN_DRY B010 + +#define DAIKIN_POWERFUL B00000010 +#define DAIKIN_SILENT B00100000 + +/* + Daikin AC map + byte 7= checksum of the first part (and last byte before a 29ms pause) + byte 13=mode + b7 = 0 + b6+b5+b4 = Mode + Modes: b6+b5+b4 + 011 = Cool + 100 = Heat (temp 23) + 110 = FAN (temp not shown, but 25) + 000 = Fully Automatic (temp 25) + 010 = DRY (temp 0xc0 = 96 degrees c) + b3 = 0 + b2 = OFF timer set + b1 = ON timer set + b0 = Air Conditioner ON + byte 14=temp*2 (Temp should be between 18 - 32) + byte 16=Fan + FAN control + b7+b6+b5+b4 = Fan speed + Fan: b7+b6+b5+b4 + 0×30 = 1 bar + 0×40 = 2 bar + 0×50 = 3 bar + 0×60 = 4 bar + 0×70 = 5 bar + 0xa0 = Auto + 0xb0 = Not auto, moon + tree + b3+b2+b1+b0 = Swing control up/down + Swing control up/down: + 0000 = Swing up/down off + 1111 = Swing up/down on + byte 17 + Swing control left/right: + 0000 = Swing left/right off + 1111 = Swing left/right on + byte 21=Aux -> Powerful (bit 1), Silent (bit 5) + byte 24=Aux2 -> Intelligent eye on (bit 7) + byte 26= checksum of the second part +*/ + +#define DAIKIN_COMMAND_LENGTH 27 + +class IRDaikinESP +{ + public: + IRDaikinESP(int pin); + //: IRsend(pin){}; + + void send(); + + void begin(); + void on(); + void off(); + uint8_t getPower(); + + void setAux(uint8_t aux); + uint8_t getAux(); + + void setTemp(uint8_t temp); + uint8_t getTemp(); + + void setFan(uint8_t fan); + uint8_t getFan(); + + uint8_t getMode(); + void setMode(uint8_t mode); + + void setSwingVertical(uint8_t swing); + uint8_t getSwingVertical(); + void setSwingHorizontal(uint8_t swing); + uint8_t getSwingHorizontal(); + + private: + // # of bytes per command + unsigned char daikin[DAIKIN_COMMAND_LENGTH] = { + 0x11,0xDA,0x27,0xF0,0x00,0x00,0x00,0x20, + //0 1 2 3 4 5 6 7 + 0x11,0xDA,0x27,0x00,0x00,0x41,0x1E,0x00, + //8 9 10 11 12 13 14 15 + 0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0xE3 }; + //16 17 18 19 20 21 22 23 24 25 26 + + void checksum(); + + IRsend _irsend; +}; diff --git a/lib/IRremoteESP8266/IRKelvinator.cpp b/lib/IRremoteESP8266/IRKelvinator.cpp new file mode 100644 index 000000000..c4a13199a --- /dev/null +++ b/lib/IRremoteESP8266/IRKelvinator.cpp @@ -0,0 +1,233 @@ +/* +Code to emulate IR Kelvinator YALIF remote control unit, which should control +at least the following Kelvinator A/C units: + KSV26CRC, KSV26HRC, KSV35CRC, KSV35HRC, KSV53HRC, KSV62HRC, KSV70CRC, + KSV70HRC, KSV80HRC. + +Note: + * Unsupported: + - All Sleep modes. + - All Timer modes. + - "I Feel" button & mode. + - Energy Saving mode. + - Low Heat mode. + - Farenheit. +*/ + +#include + +IRKelvinatorAC::IRKelvinatorAC(int pin) : _irsend(pin) { + stateReset(); +} + +void 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() { + _irsend.begin(); +} + +void 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() { + fixup(); // Ensure correct settings before sending. + _irsend.sendKelvinator(remote_state); +} + +uint8_t* IRKelvinatorAC::getRaw() { + fixup(); // Ensure correct settings before sending. + return remote_state; +} + +// Many Bothans died to bring us this information. +void IRKelvinatorAC::checksum() { + // For each command + options block. + for (uint8_t offset = 0; offset < KELVINATOR_STATE_LENGTH; offset += 8) { + uint8_t sum = KELVINATOR_CHECKSUM_START; + // Sum the lower half of the first 4 bytes of this block. + for(uint8_t i = 0; i < 4; i++) { + sum += (remote_state[i + offset] & 0xFU); + } + // then sum the upper half of the next 3 bytes. + for(uint8_t i = 4; i < 7; i++) { + sum += (remote_state[i + offset] >> 4); + } + // Trim it down to fit into the 4 bits allowed. i.e. Mod 16. + sum &= 0xFU; + // Place it into the IR code in the top half of the 8th & 16th byte. + remote_state[7 + offset] = (sum << 4) | (remote_state[7 + offset] & 0xFU); + } +} + +void IRKelvinatorAC::on() { + //state = ON; + remote_state[0] |= KELVINATOR_POWER; + remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. +} + +void 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) { + if (state) + on(); + else + off(); +} + +bool IRKelvinatorAC::getPower() { + return ((remote_state[0] & KELVINATOR_POWER) != 0); +} + +// Set the temp. in deg C +void 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); + remote_state[9] = remote_state[1]; // Duplicate to the 2nd command chunk. +} + +// Return the set temp. in deg C +uint8_t 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) { + fan = min(KELVINATOR_FAN_MAX, fan); // Bounds check + + // Only change things if we need to. + if (fan != getFan()) { + // Set the basic fan values. + uint8_t fan_basic = min(KELVINATOR_BASIC_FAN_MAX, fan); + remote_state[0] = (remote_state[0] & KELVINATOR_BASIC_FAN_MASK) | + (fan_basic << KELVINATOR_FAN_OFFSET); + remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. + // Set the advanced(?) fan value. + remote_state[14] = (remote_state[14] & KELVINATOR_FAN_MASK) | + (fan << KELVINATOR_FAN_OFFSET); + setTurbo(false); // Turbo mode is turned off if we change the fan settings. + } +} + +uint8_t IRKelvinatorAC::getFan() { + return ((remote_state[14] & ~KELVINATOR_FAN_MASK) >> KELVINATOR_FAN_OFFSET); +} + +uint8_t IRKelvinatorAC::getMode() { + /* + KELVINATOR_AUTO + KELVINATOR_COOL + KELVINATOR_DRY + KELVINATOR_FAN + KELVINATOR_HEAT + */ + return (remote_state[0] & ~KELVINATOR_MODE_MASK); +} + +void 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; + remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. + if (mode == KELVINATOR_AUTO) + // When the remote is set to Auto, it defaults to 25C and doesn't show it. + setTemp(KELVINATOR_AUTO_TEMP); +} + +void IRKelvinatorAC::setSwingVertical(bool state) { + if (state) { + remote_state[0] |= KELVINATOR_VENT_SWING; + remote_state[4] |= KELVINATOR_VENT_SWING_V; + } + else { + remote_state[4] &= ~KELVINATOR_VENT_SWING_V; + if (! getSwingHorizontal()) + remote_state[0] &= ~KELVINATOR_VENT_SWING; + } + remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. +} + +bool IRKelvinatorAC::getSwingVertical() { + return ((remote_state[4] & KELVINATOR_VENT_SWING_V) != 0); +} + +void IRKelvinatorAC::setSwingHorizontal(bool state) { + if (state) { + remote_state[0] |= KELVINATOR_VENT_SWING; + remote_state[4] |= KELVINATOR_VENT_SWING_H; + } + else { + remote_state[4] &= ~KELVINATOR_VENT_SWING_H; + if (! getSwingVertical()) + remote_state[0] &= ~KELVINATOR_VENT_SWING; + } + remote_state[8] = remote_state[0]; // Duplicate to the 2nd command chunk. +} + +bool IRKelvinatorAC::getSwingHorizontal() { + return ((remote_state[4] & KELVINATOR_VENT_SWING_H) != 0); +} + +void IRKelvinatorAC::setQuiet(bool state) { + remote_state[12] &= ~KELVINATOR_QUIET; + remote_state[12] |= (state << KELVINATOR_QUIET_OFFSET); +} + +bool IRKelvinatorAC::getQuiet() { + return ((remote_state[12] & KELVINATOR_QUIET) != 0); +} + +void 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() { + return ((remote_state[2] & KELVINATOR_ION_FILTER) != 0); +} + +void 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() { + return ((remote_state[2] & KELVINATOR_LIGHT) != 0); +} + +// Note: XFan mode is only valid in Cool or Dry mode. +void 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() { + return ((remote_state[2] & KELVINATOR_XFAN) != 0); +} + +// Note: Turbo mode is turned off if the fan speed is changed. +void 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() { + return ((remote_state[2] & KELVINATOR_TURBO) != 0); +} diff --git a/lib/IRremoteESP8266/IRKelvinator.h b/lib/IRremoteESP8266/IRKelvinator.h new file mode 100644 index 000000000..d9345a6c2 --- /dev/null +++ b/lib/IRremoteESP8266/IRKelvinator.h @@ -0,0 +1,160 @@ + +#include +#include + +#define KELVINATOR_AUTO 0U +#define KELVINATOR_COOL 1U +#define KELVINATOR_DRY 2U +#define KELVINATOR_FAN 3U +#define KELVINATOR_HEAT 4U +#define KELVINATOR_MODE_MASK 0xF8U +#define KELVINATOR_POWER 8U +#define KELVINATOR_FAN_OFFSET 4U +#define KELVINATOR_BASIC_FAN_MAX 3U +#define KELVINATOR_BASIC_FAN_MASK uint8_t(0xFFU ^ (3U << KELVINATOR_FAN_OFFSET)) +#define KELVINATOR_FAN_MASK uint8_t(0xFFU ^ (7U << KELVINATOR_FAN_OFFSET)) +#define KELVINATOR_FAN_MAX 5U +#define KELVINATOR_VENT_SWING_OFFSET 6U +#define KELVINATOR_VENT_SWING uint8_t(1U << KELVINATOR_VENT_SWING_OFFSET) +#define KELVINATOR_VENT_SWING_V uint8_t(1U) +#define KELVINATOR_VENT_SWING_H uint8_t(1U << 4) +#define KELVINATOR_SLEEP_1_AND_3 uint8_t(1U << 7) +#define KELVINATOR_MIN_TEMP 16U // 16C +#define KELVINATOR_MAX_TEMP 30U // 30C +#define KELVINATOR_AUTO_TEMP 25U // 25C +#define KELVINATOR_CHECKSUM_START 10U +#define KELVINATOR_QUIET_OFFSET 7U +#define KELVINATOR_QUIET uint8_t(1U << KELVINATOR_QUIET_OFFSET) +#define KELVINATOR_ION_FILTER_OFFSET 6U +#define KELVINATOR_ION_FILTER uint8_t(1U << KELVINATOR_ION_FILTER_OFFSET) +#define KELVINATOR_LIGHT_OFFSET 5U +#define KELVINATOR_LIGHT uint8_t(1U << KELVINATOR_LIGHT_OFFSET) +#define KELVINATOR_XFAN_OFFSET 7U +#define KELVINATOR_XFAN uint8_t(1U << KELVINATOR_XFAN_OFFSET) +#define KELVINATOR_TURBO_OFFSET 4U +#define KELVINATOR_TURBO uint8_t(1U << KELVINATOR_TURBO_OFFSET) + + +/* + Kelvinator AC map + + (header mark and space) + byte 0 = Basic Modes + b2-0 = Modes + Modes: + 000 = Auto (temp = 25C) + 001 = Cool + 010 = Dry (temp = 25C, but not shown) + 011 = Fan + 100 = Heat + b3 = Power Status (1 = On, 0 = Off) + b5-4 = Fan (Basic modes) + Fan: + 00 = Auto + 01 = Fan 1 + 10 = Fan 2 + 11 = Fan 3 or higher (See byte 14) + b6 = Vent swing (1 = On, 0 = Off) (See byte 4) + b7 = Sleep Modes 1 & 3 (1 = On, 0 = Off) + byte 1 = Temperature + b3-0: Degrees C. + 0000 (0) = 16C + 0001 (1) = 17C + 0010 (2) = 18C + ... + 1101 (13) = 29C + 1110 (14) = 30C + byte 2 = Extras + b3-0 = UNKNOWN, typically 0. + b4 = Turbo Fan (1 = On, 0 = Off) + b5 = Light (Display) (1 = On, 0 = Off) + b6 = Ion Filter (1 = On, 0 = Off) + b7 = X-Fan (Fan runs for a while after power off) (1 = On, 0 = Off) + byte 3 = Section Indicator + b3-0 = Unused (Typically 0) + b5-4 = Unknown (possibly timer related) (Typically B01) + b7-6 = End of command block (B01) + (B010 marker and a gap of 20ms) + byte 4 = Extended options + b0 = Swing Vent Vertical (1 = On, 0 = Off) + b4 = Swing Vent Horizontal (1 = On, 0 = Off) + byte 5-6 = Timer related. Typically 0 except when timer in use. + byte 7 = checksum + b3-0 = Unknown (Used in Timer mode) + b7-4 = checksum of the previous bytes (0-6) + (gap of 40ms) + (header mark and space) + byte 8 = Repeat of byte 0 + byte 9 = Repeat of byte 1 + byte 10 = Repeat of byte 2 + byte 11 = Section Indicator + b3-0 = Unused (Typically 0) + b5-4 = Unknown (possibly timer related) (Typically B11) + b7-6 = End of command block (B01) + (B010 marker and a gap of 20ms) + byte 12 = Extended options + b0 = Sleep mode 2 (1 = On, 0=Off) + b6-1 = Unknown (Used in Sleep Mode 3, Typically B000000) + b7 = Quiet Mode (1 = On, 0=Off) + byte 13 = Unknown (Sleep Mode 3 related, Typically 0x00) + byte 14 = Fan control + b3-0 = Unknown (Sleep Mode 3 related, Typically B0000) + b6-4 = Fan speed + B000 (0) = Automatic + B001 (1) = Fan 1 + B010 (2) = Fan 2 + B011 (3) = Fan 3 + B100 (4) = Fan 4 + B101 (5) = Fan 5 + byte 15 = checksum + b3-0 = Unknown (Typically B0000) + b7-4 = checksum of the previous bytes (8-14) +*/ + +#define KELVINATOR_STATE_LENGTH 16 + +class IRKelvinatorAC +{ + public: + IRKelvinatorAC(int pin); + //: IRsend(pin){}; + + void stateReset(); + void send(); + + void begin(); + void on(); + void off(); + void setPower(bool state); + bool getPower(); + void setTemp(uint8_t temp); + uint8_t getTemp(); + void setFan(uint8_t fan); + uint8_t getFan(); + void setMode(uint8_t mode); + uint8_t getMode(); + void setSwingVertical(bool state); + bool getSwingVertical(); + void setSwingHorizontal(bool state); + bool getSwingHorizontal(); + void setQuiet(bool state); + bool getQuiet(); + void setIonFilter(bool state); + bool getIonFilter(); + void setLight(bool state); + bool getLight(); + void setXFan(bool state); + bool getXFan(); + void setTurbo(bool state); + bool getTurbo(); + uint8_t* getRaw(); + + + private: + // The state of the IR remote in IR code form. + uint8_t remote_state[KELVINATOR_STATE_LENGTH]; + + void checksum(); + void fixup(); + IRsend _irsend; +}; diff --git a/lib/IRremoteESP8266/IRMitsubishiAC.cpp b/lib/IRremoteESP8266/IRMitsubishiAC.cpp new file mode 100644 index 000000000..32c13e1d3 --- /dev/null +++ b/lib/IRremoteESP8266/IRMitsubishiAC.cpp @@ -0,0 +1,148 @@ +/* +Code to emulate Mitsubishi A/C IR remote control unit. +Inspired and derived from the work done at: + https://github.com/r45635/HVAC-IR-Control + +Warning: Consider this very alpha code. Seems to work, but not validated. + +Equipment it seems compatible with: + * +*/ + +#include + +// Initialise the object. +IRMitsubishiAC::IRMitsubishiAC(int pin) : _irsend(pin) { + stateReset(); +} + +// Reset the state of the remote to a known good state/sequence. +void 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() { + _irsend.begin(); +} + +// Send the current desired state to the IR LED. +void 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() { + checksum(); + return remote_state; +} + +// Calculate the checksum for the current internal state of the remote. +void IRMitsubishiAC::checksum() { + uint8_t sum = 0; + // Checksum is simple addition of all previous bytes stored + // as a 8 bit value. + for (uint8_t i = 0; i < 17; i++) + sum += remote_state[i]; + remote_state[17] = sum & 0xFFU; +} + +// Set the requested power state of the A/C to off. +void IRMitsubishiAC::on() { + //state = ON; + remote_state[5] |= MITSUBISHI_AC_POWER; +} + +// Set the requested power state of the A/C to off. +void IRMitsubishiAC::off() { + //state = OFF; + remote_state[5] &= ~MITSUBISHI_AC_POWER; +} + +// Set the requested power state of the A/C. +void IRMitsubishiAC::setPower(bool state) { + if (state) + on(); + else + off(); +} + +// Return the requested power state of the A/C. +bool IRMitsubishiAC::getPower() { + return((remote_state[5] & MITSUBISHI_AC_POWER) != 0); +} + +// Set the temp. in deg C +void 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() { + 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) { + // Bounds check + if (fan > MITSUBISHI_AC_FAN_SILENT) + fan = MITSUBISHI_AC_FAN_MAX; // Set the fan to maximum if out of range. + if (fan == MITSUBISHI_AC_FAN_AUTO) { // Automatic is a special case. + remote_state[9] = B10000000 | (remote_state[9] & B01111000); + return; + } else if (fan >= MITSUBISHI_AC_FAN_MAX) { + fan--; // There is no spoon^H^H^Heed 5 (max), pretend it doesn't exist. + } + remote_state[9] |= fan; +} + +// Return the requested state of the unit's fan. +uint8_t IRMitsubishiAC::getFan() { + uint8_t fan = remote_state[9] & B111; + if (fan == MITSUBISHI_AC_FAN_MAX) + return MITSUBISHI_AC_FAN_SILENT; + return fan; +} + +// Return the requested climate operation mode of the a/c unit. +uint8_t IRMitsubishiAC::getMode() { + /* + MITSUBISHI_AC_AUTO + MITSUBISHI_AC_COOL + MITSUBISHI_AC_DRY + MITSUBISHI_AC_HEAT + */ + return(remote_state[6]); +} + +// Set the requested climate operation mode of the a/c unit. +void IRMitsubishiAC::setMode(uint8_t mode) { + // If we get an unexpected mode, default to AUTO. + switch (mode) { + case MITSUBISHI_AC_AUTO: break; + case MITSUBISHI_AC_COOL: break; + case MITSUBISHI_AC_DRY: break; + case MITSUBISHI_AC_HEAT: break; + default: mode = MITSUBISHI_AC_AUTO; + } + remote_state[6] = mode; +} + +// Set the requested vane operation mode of the a/c unit. +void IRMitsubishiAC::setVane(uint8_t mode) { + mode = max(mode, B111); // bounds check + mode |= B1000; + mode <<= 3; + remote_state[9] |= mode; +} + +// Return the requested vane operation mode of the a/c unit. +uint8_t IRMitsubishiAC::getVane() { + return ((remote_state[9] & B00111000) >> 3); +} diff --git a/lib/IRremoteESP8266/IRMitsubishiAC.h b/lib/IRremoteESP8266/IRMitsubishiAC.h new file mode 100644 index 000000000..339d79955 --- /dev/null +++ b/lib/IRremoteESP8266/IRMitsubishiAC.h @@ -0,0 +1,52 @@ + +#include +#include + +#define MITSUBISHI_AC_AUTO 0x20U +#define MITSUBISHI_AC_COOL 0x18U +#define MITSUBISHI_AC_DRY 0x10U +#define MITSUBISHI_AC_HEAT 0x08U +#define MITSUBISHI_AC_POWER 0x20U +#define MITSUBISHI_AC_FAN_AUTO 0U +#define MITSUBISHI_AC_FAN_MAX 5U +#define MITSUBISHI_AC_FAN_SILENT 6U +#define MITSUBISHI_AC_MIN_TEMP 16U // 16C +#define MITSUBISHI_AC_MAX_TEMP 31U // 31C +#define MITSUBISHI_AC_VANE_AUTO 0U +#define MITSUBISHI_AC_VANE_AUTO_MOVE 7U +#define MITSUBISHI_AC_STATE_LENGTH 18 + +class IRMitsubishiAC +{ + public: + IRMitsubishiAC(int pin); + + void stateReset(); + void send(); + + void begin(); + void on(); + void off(); + void setPower(bool state); + bool getPower(); + void setTemp(uint8_t temp); + uint8_t getTemp(); + void setFan(uint8_t fan); + uint8_t getFan(); + void setMode(uint8_t mode); + uint8_t getMode(); + void setVane(uint8_t mode); + uint8_t getVane(); + uint8_t* getRaw(); + + + private: + // The state of the IR remote in IR code form. + // Known good state obtained from: + // https://github.com/r45635/HVAC-IR-Control/blob/master/HVAC_ESP8266/HVAC_ESP8266.ino#L108 + uint8_t known_good_state[MITSUBISHI_AC_STATE_LENGTH] = { 0x23, 0xCB, 0x26, 0x01, 0x00, 0x20, 0x08, 0x06, 0x30, 0x45, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F }; + uint8_t remote_state[MITSUBISHI_AC_STATE_LENGTH]; + + void checksum(); + IRsend _irsend; +}; diff --git a/lib/IRremoteESP8266/IRremoteESP8266.cpp b/lib/IRremoteESP8266/IRremoteESP8266.cpp new file mode 100644 index 000000000..493e8d49e --- /dev/null +++ b/lib/IRremoteESP8266/IRremoteESP8266.cpp @@ -0,0 +1,1647 @@ + /*************************************************** + * IRremote for ESP8266 + * + * Based on the IRremote library for Arduino by Ken Shirriff + * Version 0.11 August, 2009 + * Copyright 2009 Ken Shirriff + * For details, see + * http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html + * + * Modified by Paul Stoffregen to support other boards and + * timers + * Modified by Mitra Ardron + * Added Sanyo and Mitsubishi controllers + * Modified Sony to spot the repeat codes that some Sony's send + * + * Interrupt code based on NECIRrcv by Joe Knapp + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 + * Also influenced by + * http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ + * + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and + * other people at the original blog post) + * LG added by Darryl Smith (based on the JVC protocol) + * Whynter A/C ARC-110WD added by Francesco Meschia + * Global Cache IR format sender added by Hisham Khalifa + * (http://www.hishamkhalifa.com) + * Coolix A/C / heatpump added by bakrus + * Denon: sendDenon, decodeDenon added by Massimiliano Pinto + * (from https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp) + * Kelvinator A/C and Sherwood added by crankyoldgit + * Mitsubishi A/C added by crankyoldgit + * (derived from https://github.com/r45635/HVAC-IR-Control) + * + * Updated by markszabo (https://github.com/markszabo/IRremoteESP8266) for + * sending IR code on ESP8266 + * Updated by Sebastien Warin (http://sebastien.warin.fr) for receiving IR code + * on ESP8266 + * + * GPL license, all text above must be included in any redistribution + ****************************************************/ + +#include "IRremoteESP8266.h" +#include "IRremoteInt.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). + +IRtimer::IRtimer() { + reset(); +} + +void IRtimer::reset() { + start = micros(); +} + +uint32_t IRtimer::elapsed() { + uint32_t now = micros(); + if (start <= now) // Check if the system timer has wrapped. + return (now - start); // No wrap. + else + return (0xFFFFFFFF - start + now); // Has wrapped. +} + +// IRsend ---------------------------------------------------------------------- + +IRsend::IRsend(int IRsendPin) { + IRpin = IRsendPin; +} + +void IRsend::begin() { + pinMode(IRpin, OUTPUT); +} +// 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) { + if (MSBfirst) // Send the MSB first. + for (uint32_t mask = 1UL << (nbits - 1); mask; mask >>= 1) + if (data & mask) { // 1 + mark(onemark); + space(onespace); + } else { // 0 + mark(zeromark); + space(zerospace); + } + else { // Send the Least Significant Bit (LSB) first / MSB last. + for (uint8_t bit = 0; bit < nbits; bit++, data >>= 1) + if (data & 1) { // 1 + mark(onemark); + space(onespace); + } else { // 0 + mark(zeromark); + space(zerospace); + } + } +} + +void IRsend::sendCOOLIX(unsigned long data, int nbits) { + // Set IR carrier frequency + enableIROut(38); + // Header + mark(COOLIX_HDR_MARK); + space(COOLIX_HDR_SPACE); + // Data + // Sending 3 bytes of data. Each byte first being sent straight, then followed + // by an inverted version. + unsigned long COOLIXmask; + bool invert = 0; // Initializing + for (int j = 0; j < COOLIX_NBYTES * 2; j++) { + for (int i = nbits; i > nbits-8; i--) { + // Type cast necessary to perform correct for the one byte above 16bit + COOLIXmask = (unsigned long) 1 << (i-1); + if (data & COOLIXmask) { // 1 + mark(COOLIX_BIT_MARK); + space(COOLIX_ONE_SPACE); + } else { // 0 + mark(COOLIX_BIT_MARK); + space(COOLIX_ZERO_SPACE); + } + } + // Inverts all of the data each time we need to send an inverted byte + data ^= 0xFFFFFFFF; + invert = !invert; + // Subtract 8 from nbits each time we switch to a new byte. + nbits -= invert ? 0 : 8; + } + // Footer + mark(COOLIX_BIT_MARK); + space(COOLIX_ZERO_SPACE); // Stop bit (0) + space(COOLIX_HDR_SPACE); // Pause before repeating +} + +void 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 + + // Set IR carrier frequency + enableIROut(38); + IRtimer usecs = IRtimer(); + // Header + mark(NEC_HDR_MARK); + space(NEC_HDR_SPACE); + // Data + sendData(NEC_BIT_MARK, NEC_ONE_SPACE, NEC_BIT_MARK, NEC_ZERO_SPACE, + data, nbits, true); + // Footer + mark(NEC_BIT_MARK); + // Gap to next command. + space(NEC_MIN_COMMAND_LENGTH - usecs.elapsed()); + + // Optional command repeat sequence. + for (unsigned int i = 0; i < repeat; i++) { + usecs.reset(); + mark(NEC_HDR_MARK); + space(NEC_RPT_SPACE); + mark(NEC_BIT_MARK); + // Gap till next command. + space(NEC_MIN_COMMAND_LENGTH - usecs.elapsed()); + } +} + +void IRsend::sendLG (unsigned long data, int nbits) { + // 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); + } + } + // Footer + ledOff(); +} + +void IRsend::sendWhynter(unsigned long data, int nbits) { + // Set IR carrier frequency + enableIROut(38); + // Header + mark(WHYNTER_ZERO_MARK); + space(WHYNTER_ZERO_SPACE); + 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); + } + } + // Footer + mark(WHYNTER_ZERO_MARK); + space(WHYNTER_ZERO_SPACE); +} + +void IRsend::sendSony(unsigned long data, int nbits, unsigned int repeat) { + // Send an IR command to a compatible Sony device. + // + // Args: + // data: IR command to be sent. + // nbits: Nr. of bits of the IR command to be sent. + // repeat: Nr. of additional times the IR command is to be sent. + // + // sendSony() should typically be called with repeat=2 as Sony devices + // expect the code to be sent at least 3 times. + // + // Timings and details are taken from: + // http://www.sbprojects.com/knowledge/ir/sirc.php + + enableIROut(40); // Sony devices use a 40kHz IR carrier frequency. + IRtimer usecs = IRtimer(); + + for (uint16_t i = 0; i <= repeat; i++) { // Typically loop 3 or more times. + usecs.reset(); + // Header + mark(SONY_HDR_MARK); + space(SONY_HDR_SPACE); + // Data + sendData(SONY_ONE_MARK, SONY_HDR_SPACE, SONY_ZERO_MARK, SONY_HDR_SPACE, + data, nbits, true); + // Footer + // The Sony protocol requires us to wait 45ms from start of a code to the + // start of the next one. A 10ms minimum gap is also required. + space(max(10000, 45000 - usecs.elapsed())); + } + // A space() is always performed last, so no need to turn off the LED. +} + +void IRsend::sendRaw(unsigned int buf[], int len, int hz) { + // Set IR carrier frequency + enableIROut(hz); + for (int i = 0; i < len; i++) { + if (i & 1) { // Odd bit. + space(buf[i]); + } else { // Even bit. + mark(buf[i]); + } + } + ledOff(); +} + +// 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) { + int khz = buf[0]/1000; // GC data starts with frequency in Hz. + enableIROut(khz); + int periodic_time = 1000/khz; + int count = buf[1]; // Max 50 as per GC. + // Data + for (int i = 0; i < count; i++) { + // Account for offset if we're repeating, otherwise start at index 3. + int j = i > 0 ? buf[2] + 2 : 3; + for (; j < len; j++) { + // Convert periodic units to microseconds. Minimum is 80 for actual GC + // units. + int microseconds = buf[j] * periodic_time; + if (j & 1) { // Odd bit. + // Our codes start at an odd index (not even as with sendRaw). + mark(microseconds); + } else { // Even bit. + space(microseconds); + } + } + } + // Footer + ledOff(); +} + +// Note: first bit must be a one (start bit) +void IRsend::sendRC5(unsigned long data, int nbits) { + // Set IR carrier frequency + enableIROut(36); + // Header + mark(RC5_T1); // First start bit + space(RC5_T1); // Second start bit + mark(RC5_T1); // Second start bit + // Data + for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { + if (data & mask) { // 1 + space(RC5_T1); // 1 is space, then mark + mark(RC5_T1); + } else { // 0 + mark(RC5_T1); + space(RC5_T1); + } + } + // Footer + ledOff(); +} + +// Caller needs to take care of flipping the toggle bit +void IRsend::sendRC6(unsigned long data, int nbits) { + // Set IR carrier frequency + enableIROut(36); + // Header + mark(RC6_HDR_MARK); + space(RC6_HDR_SPACE); + mark(RC6_T1); // Start bit + space(RC6_T1); + int t; + // Data + for (unsigned long i = 0, mask = 1UL << (nbits - 1); mask; i++, mask >>= 1) { + // The fourth bit we send is a "double width trailer bit". + if (i == 3) { + // double-wide trailer bit + t = 2 * RC6_T1; + } else { + t = RC6_T1; + } + if (data & mask) { // 1 + mark(t); + space(t); + } else { // 0 + space(t); + mark(t); + } + } + // Footer + ledOff(); +} + +void IRsend::sendPanasonic(unsigned int address, unsigned long data) { + // Set IR carrier frequency + enableIROut(35); + // Header + mark(PANASONIC_HDR_MARK); + space(PANASONIC_HDR_SPACE); + // Address (16 bits) + sendData(PANASONIC_BIT_MARK, PANASONIC_ONE_SPACE, + PANASONIC_BIT_MARK, PANASONIC_ZERO_SPACE, + address, 16, true); + // Data (32 bits) + sendData(PANASONIC_BIT_MARK, PANASONIC_ONE_SPACE, + PANASONIC_BIT_MARK, PANASONIC_ZERO_SPACE, + data, 32, true); + // Footer + mark(PANASONIC_BIT_MARK); + ledOff(); +} + +void IRsend::sendJVC(unsigned long data, int nbits, int repeat) { + // Set IR carrier frequency + enableIROut(38); + // 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); + } + } + // Footer + mark(JVC_BIT_MARK); + ledOff(); +} + +void 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); + } + } + // 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) { + // 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); + } + } + // Footer + mark(DENON_BIT_MARK); + ledOff(); +} + +void 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(); + while (usecTimer.elapsed() < usec) { + digitalWrite(IRpin, HIGH); + delayMicroseconds(halfPeriodicTime); + digitalWrite(IRpin, LOW); + // e.g. 38 kHz -> T = 26.31 microsec (periodic time), half of it is 13 + delayMicroseconds(halfPeriodicTime); + } +} + +void IRsend::ledOff() { + digitalWrite(IRpin, LOW); +} + +/* Leave pin off for time (given in microseconds) */ +void 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(); + if (time == 0) return; + if (time <= 16383) // delayMicroseconds is only accurate to 16383us. + delayMicroseconds(time); + else { + // Invoke a delay(), where possible, to avoid triggering the WDT. + delay(time / 1000UL); // Delay for as many whole ms as we can. + delayMicroseconds((int) time % 1000UL); // Delay the remaining sub-msecond. + } +} + +void IRsend::enableIROut(int khz) { + // Enables IR output. + // The khz value controls the modulation frequency in kilohertz. + + // T = 1/f but we need T/2 in microsecond and f is in kHz + halfPeriodicTime = 500/khz; +} + + +/* Sharp and DISH support by Todd Treece +( http://unionbridge.org/design/ircommand ) + +The Dish send function needs to be repeated 4 times, and the Sharp function +has the necessary repeat built in because of the need to invert the signal. + +Sharp protocol documentation: +http://www.sbprojects.com/knowledge/ir/sharp.htm + +Here are the LIRC files that I found that seem to match the remote codes +from the oscilloscope: + +Sharp LCD TV: +http://lirc.sourceforge.net/remotes/sharp/GA538WJSA + +DISH NETWORK (echostar 301): +http://lirc.sourceforge.net/remotes/echostar/301_501_3100_5100_58xx_59xx + +For the DISH codes, only send the last for characters of the hex. +i.e. use 0x1C10 instead of 0x0000000000001C10 which is listed in the +linked LIRC file. +*/ + +void 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); + } + } + // Footer + mark(SHARP_BIT_MARK); + space(SHARP_ZERO_SPACE); + delay(40); + + data = data ^ SHARP_TOGGLE_MASK; + } +} + +// Sharp send compatible with data obtained through decodeSharp +void IRsend::sendSharp(unsigned int address, unsigned int command) { + sendSharpRaw((address << 10) | (command << 2) | 2, 15); +} + +void IRsend::sendDISH(unsigned long data, int nbits) { + // 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; + } + // 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 IRsend::sendDaikinChunk(unsigned char buf[], int len, int start) { + int data2; + // Set IR carrier frequency + enableIROut(38); + // Header + 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 + mark(DAIKIN_ONE_MARK); + space(DAIKIN_ZERO_SPACE); +} + +void IRsend::sendKelvinator(unsigned char data[]) { + uint8_t i = 0; + // Set IR carrier frequency + enableIROut(38); + // Header #1 + mark(KELVINATOR_HDR_MARK); + space(KELVINATOR_HDR_SPACE); + // Data (command) + // Send the first command data (4 bytes) + for (; i < 4; i++) + sendData(KELVINATOR_BIT_MARK, KELVINATOR_ONE_SPACE, KELVINATOR_BIT_MARK, + KELVINATOR_ZERO_SPACE, data[i], 8, false); + // Send Footer for the command data (3 bits (B010)) + sendData(KELVINATOR_BIT_MARK, KELVINATOR_ONE_SPACE, KELVINATOR_BIT_MARK, + KELVINATOR_ZERO_SPACE, KELVINATOR_CMD_FOOTER, 3, false); + // Send an interdata gap. + mark(KELVINATOR_BIT_MARK); + space(KELVINATOR_GAP_SPACE); + // Data (options) + // Send the 1st option chunk of data (4 bytes). + for (; i < 8; i++) + sendData(KELVINATOR_BIT_MARK, KELVINATOR_ONE_SPACE, KELVINATOR_BIT_MARK, + KELVINATOR_ZERO_SPACE, data[i], 8, false); + // Send a double data gap to signify we are starting a new command sequence. + mark(KELVINATOR_BIT_MARK); + space(KELVINATOR_GAP_SPACE * 2); + // Header #2 + mark(KELVINATOR_HDR_MARK); + space(KELVINATOR_HDR_SPACE); + // Data (command) + // Send the 2nd command data (4 bytes). + // Basically an almost identical repeat of the earlier command data. + for (; i < 12; i++) + sendData(KELVINATOR_BIT_MARK, KELVINATOR_ONE_SPACE, KELVINATOR_BIT_MARK, + KELVINATOR_ZERO_SPACE, data[i], 8, false); + // Send Footer for the command data (3 bits (B010)) + sendData(KELVINATOR_BIT_MARK, KELVINATOR_ONE_SPACE, KELVINATOR_BIT_MARK, + KELVINATOR_ZERO_SPACE, KELVINATOR_CMD_FOOTER, 3, false); + // Send an interdata gap. + mark(KELVINATOR_BIT_MARK); + space(KELVINATOR_GAP_SPACE); + // Data (options) + // Send the 2nd option chunk of data (4 bytes). + // Unlike the commands, definately not a repeat of the earlier option data. + for (; i < KELVINATOR_STATE_LENGTH; i++) + sendData(KELVINATOR_BIT_MARK, KELVINATOR_ONE_SPACE, KELVINATOR_BIT_MARK, + KELVINATOR_ZERO_SPACE, data[i], 8, false); + // Footer + mark(KELVINATOR_BIT_MARK); + ledOff(); +} + +void 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[]) { + // Set IR carrier frequency + enableIROut(38); + // Mitsubishi AC remote sends the packet twice. + for (uint8_t count = 0; count < 2; count++) { + // Header + mark(MITSUBISHI_AC_HDR_MARK); + space(MITSUBISHI_AC_HDR_SPACE); + // Data + for (uint8_t i = 0; i < MITSUBISHI_AC_STATE_LENGTH; i++) + sendMitsubishiACChunk(data[i]); + // Footer + mark(MITSUBISHI_AC_RPT_MARK); + space(MITSUBISHI_AC_RPT_SPACE); + } +} +// --------------------------------------------------------------- + + +//IRRecv------------------------------------------------------ + +extern "C" { + #include "user_interface.h" + #include "gpio.h" +} + +static ETSTimer timer; +volatile irparams_t irparams; + +static void ICACHE_RAM_ATTR read_timeout(void *arg __attribute__((unused))) { + os_intr_lock(); + if (irparams.rawlen) { + irparams.rcvstate = STATE_STOP; + } + os_intr_unlock(); +} + +static void ICACHE_RAM_ATTR gpio_intr() { + uint32_t now = system_get_time(); + uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); + static uint32_t start = 0; + + os_timer_disarm(&timer); + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status); + + if (irparams.rawlen >= RAWBUF) { + irparams.overflow = true; + 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; + } else { + if (now < start) + irparams.rawbuf[irparams.rawlen++] = (0xFFFFFFFF - start + now) / USECPERTICK + 1; + else + irparams.rawbuf[irparams.rawlen++] = (now - start) / USECPERTICK + 1; + } + + start = now; + #define ONCE 0 + os_timer_arm(&timer, 15, ONCE); +} + +IRrecv::IRrecv(int recvpin) { + irparams.recvpin = recvpin; +} + +// initialization +void IRrecv::enableIRIn() { + // initialize state machine variables + irparams.rcvstate = STATE_IDLE; + irparams.rawlen = 0; + + // Initialize timer + os_timer_disarm(&timer); + os_timer_setfn(&timer, (os_timer_func_t *)read_timeout, NULL); + + // Attach Interrupt + attachInterrupt(irparams.recvpin, gpio_intr, CHANGE); +} + +void IRrecv::disableIRIn() { + os_timer_disarm(&timer); + detachInterrupt(irparams.recvpin); +} + +void IRrecv::resume() { + irparams.rcvstate = STATE_IDLE; + irparams.rawlen = 0; +} + +// 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; + + if (irparams.rcvstate != STATE_STOP) { + return false; + } + +#ifdef DEBUG + Serial.println("Attempting NEC decode"); +#endif + if (decodeNEC(results)) { + return true; + } + +#ifdef DEBUG + Serial.println("Attempting Sony decode"); +#endif + if (decodeSony(results)) { + return true; + } + /* +#ifdef DEBUG + Serial.println("Attempting Sanyo decode"); +#endif + if (decodeSanyo(results)) { + return true; + }*/ +#ifdef DEBUG + Serial.println("Attempting Mitsubishi decode"); +#endif + if (decodeMitsubishi(results)) { + return true; + } +#ifdef DEBUG + Serial.println("Attempting RC5 decode"); +#endif + if (decodeRC5(results)) { + return true; + } +#ifdef DEBUG + Serial.println("Attempting RC6 decode"); +#endif + if (decodeRC6(results)) { + return true; + } +#ifdef DEBUG + Serial.println("Attempting Panasonic decode"); +#endif + if (decodePanasonic(results)) { + return true; + } +#ifdef DEBUG + Serial.println("Attempting LG decode"); +#endif + if (decodeLG(results)) { + return true; + } +#ifdef DEBUG + Serial.println("Attempting JVC decode"); +#endif + if (decodeJVC(results)) { + return true; + } +#ifdef DEBUG + Serial.println("Attempting SAMSUNG decode"); +#endif + if (decodeSAMSUNG(results)) { + return true; + } +#ifdef DEBUG + Serial.println("Attempting Whynter decode"); +#endif + if (decodeWhynter(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. + if (decodeHash(results)) { + return true; + } + // Throw away and start over + resume(); + return false; +} + +// NECs have a repeat only 4 items long +bool 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)) { + 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)) { + results->bits = 0; + results->value = REPEAT; + results->decode_type = NEC; + return true; + } + if (irparams.rawlen < 2 * NEC_BITS + 4) { + return false; + } + // Initial space + if (!MATCH_SPACE(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)) { + return false; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + // Success + results->bits = NEC_BITS; + results->value = data; + results->decode_type = NEC; + return true; +} + +bool IRrecv::decodeSony(decode_results *results) { + long data = 0; + if (irparams.rawlen < 2 * SONY_BITS + 2) { + return false; + } + int offset = 0; // Dont skip first space, check its size + + /* + // Some Sony's deliver repeats fast after first + // unfortunately can't spot difference from of repeat from two fast clicks + if (results->rawbuf[offset] < SONY_DOUBLE_SPACE_USECS) { + // Serial.print("IR Gap found: "); + results->bits = 0; + results->value = REPEAT; + results->decode_type = SANYO; + return true; + }*/ + offset++; + + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], SONY_HDR_MARK)) { + return false; + } + offset++; + + while (offset + 1 < irparams.rawlen) { + if (!MATCH_SPACE(results->rawbuf[offset], SONY_HDR_SPACE)) { + break; + } + offset++; + if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) { + data = (data << 1) | 1; + } else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) { + data <<= 1; + } else { + return false; + } + offset++; + } + + // Success + results->bits = (offset - 1) / 2; + if (results->bits < 12) { + results->bits = 0; + return false; + } + results->value = data; + results->decode_type = SONY; + return true; +} + +bool IRrecv::decodeWhynter(decode_results *results) { + long data = 0; + + if (irparams.rawlen < 2 * WHYNTER_BITS + 6) { + return false; + } + + int offset = 1; // Skip first space + + + // sequence begins with a bit mark and a zero space + if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) { + return false; + } + offset++; + if (!MATCH_SPACE(results->rawbuf[offset], WHYNTER_ZERO_SPACE)) { + return false; + } + offset++; + + // header mark and space + if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_HDR_MARK)) { + return false; + } + offset++; + if (!MATCH_SPACE(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)) { + return false; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset],WHYNTER_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + + // trailing mark + if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) { + return false; + } + // Success + results->bits = WHYNTER_BITS; + results->value = data; + results->decode_type = WHYNTER; + return true; +} + +// 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) { + long data = 0; + if (irparams.rawlen < 2 * SANYO_BITS + 2) { + return false; + } + int offset = 1; // Skip first space + + + // Initial space + /* Put this back in for debugging - note can't use #DEBUG as if Debug on we don't see the repeat cos of the delay + Serial.print("IR Gap: "); + Serial.println( results->rawbuf[offset]); + Serial.println( "test against:"); + Serial.println(results->rawbuf[offset]); + */ + + if (results->rawbuf[offset] < SANYO_DOUBLE_SPACE_USECS) { + // Serial.print("IR Gap found: "); + results->bits = 0; + results->value = REPEAT; + results->decode_type = SANYO; + return true; + } + offset++; + + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { + return false; + } + offset++; + + // Skip Second Mark + if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { + return false; + } + offset++; + + while (offset + 1 < irparams.rawlen) { + if (!MATCH_SPACE(results->rawbuf[offset], SANYO_HDR_SPACE)) { + break; + } + offset++; + if (MATCH_MARK(results->rawbuf[offset], SANYO_ONE_MARK)) { + data = (data << 1) | 1; + } else if (MATCH_MARK(results->rawbuf[offset], SANYO_ZERO_MARK)) { + data <<= 1; + } else { + return false; + } + offset++; + } + + // Success + results->bits = (offset - 1) / 2; + if (results->bits < 12) { + results->bits = 0; + return false; + } + results->value = data; + results->decode_type = SANYO; + return true; +} + +// 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); + // Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2); + long data = 0; + if (irparams.rawlen < 2 * MITSUBISHI_BITS + 2) { + return false; + } + int offset = 1; // Skip first space + // Initial space + /* Put this back in for debugging - note can't use #DEBUG as if Debug on we + don't see the repeat cos of the delay + Serial.print("IR Gap: "); + Serial.println( results->rawbuf[offset]); + Serial.println( "test against:"); + Serial.println(results->rawbuf[offset]); + */ + /* Not seeing double keys from Mitsubishi + if (results->rawbuf[offset] < MITSUBISHI_DOUBLE_SPACE_USECS) { + // Serial.print("IR Gap found: "); + results->bits = 0; + results->value = REPEAT; + results->decode_type = MITSUBISHI; + return true; + } + */ + + offset++; + + // Typical + // 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)) { + return false; + } + offset++; + while (offset + 1 < irparams.rawlen) { + if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ONE_MARK)) { + data = (data << 1) | 1; + } else if (MATCH_MARK(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)) { + // Serial.println("B"); Serial.println(offset); Serial.println(results->rawbuf[offset]); + break; + } + offset++; + } + + // Success + results->bits = (offset - 1) / 2; + if (results->bits < MITSUBISHI_BITS) { + results->bits = 0; + return false; + } + results->value = data; + results->decode_type = MITSUBISHI; + return true; +} + +// Gets one undecoded level at a time from the raw buffer. +// The RC5/6 decoding is easier if the data is broken into time intervals. +// E.g. if the buffer has MARK for 2 time intervals and SPACE for 1, +// successive calls to getRClevel will return MARK, MARK, SPACE. +// 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) { + if (*offset >= results->rawlen) { + // After end of recorded buffer, assume SPACE. + return SPACE; + } + int width = results->rawbuf[*offset]; + int val = ((*offset) % 2) ? MARK : SPACE; + int correction = (val == MARK) ? MARK_EXCESS : - MARK_EXCESS; + + int avail; + if (MATCH(width, t1 + correction)) { + avail = 1; + } else if (MATCH(width, 2*t1 + correction)) { + avail = 2; + } else if (MATCH(width, 3*t1 + correction)) { + avail = 3; + } else { + return -1; + } + + (*used)++; + if (*used >= avail) { + *used = 0; + (*offset)++; + } +#ifdef DEBUG + if (val == MARK) { + Serial.println("MARK"); + } else { + Serial.println("SPACE"); + } +#endif + return val; +} + +bool IRrecv::decodeRC5(decode_results *results) { + if (irparams.rawlen < MIN_RC5_SAMPLES + 2) { + return false; + } + int offset = 1; // Skip gap space + long data = 0; + int used = 0; + // Get start bits + if (getRClevel(results, &offset, &used, RC5_T1) != MARK) return false; + 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++) { + int levelA = getRClevel(results, &offset, &used, RC5_T1); + int levelB = getRClevel(results, &offset, &used, RC5_T1); + if (levelA == SPACE && levelB == MARK) { + // 1 bit + data = (data << 1) | 1; + } else if (levelA == MARK && levelB == SPACE) { + // zero bit + data <<= 1; + } else { + return false; + } + } + + // Success + results->bits = nbits; + results->value = data; + results->decode_type = RC5; + return true; +} + +bool 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)) { + return false; + } + offset++; + if (!MATCH_SPACE(results->rawbuf[offset], RC6_HDR_SPACE)) { + return false; + } + offset++; + long data = 0; + int used = 0; + // Get start bit (1) + if (getRClevel(results, &offset, &used, RC6_T1) != MARK) return false; + if (getRClevel(results, &offset, &used, RC6_T1) != SPACE) return false; + int nbits; + for (nbits = 0; offset < results->rawlen; nbits++) { + int levelA, levelB; // Next two levels + levelA = getRClevel(results, &offset, &used, RC6_T1); + if (nbits == 3) { + // T bit is double wide; make sure second half matches + if (levelA != getRClevel(results, &offset, &used, RC6_T1)) return false; + } + levelB = getRClevel(results, &offset, &used, RC6_T1); + if (nbits == 3) { + // T bit is double wide; make sure second half matches + if (levelB != getRClevel(results, &offset, &used, RC6_T1)) return false; + } + if (levelA == MARK && levelB == SPACE) { // reversed compared to RC5 + // 1 bit + data = (data << 1) | 1; + } else if (levelA == SPACE && levelB == MARK) { + // zero bit + data <<= 1; + } else { + return false; // Error + } + } + // Success + results->bits = nbits; + results->value = data; + results->decode_type = RC6; + return true; +} + +bool 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)) { + return false; + } + offset++; + if (!MATCH_MARK(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)) { + return false; + } + if (MATCH(results->rawbuf[offset],PANASONIC_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + results->value = (unsigned long)data; + results->panasonicAddress = (unsigned int)(data >> 32); + results->decode_type = PANASONIC; + results->bits = PANASONIC_BITS; + return true; +} + +bool 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)) { + return false; + } + offset++; + if (irparams.rawlen < 2 * LG_BITS + 1 ) { + return false; + } + // Initial space + if (!MATCH_SPACE(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)) { + return false; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + //Stop bit + if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)){ + return false; + } + // Success + results->bits = LG_BITS; + results->value = data; + results->decode_type = LG; + return true; +} + +bool 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)) { + results->bits = 0; + results->value = REPEAT; + results->decode_type = JVC; + return true; + } + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], JVC_HDR_MARK)) { + return false; + } + offset++; + if (irparams.rawlen < 2 * JVC_BITS + 1 ) { + return false; + } + // Initial space + if (!MATCH_SPACE(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)) { + return false; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], JVC_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset], JVC_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + //Stop bit + if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)) { + return false; + } + // Success + results->bits = JVC_BITS; + results->value = data; + results->decode_type = JVC; + return true; +} + +// SAMSUNGs have a repeat only 4 items long +bool 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)) { + 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)) { + results->bits = 0; + results->value = REPEAT; + results->decode_type = SAMSUNG; + return true; + } + if (irparams.rawlen < 2 * SAMSUNG_BITS + 2) { + return false; + } + // Initial space + if (!MATCH_SPACE(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)) { + return false; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + // Success + results->bits = SAMSUNG_BITS; + results->value = data; + results->decode_type = SAMSUNG; + return true; +} + +// 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) { + long data = 0; + int offset = 1; // Skip first space + + if (irparams.rawlen < 2 * DAIKIN_BITS + 4) { + //return false; + } + + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], DAIKIN_HDR_MARK)) { + return false; + } + offset++; + + if (!MATCH_SPACE(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)) { + return false; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + + unsigned long number = data ; // some number... + int bits = 32 ; // nr of bits in some number + unsigned long reversed = 0; + for ( int b=0 ; b < bits ; b++ ) { + reversed = ( reversed << 1 ) | ( 0x0001 & ( number >> b ) ); + } + + Serial.print ("Code "); + Serial.println (reversed, HEX); + + //========== + + for (int i = 0; i < 32; i++) { + if (!MATCH_MARK(results->rawbuf[offset], DAIKIN_ONE_MARK)) { + return false; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset], DAIKIN_ZERO_SPACE)) { + data <<= 1; + } else { + return false; + } + offset++; + } + + number = data ; // some number... + bits = 32 ; // nr of bits in some number + reversed = 0; + for ( int b=0 ; b < bits ; b++ ) { + reversed = ( reversed << 1 ) | ( 0x0001 & ( number >> b ) ); + } + + //Serial.print ("Code2 "); + //Serial.println (reversed, HEX); + + //=========== + if (!MATCH_SPACE(results->rawbuf[offset], 29000)) { + //Serial.println ("no gap"); + return false; + } + offset++; + + // Success + results->bits = DAIKIN_BITS; + results->value = reversed; + results->decode_type = DAIKIN; + return true; +} + +// Denon, from https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp +bool 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) { + return false; + } + + // Check initial Mark+Space match + if (!MATCH_MARK (results->rawbuf[offset++], DENON_HDR_MARK )) { + return false; + } + if (!MATCH_SPACE(results->rawbuf[offset++], DENON_HDR_SPACE)) { + return false; + } + + // Read the bits in + 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)) { + return false; + } + + // IR data is big-endian, so we shuffle it in from the right: + if (MATCH_SPACE(results->rawbuf[offset], DENON_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset], DENON_ZERO_SPACE)) { + data = (data << 1) | 0; + } else { + return false; + } + offset++; + } + + // Success + results->bits = DENON_BITS; + results->value = data; + results->decode_type = DENON; + return true; +} + + +/* ----------------------------------------------------------------------- + * hashdecode - decode an arbitrary IR code. + * Instead of decoding using a standard encoding scheme + * (e.g. Sony, NEC, RC5), the code is hashed to a 32-bit value. + * + * The algorithm: look at the sequence of MARK signals, and see if each one + * is shorter (0), the same length (1), or longer (2) than the previous. + * Do the same with the SPACE signals. Hszh the resulting sequence of 0's, + * 1's, and 2's to a 32-bit value. This will give a unique value for each + * different code (probably), for most code systems. + * + * http://arcfn.com/2010/01/using-arbitrary-remotes-with-arduino.html + */ + +// 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) { + if (newval < oldval * .8) { + return 0; + } else if (oldval < newval * .8) { + return 2; + } else { + return 1; + } +} + +// Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param +#define FNV_PRIME_32 16777619 +#define FNV_BASIS_32 2166136261 + +/* Converts the raw code values into a 32-bit hash code. + * Hopefully this code is unique for each button. + * This isn't a "real" decoding, just an arbitrary value. + */ +bool IRrecv::decodeHash(decode_results *results) { + // Require at least 6 samples to prevent triggering on noise + if (results->rawlen < 6) { + return false; + } + long hash = FNV_BASIS_32; + for (int i = 1; i+2 < results->rawlen; i++) { + int value = compare(results->rawbuf[i], results->rawbuf[i+2]); + // Add value into the hash + hash = (hash * FNV_PRIME_32) ^ value; + } + results->value = hash; + results->bits = 32; + results->decode_type = UNKNOWN; + return true; +} + +// --------------------------------------------------------------- diff --git a/lib/IRremoteESP8266/IRremoteESP8266.h b/lib/IRremoteESP8266/IRremoteESP8266.h new file mode 100644 index 000000000..247920f62 --- /dev/null +++ b/lib/IRremoteESP8266/IRremoteESP8266.h @@ -0,0 +1,221 @@ + /*************************************************** + * IRremote for ESP8266 + * + * Based on the IRremote library for Arduino by Ken Shirriff + * Version 0.11 August, 2009 + * Copyright 2009 Ken Shirriff + * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html + * + * Edited by Mitra to add new controller SANYO + * + * Interrupt code based on NECIRrcv by Joe Knapp + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 + * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ + * + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + * LG added by Darryl Smith (based on the JVC protocol) + * Whynter A/C ARC-110WD added by Francesco Meschia + * Coolix A/C / heatpump added by bakrus + * Denon: sendDenon, decodeDenon added by Massimiliano Pinto + (from https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp) + * Kelvinator A/C and Sherwood added by crankyoldgit + * Updated by markszabo (https://github.com/markszabo/IRremoteESP8266) for sending IR code on ESP8266 + * Updated by Sebastien Warin (http://sebastien.warin.fr) for receiving IR code on ESP8266 + * + * Updated by sillyfrog for Daikin, adopted from + * (https://github.com/mharizanov/Daikin-AC-remote-control-over-the-Internet/) + * + * GPL license, all text above must be included in any redistribution + ****************************************************/ + +#ifndef IRremote_h +#define IRremote_h + +#include + +// The following are compile-time library options. +// If you change them, recompile the library. +// If DEBUG is defined, a lot of debugging output will be printed during decoding. +// TEST must be defined for the IRtest unittests to work. It will make some +// methods virtual, which will be slightly slower, which is why it is optional. +//#define DEBUG +//#define TEST + +/* + * Always add to the end of the list and should never remove entries + * or change order. Projects may save the type number for later usage + * so numbering should always stay the same. + */ +enum decode_type_t { + UNKNOWN = -1, + UNUSED = 0, + RC5, + RC6, + NEC, + SONY, + PANASONIC, + JVC, + SAMSUNG, + WHYNTER, + AIWA_RC_T501, + LG, + SANYO, + MITSUBISHI, + DISH, + SHARP, + COOLIX, + DAIKIN, + DENON, + KELVINATOR, + SHERWOOD, + MITSUBISHI_AC +}; + +// Results returned from the decoder +class decode_results { +public: + int decode_type; // NEC, SONY, RC5, UNKNOWN + union { // This is used for decoding Panasonic and Sharp data + unsigned int panasonicAddress; + unsigned int sharpAddress; + }; + unsigned long value; // Decoded value + int bits; // Number of bits in decoded value + volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks + int rawlen; // Number of records in rawbuf. + bool overflow; +}; + +// 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_SHERWOOD case SHERWOOD: sendSherwood(data, nbits); break; + +// main class for receiving IR +class IRrecv +{ +public: + IRrecv(int recvpin); + bool decode(decode_results *results); + void enableIRIn(); + void disableIRIn(); + void resume(); + private: + // These are called by decode + int getRClevel(decode_results *results, int *offset, int *used, int t1); + bool decodeNEC(decode_results *results); + bool decodeSony(decode_results *results); + bool decodeSanyo(decode_results *results); + bool decodeMitsubishi(decode_results *results); + bool decodeRC5(decode_results *results); + bool decodeRC6(decode_results *results); + bool decodePanasonic(decode_results *results); + bool decodeLG(decode_results *results); + bool decodeJVC(decode_results *results); + bool decodeSAMSUNG(decode_results *results); + bool decodeWhynter(decode_results *results); + bool decodeHash(decode_results *results); + // COOLIX decode is not implemented yet + // bool decodeCOOLIX(decode_results *results); + bool decodeDaikin(decode_results *results); + bool decodeDenon(decode_results *results); + int compare(unsigned int oldval, unsigned int newval); +}; + +// Only used for testing; can remove virtual for shorter code +#ifdef TEST +#define VIRTUAL virtual +#else +#define VIRTUAL +#endif +class IRsend +{ +public: + IRsend(int IRsendPin); + void begin(); + void send(int type, unsigned long data, int nbits) { + switch (type) { + SEND_PROTOCOL_NEC + SEND_PROTOCOL_SONY + SEND_PROTOCOL_RC5 + SEND_PROTOCOL_RC6 + SEND_PROTOCOL_DISH + SEND_PROTOCOL_JVC + SEND_PROTOCOL_SAMSUNG + SEND_PROTOCOL_LG + SEND_PROTOCOL_WHYNTER + SEND_PROTOCOL_COOLIX + SEND_PROTOCOL_DENON + SEND_PROTOCOL_SHERWOOD + } + }; + 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); + // 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 + // it defaults to repeat=0 for backward compatiblity. + void sendSony(unsigned long data, int nbits, unsigned int repeat=0); + // Neither Sanyo nor Mitsubishi send is implemented yet + // void sendSanyo(unsigned long data, int nbits); + // void sendMitsubishi(unsigned long data, int nbits); + void sendRaw(unsigned int buf[], int len, int hz); + 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 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 sendKelvinator(unsigned char data[]); + void sendSherwood(unsigned long data, int nbits=32, unsigned int repeat=1); + void sendMitsubishiAC(unsigned char data[]); + void enableIROut(int khz); + VIRTUAL void mark(unsigned int usec); + VIRTUAL void space(unsigned long usec); +private: + int halfPeriodicTime; + int IRpin; + void sendMitsubishiACChunk(unsigned char data); + void sendData(uint16_t onemark, uint32_t onespace, + uint16_t zeromark, uint32_t zerospace, + uint32_t data, uint8_t nbits, bool MSBfirst=true); + void ledOff(); +} ; + +class IRtimer { +public: + IRtimer(); + void reset(); + uint32_t elapsed(); +private: + 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 new file mode 100644 index 000000000..ade21d5db --- /dev/null +++ b/lib/IRremoteESP8266/IRremoteInt.h @@ -0,0 +1,237 @@ + /*************************************************** + * IRremote for ESP8266 + * + * Based on the IRremote library for Arduino by Ken Shirriff + * Version 0.11 August, 2009 + * Copyright 2009 Ken Shirriff + * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html + * + * Modified by Paul Stoffregen to support other boards and timers + * + * Interrupt code based on NECIRrcv by Joe Knapp + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 + * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ + * + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + * Whynter A/C ARC-110WD added by Francesco Meschia + * Coolix A/C / heatpump added by bakrus + * Denon: sendDenon, decodeDenon added by Massimiliano Pinto + (from https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp) + * Kelvinator A/C added by crankyoldgit + * Mitsubishi A/C added by crankyoldgit + * (based on https://github.com/r45635/HVAC-IR-Control) + * + * 09/23/2015 : Samsung pulse parameters updated by Sebastien Warin to be compatible with EUxxD6200 + * + * GPL license, all text above must be included in any redistribution + ****************************************************/ + +#ifndef IRremoteint_h +#define IRremoteint_h + +#if defined(ARDUINO) && ARDUINO >= 100 +#include +#else +#include +#endif + +// Pulse parms are *50-100 for the Mark and *50+100 for the space +// First MARK is the one after the long gap +// pulse parameters in usec +#define COOLIX_BIT_MARK 560 // Approximately 21 cycles at 38kHz +#define COOLIX_ONE_SPACE COOLIX_BIT_MARK * 3 +#define COOLIX_ZERO_SPACE COOLIX_BIT_MARK * 1 +#define COOLIX_HDR_MARK COOLIX_BIT_MARK * 8 +#define COOLIX_HDR_SPACE COOLIX_BIT_MARK * 8 + +#define WHYNTER_HDR_MARK 2850 +#define WHYNTER_HDR_SPACE 2850 +#define WHYNTER_BIT_MARK 750 +#define WHYNTER_ONE_MARK 750 +#define WHYNTER_ONE_SPACE 2150 +#define WHYNTER_ZERO_MARK 750 +#define WHYNTER_ZERO_SPACE 750 + +#define NEC_HDR_MARK 9000 +#define NEC_HDR_SPACE 4500 +#define NEC_BIT_MARK 560 +#define NEC_ONE_SPACE 1690 +#define NEC_ZERO_SPACE 560 +#define NEC_RPT_SPACE 2250 +#define NEC_MIN_COMMAND_LENGTH 108000UL + +#define SONY_HDR_MARK 2400 +#define SONY_HDR_SPACE 600 +#define SONY_ONE_MARK 1200 +#define SONY_ZERO_MARK 600 +#define SONY_RPT_LENGTH 45000 +#define SONY_DOUBLE_SPACE_USECS 500 // usually see 713 - not using ticks as get number wrapround + +// SA 8650B +#define SANYO_HDR_MARK 3500 // seen range 3500 +#define SANYO_HDR_SPACE 950 // seen 950 +#define SANYO_ONE_MARK 2400 // seen 2400 +#define SANYO_ZERO_MARK 700 // seen 700 +#define SANYO_DOUBLE_SPACE_USECS 800 // usually see 713 - not using ticks as get number wrapround +#define SANYO_RPT_LENGTH 45000 + +// Mitsubishi RM 75501 +// 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 + +// #define MITSUBISHI_HDR_MARK 250 // seen range 3500 +#define MITSUBISHI_HDR_SPACE 350 // 7*50+100 +#define MITSUBISHI_ONE_MARK 1950 // 41*50-100 +#define MITSUBISHI_ZERO_MARK 750 // 17*50-100 +// #define MITSUBISHI_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround +// #define MITSUBISHI_RPT_LENGTH 45000 + +// Mitsubishi A/C +// Values were initially obtained from: +// https://github.com/r45635/HVAC-IR-Control/blob/master/HVAC_ESP8266/HVAC_ESP8266.ino#L84 +#define MITSUBISHI_AC_HDR_MARK 3400 +#define MITSUBISHI_AC_HDR_SPACE 1750 +#define MITSUBISHI_AC_BIT_MARK 450 +#define MITSUBISHI_AC_ONE_SPACE 1300 +#define MITSUBISHI_AC_ZERO_SPACE 420 +#define MITSUBISHI_AC_RPT_MARK 440 +#define MITSUBISHI_AC_RPT_SPACE 17100L + + +#define RC5_T1 889 +#define RC5_RPT_LENGTH 46000 + +#define RC6_HDR_MARK 2666 +#define RC6_HDR_SPACE 889 +#define RC6_T1 444 +#define RC6_RPT_LENGTH 46000 + +#define SHARP_BIT_MARK 245 +#define SHARP_ONE_SPACE 1805 +#define SHARP_ZERO_SPACE 795 +#define SHARP_GAP 600000 +#define SHARP_TOGGLE_MASK 0x3FF +#define SHARP_RPT_SPACE 3000 + +#define DISH_HDR_MARK 400 +#define DISH_HDR_SPACE 6100 +#define DISH_BIT_MARK 400 +#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 + +#define JVC_HDR_MARK 8000 +#define JVC_HDR_SPACE 4000 +#define JVC_BIT_MARK 600 +#define JVC_ONE_SPACE 1600 +#define JVC_ZERO_SPACE 550 +#define JVC_RPT_LENGTH 60000 + +#define LG_HDR_MARK 8000 +#define LG_HDR_SPACE 4000 +#define LG_BIT_MARK 600 +#define LG_ONE_SPACE 1600 +#define LG_ZERO_SPACE 550 +#define LG_RPT_LENGTH 60000 + +/* +#define SAMSUNG_HDR_MARK 5000 +#define SAMSUNG_HDR_SPACE 5000 +#define SAMSUNG_BIT_MARK 560 +#define SAMSUNG_ONE_SPACE 1600 +#define SAMSUNG_ZERO_SPACE 560 +#define SAMSUNG_RPT_SPACE 2250 +*/ + +// Update by Sebastien Warin for my EU46D6200 +#define SAMSUNG_HDR_MARK 4500 +#define SAMSUNG_HDR_SPACE 4500 +#define SAMSUNG_BIT_MARK 590 +#define SAMSUNG_ONE_SPACE 1690 +#define SAMSUNG_ZERO_SPACE 590 +#define SAMSUNG_RPT_SPACE 2250 + +#define SHARP_BITS 15 +#define DISH_BITS 16 + +// Daikin, from https://github.com/mharizanov/Daikin-AC-remote-control-over-the-Internet/tree/master/IRremote +#define DAIKIN_HDR_MARK 3650 //DAIKIN_ZERO_MARK*8 +#define DAIKIN_HDR_SPACE 1623 //DAIKIN_ZERO_MARK*4 +#define DAIKIN_ONE_SPACE 1280 +#define DAIKIN_ONE_MARK 428 +#define DAIKIN_ZERO_MARK 428 +#define DAIKIN_ZERO_SPACE 428 + +//Denon, from https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp +#define DENON_BITS 14 // The number of bits in the command +#define DENON_HDR_MARK 300 // The length of the Header:Mark +#define DENON_HDR_SPACE 750 // The lenght of the Header:Space +#define DENON_BIT_MARK 300 // The length of a Bit:Mark +#define DENON_ONE_SPACE 1800 // The length of a Bit:Space for 1's +#define DENON_ZERO_SPACE 750 // The length of a Bit:Space for 0's + +#define KELVINATOR_HDR_MARK 8990U +#define KELVINATOR_HDR_SPACE 4490U +#define KELVINATOR_BIT_MARK 675U +#define KELVINATOR_ONE_SPACE 1560U +#define KELVINATOR_ZERO_SPACE 520U +#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.) + +#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)) + +// receiver states +#define STATE_IDLE 2 +#define STATE_MARK 3 +#define STATE_SPACE 4 +#define STATE_STOP 5 + +// 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; +} +irparams_t; + +// Defined in IRremote.cpp +extern volatile irparams_t irparams; + +// IR detector output is active low +#define MARK 0 +#define SPACE 1 + +#define TOPBIT 0x80000000 + +#define NEC_BITS 32 +#define SONY_BITS 12 +#define SANYO_BITS 12 +#define MITSUBISHI_BITS 16 +#define MIN_RC5_SAMPLES 11 +#define MIN_RC6_SAMPLES 1 +#define PANASONIC_BITS 48 +#define JVC_BITS 16 +#define LG_BITS 28 +#define SAMSUNG_BITS 32 +#define WHYNTER_BITS 32 +#define COOLIX_NBYTES 3 +#define DAIKIN_BITS 99 + +#endif diff --git a/lib/IRremoteESP8266/LICENSE.txt b/lib/IRremoteESP8266/LICENSE.txt new file mode 100644 index 000000000..77cec6dd1 --- /dev/null +++ b/lib/IRremoteESP8266/LICENSE.txt @@ -0,0 +1,458 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + diff --git a/lib/IRremoteESP8266/README.md b/lib/IRremoteESP8266/README.md new file mode 100644 index 000000000..bb9040cd2 --- /dev/null +++ b/lib/IRremoteESP8266/README.md @@ -0,0 +1,29 @@ +# IRremote ESP8266 Library + +[![Build Status](https://travis-ci.org/markszabo/IRremoteESP8266.svg?branch=master)](https://travis-ci.org/markszabo/IRremoteESP8266) + +This library enables you to **send and receive** infra-red signals on an ESP8266 using Arduino framework (https://github.com/esp8266/Arduino) + +This library is based on Ken Shirriff's work (https://github.com/shirriff/Arduino-IRremote/) + +[Mark Szabo](https://github.com/markszabo/IRremoteESP8266) has updated the IRsend class to work on ESP8266 and [Sebastien Warin](https://github.com/sebastienwarin/IRremoteESP8266) the receiving & decoding part (IRrecv class). + +Seb's notes : I also changed the pulse parameters for Samsung, update the Panasonic and Samsung decoders and remove the SANYO decoders. The IR decoder was successfully tested with Panasonic and Samsung remote controls. + +## Installation +1. Click "Download ZIP" +2. Extract the downloaded zip file +3. Rename the extracted folder to "IRremoteESP8266" +4. Move this folder to your libraries directory (under windows: C:\Users\YOURNAME\Documents\Arduino\libraries\) +5. Restart your Arduino ide +6. Check out the examples + +## Contributing +If you want to contribute to this project: +- Report bugs and errors +- Ask for enhancements +- Create issues and pull requests +- Tell other people about this library + +## Contributors +Check [here](Contributors.md) diff --git a/lib/IRremoteESP8266/examples/IRGCSendDemo/IRGCSendDemo.ino b/lib/IRremoteESP8266/examples/IRGCSendDemo/IRGCSendDemo.ino new file mode 100644 index 000000000..e0534414e --- /dev/null +++ b/lib/IRremoteESP8266/examples/IRGCSendDemo/IRGCSendDemo.ino @@ -0,0 +1,26 @@ +/* + * IRremoteESP8266: IRsendGCDemo - demonstrates sending Global Cache-formatted IR codes with IRsend + * An IR LED must be connected to ESP8266 pin 0. + * Version 0.1 30 March, 2016 + * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com + */ + +#include + +// Codes are in Global Cache format less the emitter ID and request ID. These codes can be found in GC's Control Tower database. + +unsigned int Samsung_power_toggle[71] = {38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798}; + +IRsend irsend(4); //an IR emitter led is connected to GPIO pin 4 + +void setup() +{ + irsend.begin(); + Serial.begin(115200); +} + +void loop() { + Serial.println("Toggling power"); + irsend.sendGC(Samsung_power_toggle, 71); + delay(10000); +} \ No newline at end of file diff --git a/lib/IRremoteESP8266/examples/IRGCTCPServer/IRGCTCPServer.ino b/lib/IRremoteESP8266/examples/IRGCTCPServer/IRGCTCPServer.ino new file mode 100644 index 000000000..b5ea42294 --- /dev/null +++ b/lib/IRremoteESP8266/examples/IRGCTCPServer/IRGCTCPServer.ino @@ -0,0 +1,85 @@ +/* + * IRremoteESP8266: IRGCTCPServer - send Global Cache-formatted codes via TCP. + * An IR emitter must be connected to GPIO pin 4. + * Version 0.1 1 April, 2016 + * Hisham Khalifa, http://www.hishamkhalifa.com + * + * Example command - Samsung TV power toggle: 38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798\r\n + */ + +#include +#include + +#include +#include +#include + +const char* ssid = "..."; +const char* password = "..."; + +WiFiServer server(4998); // Uses port 4998. +WiFiClient client; + +unsigned int *codeArray; +IRsend irsend(4); //an IR emitter led is connected to GPIO pin 4 + +void parseString(String str) { + int nextIndex; + int codeLength = 1; + int currentIndex = 0; + nextIndex = str.indexOf(','); + + // change to do/until and remove superfluous repetition below... + while (nextIndex != -1) { + if (codeLength > 1) { + codeArray = (unsigned int*) realloc(codeArray, codeLength * sizeof(unsigned int)); + } else { + codeArray = (unsigned int*) malloc(codeLength * sizeof(unsigned int)); + } + + codeArray[codeLength-1] = (unsigned int) (str.substring(currentIndex, nextIndex).toInt()); + + codeLength++; + currentIndex = nextIndex + 1; + nextIndex = str.indexOf(',', currentIndex); + } + codeArray = (unsigned int*) realloc(codeArray, codeLength * sizeof(unsigned int)); + codeArray[codeLength-1] = (unsigned int) (str.substring(currentIndex, nextIndex).toInt()); + + irsend.sendGC(codeArray,codeLength); +} + +void setup() { + // initialize serial: + Serial.begin(115200); + Serial.println(" "); + Serial.println("IR TCP Server"); + + while (WiFi.status() != WL_CONNECTED) { + delay(900); + Serial.print("."); + } + + server.begin(); + IPAddress myAddress = WiFi.localIP(); + Serial.println(myAddress); + irsend.begin(); +} + +void loop() { + while(!client) { + client = server.available(); + } + + while(!client.connected()){ + delay(900); + client = server.available(); + } + + if(client.available()){ + String irCode = client.readStringUntil('\r'); // Exclusive of \r + client.readStringUntil('\n'); // Skip new line as well + client.flush(); + parseString(irCode); + } +} \ No newline at end of file diff --git a/lib/IRremoteESP8266/examples/IRServer/IRServer.ino b/lib/IRremoteESP8266/examples/IRServer/IRServer.ino new file mode 100644 index 000000000..94cf929ee --- /dev/null +++ b/lib/IRremoteESP8266/examples/IRServer/IRServer.ino @@ -0,0 +1,88 @@ +/* + * IRremoteESP8266: IRServer - demonstrates sending IR codes controlled from a webserver + * An IR LED must be connected to ESP8266 pin 0. + * Version 0.1 June, 2015 + */ + +#include +#include +#include +#include +#include + +const char* ssid = "....."; +const char* password = "....."; +MDNSResponder mdns; + +ESP8266WebServer server(80); + +IRsend irsend(0); + +void handleRoot() { + server.send(200, "text/html", " ESP8266 Demo

Hello from ESP8266, you can send NEC encoded IR signals from here!

Send 0xFFE01F

Send 0xFAB123

Send 0xFFE896

"); +} + +void handleIr(){ + for (uint8_t i=0; i + +int RECV_PIN = 2; //an IR detector/demodulatord is connected to GPIO pin 2 + +IRrecv irrecv(RECV_PIN); + +decode_results results; + +void setup() +{ + Serial.begin(9600); + irrecv.enableIRIn(); // Start the receiver +} + +void loop() { + if (irrecv.decode(&results)) { + Serial.println(results.value, HEX); + irrecv.resume(); // Receive the next value + } + delay(100); +} diff --git a/lib/IRremoteESP8266/examples/IRrecvDump/IRrecvDump.ino b/lib/IRremoteESP8266/examples/IRrecvDump/IRrecvDump.ino new file mode 100644 index 000000000..454b06628 --- /dev/null +++ b/lib/IRremoteESP8266/examples/IRrecvDump/IRrecvDump.ino @@ -0,0 +1,89 @@ +/* + * IRremoteESP8266: IRrecvDump - dump details of IR codes with IRrecv + * An IR detector/demodulator must be connected to the input RECV_PIN. + * Version 0.1 Sept, 2015 + * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + * LG added by Darryl Smith (based on the JVC protocol) + */ + +#include + +int RECV_PIN = 2; //an IR detector/demodulatord is connected to GPIO pin 2 + +IRrecv irrecv(RECV_PIN); + +decode_results results; + +void setup() +{ + Serial.begin(9600); + irrecv.enableIRIn(); // Start the receiver +} + + +void dump(decode_results *results) { + // Dumps out the decode_results structure. + // Call this after IRrecv::decode() + int count = results->rawlen; + if (results->decode_type == UNKNOWN) { + Serial.print("Unknown encoding: "); + } + else if (results->decode_type == NEC) { + Serial.print("Decoded NEC: "); + + } + else if (results->decode_type == SONY) { + Serial.print("Decoded SONY: "); + } + else if (results->decode_type == RC5) { + Serial.print("Decoded RC5: "); + } + else if (results->decode_type == RC6) { + Serial.print("Decoded RC6: "); + } + else if (results->decode_type == PANASONIC) { + Serial.print("Decoded PANASONIC - Address: "); + Serial.print(results->panasonicAddress, HEX); + Serial.print(" Value: "); + } + else if (results->decode_type == LG) { + Serial.print("Decoded LG: "); + } + else if (results->decode_type == JVC) { + Serial.print("Decoded JVC: "); + } + else if (results->decode_type == AIWA_RC_T501) { + Serial.print("Decoded AIWA RC T501: "); + } + else if (results->decode_type == WHYNTER) { + Serial.print("Decoded Whynter: "); + } + Serial.print(results->value, HEX); + Serial.print(" ("); + Serial.print(results->bits, DEC); + Serial.println(" bits)"); + Serial.print("Raw ("); + Serial.print(count, DEC); + Serial.print("): "); + + for (int i = 1; i < count; i++) { + if (i & 1) { + Serial.print(results->rawbuf[i]*USECPERTICK, DEC); + } + else { + Serial.write('-'); + Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC); + } + Serial.print(" "); + } + Serial.println(); +} + +void loop() { + if (irrecv.decode(&results)) { + Serial.println(results.value, HEX); + dump(&results); + irrecv.resume(); // Receive the next value + } +} diff --git a/lib/IRremoteESP8266/examples/IRrecvDumpV2/IRrecvDumpV2.ino b/lib/IRremoteESP8266/examples/IRrecvDumpV2/IRrecvDumpV2.ino new file mode 100644 index 000000000..877c99268 --- /dev/null +++ b/lib/IRremoteESP8266/examples/IRrecvDumpV2/IRrecvDumpV2.ino @@ -0,0 +1,174 @@ +/* + * IRremoteESP8266: IRrecvDumpV2 - dump details of IR codes with IRrecv + * An IR detector/demodulator must be connected to the input RECV_PIN. + * Version 0.1 Sept, 2015 + * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com + */ + +#include + +int RECV_PIN = 2; //an IR detector/demodulator is connected to GPIO pin 2 + +IRrecv irrecv(RECV_PIN); + +void setup ( ) +{ + Serial.begin(9600); // Status message will be sent to PC at 9600 baud + irrecv.enableIRIn(); // Start the receiver +} + +//+============================================================================= +// Display IR code +// +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); +} + +//+============================================================================= +// Display encoding type +// +void encoding (decode_results *results) +{ + switch (results->decode_type) { + default: + case UNKNOWN: Serial.print("UNKNOWN"); break ; + case NEC: Serial.print("NEC"); break ; + case SONY: Serial.print("SONY"); break ; + case RC5: Serial.print("RC5"); break ; + case RC6: Serial.print("RC6"); break ; + case DISH: Serial.print("DISH"); break ; + case SHARP: Serial.print("SHARP"); break ; + case JVC: Serial.print("JVC"); break ; + case SANYO: Serial.print("SANYO"); break ; + case MITSUBISHI: Serial.print("MITSUBISHI"); break ; + case SAMSUNG: Serial.print("SAMSUNG"); break ; + case LG: Serial.print("LG"); break ; + case WHYNTER: Serial.print("WHYNTER"); break ; + case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ; + case PANASONIC: Serial.print("PANASONIC"); break ; + } +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpInfo (decode_results *results) +{ + if (results->overflow) { + Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF"); + return; + } + + // Show Encoding standard + Serial.print("Encoding : "); + encoding(results); + Serial.println(""); + + // Show Code & length + Serial.print("Code : "); + ircode(results); + Serial.print(" ("); + Serial.print(results->bits, DEC); + Serial.println(" bits)"); +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpRaw (decode_results *results) +{ + // Print Raw data + Serial.print("Timing["); + Serial.print(results->rawlen-1, DEC); + Serial.println("]: "); + + for (int i = 1; i < results->rawlen; i++) { + unsigned long x = results->rawbuf[i] * USECPERTICK; + if (!(i & 1)) { // even + Serial.print("-"); + if (x < 1000) Serial.print(" ") ; + if (x < 100) Serial.print(" ") ; + Serial.print(x, DEC); + } else { // odd + Serial.print(" "); + Serial.print("+"); + if (x < 1000) Serial.print(" ") ; + if (x < 100) Serial.print(" ") ; + Serial.print(x, DEC); + if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one + } + if (!(i % 8)) Serial.println(""); + } + Serial.println(""); // Newline +} + +//+============================================================================= +// Dump out the decode_results structure. +// +void dumpCode (decode_results *results) +{ + // Start declaration + Serial.print("unsigned int "); // variable type + Serial.print("rawData["); // array name + Serial.print(results->rawlen - 1, DEC); // array size + Serial.print("] = {"); // Start declaration + + // Dump data + for (int i = 1; i < results->rawlen; i++) { + Serial.print(results->rawbuf[i] * USECPERTICK, DEC); + if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one + if (!(i & 1)) Serial.print(" "); + } + + // End declaration + Serial.print("};"); // + + // Comment + Serial.print(" // "); + encoding(results); + Serial.print(" "); + ircode(results); + + // Newline + Serial.println(""); + + // 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"); + Serial.print(results->panasonicAddress, HEX); + Serial.println(";"); + } + + // All protocols have data + Serial.print("unsigned int data = 0x"); + Serial.print(results->value, HEX); + Serial.println(";"); + } +} + +//+============================================================================= +// The repeating section of the code +// +void loop ( ) +{ + decode_results results; // Somewhere to store the results + + if (irrecv.decode(&results)) { // Grab an IR code + 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 new file mode 100644 index 000000000..449b79a22 --- /dev/null +++ b/lib/IRremoteESP8266/examples/IRsendDemo/IRsendDemo.ino @@ -0,0 +1,25 @@ +/* + * IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend + * An IR LED must be connected to ESP8266 pin 0. + * Version 0.1 June, 2015 + * 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 + +void setup() +{ + irsend.begin(); + Serial.begin(9600); +} + +void loop() { + Serial.println("NEC"); + irsend.sendNEC(0x00FFE01FUL, 32); + delay(2000); + Serial.println("Sony"); + irsend.sendSony(0xa90, 12); + delay(2000); +} diff --git a/lib/IRremoteESP8266/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino b/lib/IRremoteESP8266/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino new file mode 100644 index 000000000..fddc55989 --- /dev/null +++ b/lib/IRremoteESP8266/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino @@ -0,0 +1,29 @@ +/* + * IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend + * An IR LED must be connected to ESP8266 pin 0. + * Version 0.1 June, 2015 + * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + */ +#include + +#define PanasonicAddress 0x4004 // Panasonic address (Pre data) +#define PanasonicPower 0x100BCBD // Panasonic Power button + +#define JVCPower 0xC5E8 + +IRsend irsend(0); //an IR led is connected to GPIO pin 0 + +void setup() +{ + irsend.begin(); +} + +void loop() { + irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off + + irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat + delayMicroseconds(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information + irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat + delayMicroseconds(50); +} diff --git a/lib/IRremoteESP8266/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino b/lib/IRremoteESP8266/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino new file mode 100644 index 000000000..ef5c7f282 --- /dev/null +++ b/lib/IRremoteESP8266/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino @@ -0,0 +1,27 @@ + +#include + +IRDaikinESP dakinir(D1); + +void setup(){ + dakinir.begin(); + Serial.begin(115200); +} + + +void loop(){ + Serial.println("Sending..."); + + // Set up what we want to send. See IRDaikinESP.cpp for all the options. + dakinir.on(); + dakinir.setFan(1); + dakinir.setMode(DAIKIN_COOL); + dakinir.setTemp(25); + dakinir.setSwingVertical(0); + dakinir.setSwingHorizontal(0); + + // Now send the IR signal. + dakinir.send(); + + delay(5000); +} diff --git a/lib/IRremoteESP8266/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino b/lib/IRremoteESP8266/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino new file mode 100644 index 000000000..155c4db40 --- /dev/null +++ b/lib/IRremoteESP8266/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino @@ -0,0 +1,52 @@ + +#include + +IRKelvinatorAC kelvir(D1); // IR led controlled by Pin D1. + +void printState() { + // Display the settings. + Serial.println("Kelvinator A/C remote is in the following state:"); + Serial.printf(" Basic\n Power: %d, Mode: %d, Temp: %dC, Fan Speed: %d\n", + kelvir.getPower(), kelvir.getMode(), kelvir.getTemp(), + kelvir.getFan()); + Serial.printf(" Options\n X-Fan: %d, Light: %d, Ion Filter: %d\n", + kelvir.getXFan(), kelvir.getLight(), kelvir.getIonFilter()); + Serial.printf(" Swing (V): %d, Swing (H): %d, Turbo: %d, Quiet: %d\n", + kelvir.getSwingVertical(), kelvir.getSwingHorizontal(), + kelvir.getTurbo(), kelvir.getQuiet()); + // Display the encoded IR sequence. + unsigned char* ir_code = kelvir.getRaw(); + Serial.print("IR Code: 0x"); + for (int i = 0; i < KELVINATOR_STATE_LENGTH; i++) + Serial.printf("%02X", ir_code[i]); + Serial.println(); +} + +void setup(){ + kelvir.begin(); + Serial.begin(115200); + delay(200); + + // Set up what we want to send. See IRKelvinator.cpp for all the options. + // Most things default to off. + Serial.println("Default state of the remote."); + printState(); + Serial.println("Setting desired state for A/C."); + kelvir.on(); + kelvir.setFan(1); + kelvir.setMode(KELVINATOR_COOL); + kelvir.setTemp(26); + kelvir.setSwingVertical(false); + kelvir.setSwingHorizontal(true); + kelvir.setXFan(true); + kelvir.setIonFilter(false); + kelvir.setLight(true); +} + +void loop() { + // Now send the IR signal. + Serial.println("Sending IR command to A/C ..."); + kelvir.send(); + printState(); + delay(5000); +} diff --git a/lib/IRremoteESP8266/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino b/lib/IRremoteESP8266/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino new file mode 100644 index 000000000..5a0d17824 --- /dev/null +++ b/lib/IRremoteESP8266/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino @@ -0,0 +1,42 @@ + +#include + +IRMitsubishiAC mitsubir(D1); // IR led controlled by Pin D1. + +void printState() { + // Display the settings. + Serial.println("Mitsubishi A/C remote is in the following state:"); + Serial.printf(" Power: %d, Mode: %d, Temp: %dC, Fan Speed: %d, Vane Mode: %d\n", + mitsubir.getPower(), mitsubir.getMode(), mitsubir.getTemp(), + mitsubir.getFan(), mitsubir.getVane()); + // Display the encoded IR sequence. + unsigned char* ir_code = mitsubir.getRaw(); + Serial.print("IR Code: 0x"); + for (int i = 0; i < MITSUBISHI_AC_STATE_LENGTH; i++) + Serial.printf("%02X", ir_code[i]); + Serial.println(); +} + +void setup(){ + mitsubir.begin(); + Serial.begin(115200); + delay(200); + + // Set up what we want to send. See IRMitsubishiAC.cpp for all the options. + Serial.println("Default state of the remote."); + printState(); + Serial.println("Setting desired state for A/C."); + mitsubir.on(); + mitsubir.setFan(1); + mitsubir.setMode(MITSUBISHI_AC_COOL); + mitsubir.setTemp(26); + mitsubir.setVane(MITSUBISHI_AC_VANE_AUTO); +} + +void loop() { + // Now send the IR signal. + Serial.println("Sending IR command to A/C ..."); + mitsubir.send(); + printState(); + delay(5000); +} diff --git a/lib/IRremoteESP8266/keywords.txt b/lib/IRremoteESP8266/keywords.txt new file mode 100644 index 000000000..7bdc4c91c --- /dev/null +++ b/lib/IRremoteESP8266/keywords.txt @@ -0,0 +1,68 @@ +####################################### +# Syntax Coloring Map For IRremote +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +decode_results KEYWORD1 +IRrecv KEYWORD1 +IRsend KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +decode KEYWORD2 +enableIRIn KEYWORD2 +disableIRIn KEYWORD2 +resume KEYWORD2 +begin KEYWORD2 +enableIROut KEYWORD2 +sendNEC KEYWORD2 +sendNECRepeat KEYWORD2 +sendSony KEYWORD2 +sendSanyo KEYWORD2 +sendMitsubishi KEYWORD2 +sendRaw KEYWORD2 +sendRC5 KEYWORD2 +sendRC6 KEYWORD2 +sendDISH KEYWORD2 +sendSharp KEYWORD2 +sendSharpRaw KEYWORD2 +sendPanasonic KEYWORD2 +sendJVC KEYWORD2 +sendWhynter KEYWORD2 +sendSAMSUNG KEYWORD2 +sendCOOLIX KEYWORD2 +sendDenon KEYWORD2 +sendKelvinator KEYWORD2 +sendSherwood KEYWORD2 +sendMitsubishiAC KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + +NEC LITERAL1 +SONY LITERAL1 +SANYO LITERAL1 +MITSUBISHI LITERAL1 +RC5 LITERAL1 +RC6 LITERAL1 +DISH LITERAL1 +SHARP LITERAL1 +PANASONIC LITERAL1 +JVC LITERAL1 +LG LITERAL1 +SAMSUNG LITERAL1 +WHYNTER LITERAL1 +AIWA_RC_T501 LITERAL1 +COOLIX LITERAL1 +UNKNOWN LITERAL1 +REPEAT LITERAL1 +DENON LITERAL1 +KELVINATOR LITERAL1 +SHERWOOD LITERAL1 +MITSUBISHIAC LITERAL1 diff --git a/lib/IRremoteESP8266/library.json b/lib/IRremoteESP8266/library.json new file mode 100644 index 000000000..776e3c3b6 --- /dev/null +++ b/lib/IRremoteESP8266/library.json @@ -0,0 +1,44 @@ +{ + "name": "IRremoteESP8266", + "version": "1.0.2", + "keywords": "infrared, ir, remote, esp8266", + "description": "Send and receive infrared signals with multiple protocols (ESP8266)", + "repository": + { + "type": "git", + "url": "https://github.com/markszabo/IRremoteESP8266.git" + }, + "authors": [ + { + "name": "Ken Shirriff", + "email": "zetoslab@gmail.com" + }, + { + "name": "Mark Szabo", + "url": "http://nomartini-noparty.blogspot.com/", + "maintainer": true + }, + { + "name": "Sebastien Warin", + "url": "http://sebastien.warin.fr", + "maintainer": true + }, + { + "name": "David Conran", + "url": "https://plus.google.com/+davidconran", + "maintainer": true + }, + { + "name": "Roi Dayan", + "url": "https://github.com/roidayan/", + "maintainer": true + }, + { + "name": "Massimiliano Pinto", + "url": "https://github.com/pintomax/", + "maintainer": true + } + ], + "frameworks": "arduino", + "platforms": "espressif8266" +} diff --git a/lib/IRremoteESP8266/library.properties b/lib/IRremoteESP8266/library.properties new file mode 100644 index 000000000..403f88cd2 --- /dev/null +++ b/lib/IRremoteESP8266/library.properties @@ -0,0 +1,9 @@ +name=IRremoteESP8266 +version=1.0.2 +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) +paragraph=This library enables you to send and receive infra-red signals on an ESP8266. +category=Device Control +url=https://github.com/markszabo/IRremoteESP8266 +architectures=esp8266