From bdb9f1c1f58436b241d05f4f13ecb1dcc491373e Mon Sep 17 00:00:00 2001 From: Rafi Khan Date: Sat, 23 Sep 2017 21:03:07 -0400 Subject: [PATCH] Added support for RC5 extended Credits: https://github.com/LarsWH Excerpt from PR: ``` Hi, I added support for 'RC5 extended' in order to make this project: https://www.instructables.com/id/Remote-Control-for-Lava-mMotion-Swing-Mounting-Bra/ The modification is working nicely in this single application. It has not been tested elsewhere. (I am new to Git and this is my first pull request ever. So please excuse me if I have messed something up) Kind regards, Lars ``` Merged #522 --- IRremote.h | 1 + changelog.md | 7 ++---- ir_RC5_RC6.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/IRremote.h b/IRremote.h index fe1a870..4ce810e 100644 --- a/IRremote.h +++ b/IRremote.h @@ -270,6 +270,7 @@ class IRsend //...................................................................... # if SEND_RC5 void sendRC5 (unsigned long data, int nbits) ; + void sendRC5ext (unsigned long addr, unsigned long cmd, boolean toggle); # endif # if SEND_RC6 void sendRC6 (unsigned long data, int nbits) ; diff --git a/changelog.md b/changelog.md index a3adbfe..3435389 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,5 @@ -## 3.0.0 - 2017/09/14 -- Changed default send pin on ATmega32u4 from 13 to 9. - Note: this is a non-backwards compatible change as the behaviour of existing programs using this board for receiving WILL be affected. If you would like to use pin 13 as before then please search src/boarddefs.h for "32u4" and comment the line for pin 9 while uncommenting the line for pin 13 - - +## 2.4.3 +- Added Philips Extended RC-5 protocol support [PR #522] (https://github.com/z3t0/Arduino-IRremote/pull/522) ## 2.3.3 - 2017/03/31 - Added ESP32 IR receive support [PR #427](https://github.com/z3t0/Arduino-IRremote/pull/425) diff --git a/ir_RC5_RC6.cpp b/ir_RC5_RC6.cpp index 10e7927..e16a334 100644 --- a/ir_RC5_RC6.cpp +++ b/ir_RC5_RC6.cpp @@ -78,6 +78,73 @@ void IRsend::sendRC5 (unsigned long data, int nbits) space(0); // Always end with the LED off } + +void IRsend::sendRC5ext (unsigned long addr, unsigned long cmd, boolean toggle) +{ + // Set IR carrier frequency + enableIROut(36); + + unsigned long addressBits = 5; + unsigned long commandBits = 7; + unsigned long nbits = addressBits + commandBits; + + // Start + mark(RC5_T1); + + // Bit #6 of the command part, but inverted! + unsigned long cmdBit6 = (1UL << (commandBits-1)) & cmd; + if (cmdBit6) { + // Inverted (1 -> 0 = mark-to-space) + mark(RC5_T1); + space(RC5_T1); + } else { + space(RC5_T1); + mark(RC5_T1); + } + commandBits--; + + // Toggle bit + static int toggleBit = 1; + if (toggle) { + if (toggleBit == 0) { + toggleBit = 1; + } else { + toggleBit = 0; + } + } + if (toggleBit) { + space(RC5_T1); + mark(RC5_T1); + } else { + mark(RC5_T1); + space(RC5_T1); + } + + // Address + for (unsigned long mask = 1UL << (addressBits - 1); mask; mask >>= 1) { + if (addr & mask) { + space(RC5_T1); // 1 is space, then mark + mark(RC5_T1); + } else { + mark(RC5_T1); + space(RC5_T1); + } + } + + // Command + for (unsigned long mask = 1UL << (commandBits - 1); mask; mask >>= 1) { + if (cmd & mask) { + space(RC5_T1); // 1 is space, then mark + mark(RC5_T1); + } else { + mark(RC5_T1); + space(RC5_T1); + } + } + + space(0); // Always end with the LED off +} + #endif //+=============================================================================