LIR format for the KontroLIR?

For discussions about our KontroLIR - 100% Arduino compatible IR remote control
Post Reply
van0014
Posts: 3
Joined: Sun Dec 10, 2017 3:39 am

LIR format for the KontroLIR?

Post by van0014 »

Hi, i've been using LearnIR and KontroLIR, and wanted to use a format other than RAW for storing codes on the remote with. The LearnIR application is a reduced version of AnalysIR, and doesn't tell me what kind of code is detected. Whether it's NEC, RC5 or any other kind. What it does give is the LIR format, as the most readily useable kind. So i've begun making an array to store codes in LIR format, with or without the carrier. These could be stored in a char array. And while I could try to write some code for this, sending LIR codes, someone might have done this before.

Also, i'm confused about the compression format. It seems to be that compressed sequences start from the list of single bytes, where the double bytes end. Not sure if every remote code has a compressed sequence. The F nibble isn't always near the start of the sequence, so it mustn't be used to mark the start of a sequence. Just the start of a repetition. It's tricky to store these codes in formats other than a string.

Maybe as an unsigned long, leading zeroes can be used to check the size: 0x00xx would be used for sequences without an F. And any data read from after the start of the sequence gets automatically treated as sequence information, rather than data from the pulse pair list

Edit: I've attempted to write a function. It hasn't been tested, and most likely has mistakes. The function takes an unsigned long array and length. 0x00xx is used in place of ASCII spaces, so if the first two nibbles are zero, it's part of the pulse sequence or compressed sequence

Code: Select all

void KIR_sendLIR(const unsigned long* lircode_char, unsigned int arlen)
{
  KIR_sigTime = micros();  // start rolling timer for signal for better accuracy
  unsigned long lirdata[arlen];

  for (unsigned int ik=0; ik<arlen; ik++){
    lirdata[ik] = pgm_read_word_near(&lircode_char[ik]);
  }

  //unsigned long lirdata[] = {
  //  0x0026, 0x228C, 0x11B8, 0x0206, 0x0280, 0x021C, 0x0650, 0x0228, 0x0228, 0x0214, 0xA680, 0x228C, 0x08E4, 0x0001, 0x0011, 0x0022, 0x0021, 0x00F2, 0x0041, 0x0011, 0x0021, 0x0012, 0x0012, 0x0021, 0x0012, 0x0021, 0x0021, 0x0032, 0x0023, 0x0045, 0x001F};

    //arlen = sizeof(lirdata) / sizeof(unsigned long);
  KIRsend.enableIROut(lirdata[0]);

  unsigned int ivar = 1;
  unsigned int seqst = 0;

  for (unsigned int ii=1; ii<arlen; ii++){
    //Check if data is a pulse pair, or part of the sequence
    if (lirdata[ii] <= 0xFF){
      if (seqst == 0){seqst = ii;}
    }
  }

  unsigned int fmark = 0;
  unsigned int pointer = 0;
  unsigned int repeat = 0;
  bool mark = true;
  byte seqdata = 0;
  unsigned long pulsedata = 0;

  for (unsigned int ix=seqst; ix<arlen; ix++){
      for (unsigned int ij=0; ij<2; ij++){
        //Read a nibble
        switch(ij){
            case 0:
            seqdata = (lirdata[ix] & 0xF0) >> 4;
            break;
            case 1:
            seqdata = lirdata[ix] & 0xF;
            break;
          }

        //Send normal mark or space
          if (seqdata == 0xF){
              fmark = 1;
              pointer = 0;
              repeat = 0;

              //If byte = $Fx
              if (((lirdata[ix] & 0xF0) >> 4) == 0xF){
                pointer = lirdata[ix] & 0xF;
                if (ix + 1 < arlen){
                repeat = (lirdata[ix + 1] & 0xF0) >> 4;
                }
                else
                {
                  fmark = 2;
                }
              }
              else
              {
                //if byte = $xF
                if ((ix + 1) < arlen){
                pointer = (lirdata[ix + 1] & 0xF0) >> 4;
                repeat = lirdata[ix + 1] & 0xF;
                }
                else
                {
                  fmark = 2;
                }
              }

              //Pulse repeat
              pulsedata = lirdata[1 + (pointer * 2) + ij];

              for (unsigned int il=0; il<repeat; il++){
                pulsedata = lirdata[1 + (pointer * 2)];
                KIR_mark(pulsedata + ((pulsedata % 2) * 65536));
                if (fmark != 2){
                  pulsedata = lirdata[1 + (pointer * 2) + 1];
                KIR_space(pulsedata + ((pulsedata % 2) * 65536));}
              }
            }

        if (fmark == 0){
          pulsedata = lirdata[1 + (seqdata * 2) + ij];

        switch (mark){
            case false:
            KIR_space(pulsedata + ((pulsedata % 2) * 65536));
            break;
            case true:
            KIR_mark(pulsedata + ((pulsedata % 2) * 65536));
            break;
          }

          mark = !mark;
        }

        fmark = 0;
    }
  }
}
Post Reply