Changes to the IRremote library
As mentioned, this work included some changes to the IRremote library code, as described below. Note that there now are newer versions of the IRremote library, so some of this may not be required.
IRremote.cpp
In this file, I added a new function for sending IR signals with the Panasonic TV protocol, and I also added a similar function for sending with the Samsung DVD protocol.
The original IRremote library does not support more than 32 bits, i.e. the send-out data must not exceed 32 bits. The Pansaonic, however, requires 48 bit and the Samsung 42. The solution was to add a second parameter for communicating the “over 32” bits to the library function.
So, I added functions sendPanasonic and sendSamsung as shown below. For the Panasonic, I had to add some space(30000); calls because I saw online someone else who had done that. I did not fully research why this is needed, but it works.
The IRremote library also includes code for receiving the various protocols, but I did not make such additions for these Panasonic & Samsung protocols.
//Added Panasonic --- a more than 32 bit protocol
// First 32 bit in data1
// Remaining bits leftadjusted in data2
void IRsend::sendPanasonic(unsigned long data1, unsigned long data2, int nbits) {
enableIROut(38);
mark(PANASONIC_HDR_MARK);
space(PANASONIC_HDR_SPACE);
for (int i = 0; i < 32; i++) {
if (data1 & TOPBIT) {
mark(PANASONIC_BIT_MARK);
space(PANASONIC_ONE_SPACE);
}
else {
mark(PANASONIC_BIT_MARK);
space(PANASONIC_ZERO_SPACE);
}
data1 <<= 1;
}
nbits = nbits - 32;
for (int i = 0; i < nbits; i++) {
if (data2 & TOPBIT) {
mark(PANASONIC_BIT_MARK);
space(PANASONIC_ONE_SPACE);
}
else {
mark(PANASONIC_BIT_MARK);
space(PANASONIC_ZERO_SPACE);
}
data2 <<= 1;
}
mark(PANASONIC_BIT_MARK);
space(30000);
space(30000);
space(14000);
}
// Added Samsung code - a 42 bit protocol
// First 32 bit in data1
// Remaining bits left-adjusted in data2
// Code is exact copy of NEC with extra loop for data2
void IRsend::sendSamsung(unsigned long data1, unsigned long data2, int nbits)
{
enableIROut(38);
mark(NEC_HDR_MARK);
space(NEC_HDR_SPACE);
for (int i = 0; i < 32; i++) {
if (data1 & TOPBIT) {
mark(NEC_BIT_MARK);
space(NEC_ONE_SPACE);
}
else {
mark(NEC_BIT_MARK);
space(NEC_ZERO_SPACE);
}
data1 <<= 1;
}
//last bits
nbits = nbits -32;
for (int i = 0; i < nbits; i++) {
if (data2 & TOPBIT) {
mark(NEC_BIT_MARK);
space(NEC_ONE_SPACE);
}
else {
mark(NEC_BIT_MARK);
space(NEC_ZERO_SPACE);
}
data2 <<= 1;
}
mark(NEC_BIT_MARK);
space(0);
}
IRremote.h
The above functions need to be declared in this file as well.
void sendPanasonic(unsigned long data1, unsigned long data2, int nbits);
void sendSamsung(unsigned long data1, unsigned long data2, int nbits);
The internal buffer for receiving IR data needs to be longer. Changed 76 to 140:
#define RAWBUF 140 // Length of raw duration buffer
IRremoteInt.h
The above functions requires the following declarations in this file:
#define PANASONIC_HDR_MARK 3502
#define PANASONIC_HDR_SPACE 1750
#define PANASONIC_BIT_MARK 502
#define PANASONIC_ONE_SPACE 1244
#define PANASONIC_ZERO_SPACE 370