Importing an IR protocol in IRremote library

Hi fellow arduinians,

I need to build a remote IR controller for my TV.

I've searched and founded for the protocol:
http://lirc.sourceforge.net/remotes/samsung/AA59-00382A

I included it in the IRremote library, loaded in arduino aaaand it doesn't work.
I know there a billions of reason why it doesn't and I'd like to narrow the options.
Below there's my implementation of the protocol I found, could you please let me know if it is correct?
In particular I have no idea of what "toggle_bit_mask" means, nor what the gap is, since there is no minimum repeat value indicated.
Thanks in advance:

send function :

void IRsend::sendSamsung(unsigned long data, int nbits,int repeat){
  enableIROut(40);
  if (repeat == 0) {
  mark(SAMSUNG_HDR_MARK);
  space(SAMSUNG_HDR_SPACE);
  }
  //Invio il pre_data 0xE0E0 del protocollo http://lirc.sourceforge.net/remotes/samsung/AA59-00382A
  unsigned long pre_data = 0xE0E0;
  pre_data <<= 16;
  for (int i = 0; i < 16; i++) {
    if (pre_data & TOPBIT) {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ONE_SPACE);
    } 
    else {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ZERO_SPACE);
    }
    pre_data <<= 1;
  }
  //Ora trasmetto il mio segnale
  data = data << (32-nbits);
  for (int i = 0; i < 16; i++) {
    if (data & TOPBIT) {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ONE_SPACE);
    } 
    else {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ZERO_SPACE);
    }
    data <<= 1;
  }
  //aggiungo il trail
  mark(SAMSUNG_PTRAIL);
}

mark-space times :

#define SAMSUNG_HDR_MARK 4764
#define SAMSUNG_HDR_SPACE 4703
#define SAMSUNG_ONE_MARK 573 
#define SAMSUNG_ONE_SPACE 1663
#define SAMSUNG_ZERO_SPACE 534
#define SAMSUNG_PTRAIL 556
#define SAMSUNG_GAP 48962

and finally the sketch :

#include <IRremote.h>

IRsend irsend;

void setup()
{
  Serial.begin(9600);
  pinMode(13,OUTPUT);
}

void loop() {
  digitalWrite(13,HIGH);
  for(int i=0;i<3;i++) {
  irsend.sendSamsung(0x20DF, 16,i); // Sony TV power code
  delay(45);
  }
  digitalWrite(13,LOW);
  delay(500);
}
  int pre_data = 0xE0E0;
  pre_data <<= 16;

If you take a 16-bit integer and shift it left 16 bits the results will be 0. Probably not what you wanted.

thanks, that has been modified, now is "unsigned long" instead of "int"

Ok, I managed to get this things work.
I post here the solution in case someone had to do the same thing:

It was wrong to not send the header when repeating the signal, so the code now is :

void IRsend::sendSamsung(unsigned long data, int nbits,int repeat){
  enableIROut(38);

  mark(SAMSUNG_HDR_MARK);
  space(SAMSUNG_HDR_SPACE);
  //Invio il pre_data 0xE0E0 del protocollo http://lirc.sourceforge.net/remotes/samsung/AA59-00382A
  unsigned long pre_data = 0xE0E0;
  pre_data <<= 16;
  for (int i = 0; i < 16; i++) {
    if (pre_data & TOPBIT) {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ONE_SPACE);
    } 
    else {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ZERO_SPACE);
    }
    pre_data <<= 1;
  }
  //Ora trasmetto il mio segnale
  data = data << (32-nbits);
  for (int i = 0; i < 16; i++) {
    if (data & TOPBIT) {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ONE_SPACE);
    } 
    else {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ZERO_SPACE);
    }
    data <<= 1;
  }
  //aggiungo il trail
  mark(SAMSUNG_PTRAIL);
  space(48962);  //gap
}

note that i moved the gap here from the sketch.

It was a pointbreak find this legend to read lirc files : Technical Details
And I suggest also reading the blog of the library's creator, just google IRremote library and you should find him.

If I may help someone with this kind of project let me know, and thanks to johnwasser for finding that mistake

I would like to try this out on my Samsung. I created a sketch from this code and get a compilation error. "no void IRsend::sendSamsung(unsigned int, int ,int ) member function declared in iRsend". Is there a special place that function should reside?

samsungIRRemote.ino (1.43 KB)

philG:
I would like to try this out on my Samsung. I created a sketch from this code and get a compilation error. "no void IRsend::sendSamsung(unsigned int, int ,int ) member function declared in iRsend". Is there a special place that function should reside?

You have to add it to the IRremote library, in both IRremote.h and IRremote.cpp. You might as well add it to keywords.txt, too.

Oh, right. I have it compiling now. I think the code assumes that the LED will be driven directly off the pin. I plan to use an NPN driver so I will have to invert the output. I'm not sure is that can be done easily in the PWM setup. Thanks for the help John.

OK, this works fine. I was not sure why there was a loop around the send command since there is a repeat count parameter. I added defines for all the useful commands and built a sequence of commands that turns on the TV and sets the source to the DTV STB.

I am wondering why I can't find the hex codes for the DTV RC65 remote anywhere. Is there some legal issue?

samsungIRRemote.ino (2.66 KB)