B4A Library IrdaManager

scsjc

Well-Known Member
Licensed User
Longtime User



one question more:

i have this patern...
0000 0073 0000 000c 0020 0020 0020 0020 0040 0020 0020 0020 0020 0020 0020 0020 0020 0020 0020 0040 0040 0020 0020 0020 0020 0020 0020 0cce

and work perfectly like:
frequency: 38000 (i put manual!!!)
patern: 0020 0020 0020 0020 0040 0020 0020 0020 0020 0020 0020 0020 0020 0020 0020 0040 0040 0020 0020 0020 0020 0020 0020 0cce (making your formula)

but the first 4 hexcodes " 0000 0073 0000 000c " can i convert to 38.000 from any calculate ???

thanks !!!!
 

aleung

Member
Licensed User
Longtime User

The pattern you have is pronto format. You can google search and find how the format descript or this is one of the examples: http://www.remotecentral.com/features/irdisp2.htm
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi,

Thank you for this lib !

I have struggled a little but finally it works like a charm (galaxy S5 + lollipop)

Here are the two lines to respectively trigger the shutter of any EOS Canon DSLR and same thing with 2s delay :

B4X:
Sub BtnShoot_Click
        'IrdaHelper1.Transmit(IrdaHelper1.GetTransmitData2("32898,16,240,16,240"))         'freq, nb pulses before lollipop
        IrdaHelper1.Transmit(IrdaHelper1.GetTransmitData2("32898,352,7330,352,7330"))     'freq, µs for lollipop
End Sub
Sub BtnShoot2s_Click
            IrdaHelper1.Transmit(IrdaHelper1.GetTransmitData2("32898,352,5360,352,5360"))  
End Sub

Canon EOS remote info here : http://www.doc-diy.net/photo/rc-1_hacked/
 

Juan Marrero

Active Member
Licensed User
Longtime User
in case someone need this.
I had problems using this library with my HTC One M8. It didn't work at all. Then I found something interesting on the web.
B4X:
#If JAVA
import android.os.Build;

/*
 * preforms some calculations on the codesets we have in order To make them work with certain models of phone.
 *
 * HTC devices need formula 1
 * Samsungs want formula 2
 *
 * Samsung Pre-4.4.3 want nothing, so just Return the input data
 *
 */
private static int[] string2Dec(int[] irData, int frequency) {
  int formula = shouldEquationRun();

  //Should we run any computations on the irData?
  if (formula != 0) {
  for (int i = 0; i < irData.length; i++) {
  if (formula == 1) {
  irData[i] = irData[i] * (1000000/frequency);//the brackets should avoid an arithmetic overflow
  } else if (formula == 2) {
  irData[i] = (int) Math.ceil(irData[i] * 26.27272727272727); //this is the samsung formula as per http://developer.samsung.com/android/technical-docs/Workaround-to-solve-issues-with-the-ConsumerIrManager-in-Android-version-lower-than-4-4-3-KitKat
  }
  }
  }
  return irData;
}

private static int shouldEquationRun() {
  //Some notes on what Build.X will Return
  //System.out.println(Build.MODEL); //One M8
  //System.out.println(Build.MANUFACTURER); //htc
  //System.out.println(Build.VERSION.SDK_INT); //19

  //Samsung's way of finding out if their OS is too new to work without a formula:
  //int lastIdx = Build.VERSION.RELEASE.lastIndexOf(".");
  //System.out.println(Build.VERSION.RELEASE.substring(lastIdx+1)); //4

  //handle HTC
  if (Build.MANUFACTURER.equalsIgnoreCase("HTC")) {
  return 1;
  }
  //handle Lollipop (Android 5.0.1 == SDK 21) / beyond
  if (Build.VERSION.SDK_INT >= 21) {
  return 1;
  }
  //handle Samsung PRE-Android 5
  if (Build.MANUFACTURER.equalsIgnoreCase("SAMSUNG")) {
  if (Build.VERSION.SDK_INT >= 19) {
  int lastIdx = Build.VERSION.RELEASE.lastIndexOf(".");
  int VERSION_MR = Integer.valueOf(Build.VERSION.RELEASE.substring(lastIdx + 1));
  if (VERSION_MR < 3) {
  // Before version of Android 4.4.2
  //Note: NO formula here, Not even the other one
  return 0;
  } else {
  // Later version of Android 4.4.3
  //run the special samsung formula here
  return 2;
  }
  }
  }
  //If something Else...
  return 0;
}
#End If
There is a formula for HTC (same as Android Version 21+) and a formula for Samsung with version 4.4.3 or later. Previous to these exceptions no formula is needed.
So I translated these functions to b4a.
B4X:
Sub string2Dec(irData() As Int, freq As Int) As Int()
   Dim formula As Int = shouldEquationRun
   
   If formula <> 0 Then
     For i = 0 To irData.Length - 1
       If formula = 1 Then
         irData(i) = irData(i) * (1000000/freq)
       Else
         irData(i) = Ceil(irData(i) * 26.27272727272727)
       End If
     Next
   End If
   
   Return irData
End Sub

Sub shouldEquationRun() As Int
   Dim ph As Phone
   
   If ph.Manufacturer.ToUpperCase = "HTC" Then
     Return  1
   End If
   
   If ph.SdkVersion >= 21 Then
     Return 1
   End If
   
   Return 0
End Sub
I did not include the "If" part of samsung because this code is for a personal app to handle my remotes at home but you can add it. Also you can use JavaObject to access the Java code posted first (#If JAVA).
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Learned string.

Trying to send this Pronto Learned code:
"0000 007e 0022 0000 000a 0046 000a 0046 000a 0046 000a 001e 000a 001e 000a 001e 000a 0046 000a 001e 000a 001e 000a 0046 000a 001e 000a 001e 000a 001e 000a 001e 000a 001e 000a 001e 000a 036a 000a 0046 000a 0046 000a 0046 000a 001e 000a 001e 000a 001e 000a 0046 000a 001e 000a 001e 000a 0046 000a 001e 000a 001e 000a 001e 000a 001e 000a 001e 000a 001e 0009 0000"

And keep getting java.lang.IllegalArgumentException: Non-positive IR slice

All my other learned codes work fine. Not sure what this message is telling me


OK: Update, found this website: http://irdb.tk/convert/ that lets me put in the Pronto Code and it converts it somehow. Put in the pronto code click Get Protocol Information then click on ProntoHex and the hex code there works without any problems (or at least the two I have tried)
 
Last edited:

Acuario

Active Member
Licensed User
Longtime User
I know this is an old thread but it might help anyone looking for an IrdaManager.
The library works correctly on a Xiaomi (mi) Redmi Note 9 Pro - I imagine it will work on any of their phones with IR.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…