List of IR patterns/Codes and Device codes vs Device names

2.4k Views Asked by At

I want to make an Android app 'Universal Remote Control', using Infrared. I am able to find many IR codes in XML format from here: https://github.com/probonopd/lirc-remotes. Here is an example of IR code for a Key:

<code name="KEY_PLAY" codeno="0x0000000000000059">
      <decoding protocol="Sony12" device="17" subdevice="-1" obc="50" hex0="76" hex1="77" hex2="-1" hex3="-1" misc="no repeat" error=""/>
      <ccf>0000 006d 000d 0000 005c 0016 0017 0016 002e 0016 0017 0016 0017 0016 002e 0016 002e 0016 0017 0016 002e 0016 0017 0016 0017 0016 0017 0016 002e 03d4</ccf>
    </code>

Now I want to get target Device Type, that I want to display in my App, from these XML files. Device Type can be TV or DVD Player or AC, etc. I know the Device Code can be fetched, but how to get Device Types against the Device Codes?

Another question, is there any Android/Java code that is generic for all the above XML files and it just return me the IR pattern that I need to transmitt?

1

There are 1 best solutions below

0
On
  1. Unfortunately there is no simple mapping between the "device code" and device type. Actually the device code in the XML relates to the IR protocol. Although some makers may use this field to map to their device type, most makers don't. Even the maker uses the device code to map to the actual device type, the mapping is not universal.

  2. You can extract the carrier frequency and pattern from the ccf field which is in the Pronto Hex format. (See Pronto's IR Code Format) The conversion is pretty straightforward.

Here is a sample class for your reference. (in C#, but could be easily converted into Java.)

public class ProntoFormat
{
     private int mFrequency = 0;
     private List<int> mSequence1 = new List<int>();
     private List<int> mSequence2 = new List<int>();

        public int CarrierFrequency { get { return mFrequency; } }

        public Boolean LoadData(int[] data)
        {
            // reset
            mFrequency = 0;
            mSequence1.Clear();
            mSequence2.Clear();

            // check length
            if (null == data || data.Length < 6)
            {
                return false;
            }

            // check preamble: must be 0 for raw data, so far we only handle raw data
            if (data[0] != 0)
            {
                return false;
            }

            // check frequency
            if (data[1] != 0)
            {
                mFrequency = (int)(1000000 / ((double)data[1] * 0.241246));

                if (mFrequency > 65000) // so we set the ceiling to 65KHz
                {
                    return false;
                }
            }
            else
            {
                return false;
            }

            // check burst pair sequence 1 count
            int sequenceLen1 = data[2] * 2;

            // check burst pair sequency 2 count
            int sequenceLen2 = data[3] * 2;

            if (data.Length < 4 + sequenceLen1 + sequenceLen2)
            {
                return false;
            }


            for (int i = 0; i < sequenceLen1; i++)
            {
                mSequence1.Add(data[4 + i]);
            }

            for (int i = 0; i < sequenceLen2; i++)
            {
                mSequence2.Add(data[4 + sequenceLen1 + i]);
            }

            return true;
        }

        public int[] GetWaveform()
        {
            if (CarrierFrequency == 0 || 
                (mSequence1.Count == 0 && mSequence2.Count == 0))
            {
                return new int[0];
            }

            // carrier cycle time
            int cycleTime = 1000000 / CarrierFrequency;

            int[] waveform = new int[mSequence1.Count + mSequence2.Count];
            for (int i = 0; i < mSequence1.Count; i++)
            {
                waveform[i] = mSequence1[i] * cycleTime;
            }
            for (int i = 0; i < mSequence2.Count; i++)
            {
                waveform[i + mSequence1.Count] = mSequence2[i] * cycleTime;
            }

            return waveform;
        }
    }