Don't understand this logic in IR code

Hello

I am (unsuccessfully) trying to pull apart an IR code learning routine for my project.

The original code is the from the <IRremote.h> library, and I am using the IRecord example.

This part here is to do with the non repeating of a particular IR code

void sendCode(int repeat) {
  if (codeType == NEC) {
    if (repeat) {
      irsend.sendNEC(REPEAT, codeLen);
      Serial.println("Sent NEC repeat");
    } 
    else {
      irsend.sendNEC(codeValue, codeLen);
      Serial.print("Sent NEC ");
      Serial.println(codeValue, HEX);
    }
  }

How does the (repeat) part of this work? The value repeat is declared as an int, which seems odd to me.
I thought it was simply a toggle for whether to repeat the code or not.

I have had real issues unstitching it all, as I just CANNOT get my head around pointers (->). I have Googled that subject to death. I know what they do, I just cannot unstitch it from this demo code for my uses.

Saying that, I have managed to decode the NEC, Sony and other mainstream IR code and break them down into 4x storable bytes for my storage loop.
I can them re-assemble them back into the original IR code for transmission

I did that by:

  Serial.print("IR data: "); Serial.println(results.value, HEX);
  delay(200);

  IRcodeA = ((results.value >> 0) & 0xFF);                                                           
  IRcodeC = ((results.value >> 16) & 0xFF);
  IRcodeD = ((results.value >> 24) & 0xFF);
  IRbits = (results.bits);

and to reassemble:

  ReassembledData = ((IRcodeA << 0) & 0xFF) + ((IRcodeB << 8) & 0xFF00) + ((IRcodeC << 16) & 0xFF0000) + ((IRcodeD << 24) & 0xFF000000);        // Reassemble the bytes into a HEX code
  
  Serial.print("The decimal value of IRcodeA is: "); Serial.println(IRcodeA);
  Serial.print("The decimal value of IRcodeB is: "); Serial.println(IRcodeB);
  Serial.print("The decimal value of IRcodeC is: "); Serial.println(IRcodeC);
  Serial.print("The decimal value of IRcodeD is: "); Serial.println(IRcodeD);

  Serial.print("The re-assembled HEX value from the decoded bytes is: "); Serial.println(ReassembledData, HEX);
  Serial.print("IR code length = ");Serial.println(results.bits);

The idea then being, I could send them like this:

irsend.sendSony(ReassembledData, IRbits);

Look OK?

The only problem I have got, is I can only store 5 bytes in a single 'storage event' in my learning loop.
For a known code/manufacturer, that is fine (4x bytes of data and the length).

But, the whole thing falls flat when the code is unknown, as the data is then read as a raw value, and I have no idea how to store that huge amount of data.
Worry about that later!

repeat is used as a flag so it could have been a boolean, but byte or int will also work. If true it sends the standard REPEAT code (0xFFFFFF) instead of the original code. Where's the problem?

Other than that you lost me. There are no pointers in any of the snippets you posted so what's to understand?

Steve

How does the (repeat) part of this work? The value repeat is declared as an int, which seems odd to me. I thought it was simply a toggle for whether to repeat the code or not.

looks like the argument determines if the REPEAT code is sent. a flag, not a toggle.

looks like codeType and codeValue are globals variables.

i think a more generic approach would be to have a function that sends a value passed as an argument and let the code calling that function determine if it is REPEAT or something else

The only problem I have got, is I can only store 5 bytes in a single 'storage event' in my learning loop. For a known code/manufacturer, that is fine (4x bytes of data and the length).

assuming you don't understand structures, couldn't you have two arrays: one an array of 64-bit longs that holds the 4 byte data and a second, an array of bytes that holds the manufacturer. the corresponding array index associates the values from the 2 arrays.

Thanks.
I thought it could be a boolean.

As for the code.... I didn't want to post the whole IRecord code, as that seemed a bit excessive and not my code anyway.

phoneystark2020:
Thanks.
I thought it could be a boolean.

As for the code.... I didn't want to post the whole IRecord code, as that seemed a bit excessive and not my code anyway.

bool/boolean is a late addition to C/C++ so many older programmers (or people who learned from older programmers) continue to use 'int' when they mean 'boolean'. The 'if' statement converts the expression to boolean in any case.