Format of results.rawbuf from Ken Shirriff's IR library?

Hello!
I found an example code for storing and immitating IR remote signals from a book (http://www.arduinoevilgenius.com/) using Ken Shirriff’s IRremote library (http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html):

// Project 28 - IR Remote
#include <EEPROM.h>
#include <IRremote.h>

int irRxPin = 9;

int f = 38; // 40, 36, 38

IRrecv irrecv(irRxPin);
IRsend irsend;

decode_results results;
int codeLength = 0; 
int currentCode = 0;

void setup()
{
  Serial.begin(9600);
  Serial.println("0-9 to set code memory, s - to send");
  irrecv.enableIRIn(); 
  setCodeMemory(0);
}

void loop()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch >= '0' && ch <= '9')
    {
      setCodeMemory(ch - '0');
    }
    else if (ch == 's')
    {
      sendIR();
    }
  }
  if (irrecv.decode(&results)) 
  {
    storeCode();
    irrecv.resume();
  }
}

void setCodeMemory(int x) 
{
  currentCode = x;
  Serial.print("Set current code memory to: ");
  Serial.println(currentCode);
  irrecv.resume();
}

void storeCode()
{
   // write the code to EEPROM, first byte is length
   int startIndex = currentCode * (RAWBUF + 1);
   int len = results.rawlen - 1;
   EEPROM.write(startIndex, (unsigned byte)len);
   for (int i = 0; i < len; i++)
   {
     if (results.rawbuf[i] > 255)
     {
       EEPROM.write(startIndex + i + 1, 255); 
     }
     else
     {
      EEPROM.write(startIndex + i + 1, results.rawbuf[i]); 
     }
   }
   Serial.print("Saved code, length: ");
   Serial.println(len);
}

void sendIR()
{
  // construct a buffer from the saved data in EEPROM and send it
  int startIndex = currentCode * (RAWBUF + 1);
  int len = EEPROM.read(startIndex);
  unsigned int code[RAWBUF];
  for (int i = 0; i < len; i++) 
  {
     int pulseLen = EEPROM.read(startIndex + i + 2);
     if (i % 2) 
     {
        code[i] = pulseLen * USECPERTICK + MARK_EXCESS;
     } 
     else 
     {
        code[i] = pulseLen * USECPERTICK - MARK_EXCESS;
     }
  }
  irsend.sendRaw(code, len, f);
  Serial.print("Sent code length: ");
  Serial.println(len);
}

They use results.rawbuf at line 62, which is an array of signals. For clarification, what format is the array in? By that I mean something like this:

usec on, usec off,
usec on, usec off,
usec on, usec off,

So element 0 is HIGH pulse in usec, and element 1 is LOW pulse in usec? Please tell me if I’m correct or not. Also, is there an online reference to this library’s methods and constants, etc.?
Thanks!

For clarification, what format is the array in?

From IRremote.h:

class decode_results {
public:
  int decode_type; // NEC, SONY, RC5, UNKNOWN
  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.
};

So, rawbuf is an unsigned int array.

So, rawbuf is an unsigned int array.

Yes, I know that. What I mean is that is the array organized in a way like the usec on/off thing I wrote in my first post?
P.S. It's a volatile unsigned int array (or volatile word). I found that out when trying to pass that array to function as an argument / parameter. They are two different things, because it generated a compiler error

What I mean is that is the array organized in a way like the usec on/off thing

Why don't you look at the source code? See how rawbuf is used in functions like decodeSony or in the ISR that populates the array.

Yes, they values are time on/time off.

You can see a great tutorial about IR remote control here: http://diarioelectronicohoy.com/arduino

You can see a great tutorial about IR remote control here: http://diarioelectronicohoy.com/arduino

Except that I can’t find it!

Would this be the correct way to print the code in this format:

usec on, usec off,
usec on, usec off,
...

Function:

void printCode(volatile word* code, byte length){
  for(byte i = 0; i < length; i++){
    if (i & 1) Serial << code[i] << ", ";
    else if (!(i & 1) && i < length - 1) Serial << code[i] << "," << endl;
    else if (!(i & 1) && i == length - 1) Serial << code[i] << endl;
  }
}

Result (after pressing “1” button on a Sony remote):

39299,
48, 12,
11, 13,
12, 11,
13, 11,
12, 13,
11, 12,
13, 11,
13, 11,
12, 11,
24, 13,
14, 10,
25, 11,
23, 12,
12, 12,
24, 11,
13, 12,
23, 13,
23, 13,
24, 12,
23, 12,
25,

dkl65:
Would this be the correct way to print the code in this format:nd it!

usec on, usec off,

usec on, usec off,

I don’t think so. From my experiments with remote controls, they usually send out pulses in increments of about 50 microseconds (40 to 70ish). I suspect that each of those numbers is in tens of microseconds.
That information is posted on the page you linked to. Did you even read it?

The header file for the library contains a reference to all of the methods of the library.

I don't see anything anywhere about how to print the code in my format. However, on the page I linked to, it says that the first measurement is the gap / space before the measurement starts, and the last measurement is the final mark. Is the first gap part of the IR code? How can there be a "gap" before the IR detector gives any signal? Am I actually printing it in my format? Does results.rawlen return the number of elements in results.rawbuf?

WizenedEE:
The header file for the library contains a reference to all of the methods of the library.

Not exactly.

dkl65:
I don't see anything anywhere about how to print the code in my format.

It tells you what format they are in. It's up to you to translate that to how you want to see it.

However, on the page I linked to, it says that the first measurement is the gap / space before the measurement starts, and the last measurement is the final mark. Is the first gap part of the IR code? How can there be a "gap" before the IR detector gives any signal?

It's my understanding that the gap is the time between signals. So if you pressed a button and then three seconds later pressed another, the gap would be 3 seconds.

Am I actually printing it in my format?

Don't understand. Your code is printing it how you told it to print it. What's "Your format" but how your code does it?

Does results.rawlen return the number of elements in results.rawbuf?

Yes?

WizenedEE:
The header file for the library contains a reference to all of the methods of the library.

Not exactly.

Uh, what? Yes, it does. If it's not in the header file, it essentially can't be called. If it's in the header file, it can be called. Are you saying that he doesn't provide sufficient documentation? He provides quite a lot, and more than most.

WizenedEE:
If it's not in the header file, it essentially can't be called.

I thought that you meant that the "reference" is a description of the functions and how to use them. What you were talking about I call "function definitions".

WizenedEE:
What's "Your format" but how your code does it?

My format is:
usec on, usec off,
usec on, usec off,
...

dkl65:
I thought that you meant that the “reference” is a description of the functions and how to use them. What you were talking about I call “function definitions”.

You probably shouldn’t call them that because a definition is generally

int foo() {
  return 3;
}
bar = 4;

and a declaration is

int foo();
int bar;

Those terms are pretty standard:
http://www.cprogramming.com/declare_vs_define.html