Bastian Rihm
Bastian Rihm

Reputation: 13

IR Hex to Raw IR code conversion

How do I get this Hex IR Code

0000 006d 0022 0003 00a9 00a8 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702 00a9 00a8 0015 0015 0015 0e6e

Into a Raw IR Code like this

int[] irdata = {4600,4350,700,1550,650,1550,650,1600,650,450,650,450,650,450,650,450,700,400,700,1550,650,1550,650,1600,650,450,650,450,650,450,700,450,650,450,650,450,650,1550,700,450,650,450,650,450,650,450,650,450,700,400,650,1600,650,450,650,1550,650,1600,650,1550,650,1550,700,1550,650,1550,650};
    mIR.sendIRPattern(37470, irdata);

Upvotes: 0

Views: 12460

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

The first four numbers there have special meaning:

  • 1 - 0000 indicates raw IR data (you can ignore this value)
  • 2 - frequency
  • 3 - length of the first burst pair sequence
  • 4 - length of the second burst pair sequence

The frequency will be particularly important. LG wants the frequency in Hz, as you might expect, but your Hex code is in terms of the Pronto internal clock. The conversion will be:

carrierfrequency = 1000000/(HexFreq * .241246)

To the rest of the code, after that four digit preamble, LG wants those in μs, where the hex code has them in terms of the frequency. You'll need to convert each of them:

pulselength = 1000000*(HexPulse/carrierfrequency)

I'm not sure whether you want to just send the whole thing, or only the first or second burst sequence. The second is a repeat sequence, used for long button presses and the like. But keep in mind, these are in terms of pairs, not individual numbers. 00a9 00a8 is one burst pair (on time, off time). In this case:

  • first sequence: 00a9 00a8 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702
  • second sequence: 00a9 00a8 0015 0015 0015 0e6e

Sidenote: The distinct pair up front, and very large value at the end are very typical. Makes it easy to eyeball without having to count.

So, to lay out the steps:

array numbers = Split hexcode on space
(ignore numbers[0])
carrierFrequency = 1000000/(numbers[1] * .241246)
codeLength = numbers[2]
repeatCodeLength = numbers[3]
for (number in numbers[4 to end]) {
    convertedToMicrosec = 1000000*(number/carrierFrequency)
    fullSequenceConverted.add(convertedToMicrosec)
}
sequence1EndPoint = 2 * codeLength
sequence2EndPoint = sequence1EndPoint + 2 * repeatCodeLength
firstSequence = fullSequenceConverted from index 0 to sequence1EndPoint
secondSequence = fullSequenceConverted from sequence1EndPoint to sequence2EndPoint

mIR.sendIRPattern(carrierFrequency, firstSequence)

Upvotes: 7

Related Questions