Bug? Incorrect values for IrReceive.RawBuffer in B4R Infrared Lib

miker2069

Active Member
Licensed User
Longtime User
I'm using version 1.12 of the IR Library for esp8266. Here's my code below.

When I get the Result object as the result of decode event , the number of elements for RawBuffer are correct (I get 68 consistently which is correct) however the values are wrong. I'm comparing with my working Arduino decode sketch (which also gives me 68), which gives me the correct rawbuf values (I know they're correct b/c I can record and play back the raw codes in my arduino sketch successfully). The values from the sketch are like 4550, 4574,4500, etc.... What I am getting back from B4R is something like 12,10,12,10,12,40. It feels like there's a type conversion issue at play here.

Basically I am trying to port my IR record and blaster to B4R. In my for each loop below I figure an explicit cast from Object to string should be okay. I also tried "For Each code as Ulong...." with the same results. Any thoughts?


B4X:
Private Sub ir_Decoded (Result As IrResult)
    Log("result: ", Result.DecodeType, ", ", Result.Value)
   
    Dim length As Int = Result.RawBuffer.Length
    Dim tmpstr As String
   
    Log("Result raw buffer length:", length)
    Log("result: ", Result.DecodeType, ", ", Result.Value, " size ",Result.RawBuffer.Length)
   
     For Each code As Object In Result.RawBuffer
        tmpstr = code
        Log("code: ", code)
    Next
   
    ir_recv.Disable
   
End Sub
 

miker2069

Active Member
Licensed User
Longtime User
My bad...I was incorrect, it looks like it's working properly. I forgot to port over the logic from my sketch that converts the ticks (which is what the rawbuf values are) to microseconds. Essentially this c code:
B4X:
    // To store raw codes:
    // Drop first value (gap)
    // Convert from ticks to microseconds
    // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
    for (int i = 1; i <= codeLen; i++) {
      Sprint("rawbuf: ");Sprint(i);Sprint("  "); Sprint(results.rawbuf[i]);
    
      if (i % 2) {
        // Mark
        rawCodes[i - 1] = results.rawbuf[i]*USECPERTICK - MARK_EXCESS;
        //Sprint(" m");
      }
      else {
        // Space
        rawCodes[i - 1] = results.rawbuf[i]*USECPERTICK + MARK_EXCESS;
        //Sprint(" s");
      }

      //print concat the raw code
      if (i < codeLen) {
        strResult.concat(rawCodes[i - 1]); strResult.concat(",");
      }
      else {
        strResult.concat(rawCodes[i - 1]);
      }
       //Sprintln(rawCodes[i - 1], HEX);
    }

Ultimately I based my original Arudino sketch on examples like this.

Might be worth leaving this thread in case some one else makes the same mistake .


The
USECPERTICK and MARK_EXCESS are from the IRremoteESP8266.h header file and are defined below for esp8266 (you will need to get the correct values for your board if you intend on performing the same conversion).

B4X:
#define USECPERTICK 50  // microseconds per clock interrupt tick
#define RAWBUF 100 // Length of raw duration buffer

// Marks tend to be 100us too long, and spaces 100us too short
// when received due to sensor lag.
#define MARK_EXCESS 100



So it won't be to hard to turn it into a B4R sub....
 
Top