B4A Library IrdaManager

The IrdaManager library is exclusively for use with Samsung devices.
It exposes the hidden Samsung IrdaManager system servcie, enabling you to use the device's IR transmitter to send IR codes.

For more info take a look at this thread: http://www.b4x.com/forum/basic4android-updates-questions/29902-what-hardware-does-b4a-support.html

IrdaManager
Version: 0.02
  • IrdaManager
    Methods:
    • Hex2Dec (HexData As String, Separator As String) As String
      Converts a String of Hex IR codes into a String of comma separated decimal codes suitable for use with WriteIrSend.
      Separator denotes the separator character used in the HexData input.
    • Initialize As Boolean
      Initialize the IrdaManager.
      Returns True if successfully initialized, otherwise False.
      If initialization fails the B4A LastException property will contain the related Exception.
    • IsInitialized As Boolean
      Returns whether or not the IrdaManager is initialized.
    • WriteIrSend (DecimalData As String) As Boolean
      Sends Data using the IrdaManager.
      Returns True if successfully sent, otherwise False.
      If send fails the B4A LastException property will contain the related Exception.

Here's a simple example showage usage syntax:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim IrdaManager1 As IrdaManager
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If IrdaManager1.Initialize Then
      Log("IrdaManager successfully initialized")
      Dim HexData As String="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"
      Dim DecData As String=IrdaManager1.Hex2Dec(HexData, " ")
      Log("DecData: "&DecData)
      
      If IrdaManager1.WriteIrSend(DecData) Then
         Log("WriteIrSend succeeded")
      Else
         Log("WriteIrSend failed: "&LastException)
      End If
   Else
      Log("Failed to initialize the IrdaManager: "&LastException)
   End If
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

As you can see the WriteIrSend (DecimalData As String) As Boolean method accepts a String and this String should be a decimal IR code sequence.
If you get a code from somewhere that is a hexadecimal IR sequence then you will need to use the Hex2Dec (HexData As String, Separator As String) As String method to convert the hex sequence to a decimal sequence suitable for use with WriteIrSend.

The library files, example project and library source code are attached.

Martin.
 

Attachments

  • IrdaManager_0.02.zip
    14.7 KB · Views: 642

ivan.tellez

Active Member
Licensed User
Longtime User
Wow, simply Amazing.


Sorry the delay, but I reinstaled 4.2.2 on a Galaxy S4 to test, then 4.4.2. Works in Both.


On 4.2.2 uses Samsung's IrdaManager and on 4.4.2 uses the ConsumerIrManager.

The only problem is that the permission is not added. You have to use the manifest editor and add a line:

B4X:
<uses-permission android:name="android.permission.TRANSMIT_IR"/>


The grat advantage is that when compiled fot API level 17, a single Binary works on API 17, 18 and 19 :D
 

warwound

Expert
Licensed User
Longtime User
@ivan.tellez

That's odd, the ConsumerIrManager class has that permission added:

B4X:
@Permissions(values={
   "android.permission.TRANSMIT_IR"
})
@ShortName("ConsumerIrManager")

Are you saying that on API 19+ this permission is not automatically added to the manifest?

On API less than 19 where the ConsumerIrManager is not used the permission should not be added but on API 19+ it should be added.

Martin.
 

ivan.tellez

Active Member
Licensed User
Longtime User
@ivan.tellez

That's odd, the ConsumerIrManager class has that permission added:


Thats right. Its odd.

Tested compiling targeting API 17, 18 and 19 with the same result: The permission is not automatically added to the manifest. So, it works on API 17 and 18, but when using on API 19, an error is raised on the phone:

B4X:
An error has cocurred in sub:
java.lang.SecurityException:
Requieres TRANSMIT_IR permission
Continue?

And if you compile the app targeting API 17 and add manualy the permission in the manifest editor, the same app works on API 17, 18 and 19.

If that is the cost of having a single app working on diferent API levels, its Ok by me.

Ivan.
 

warwound

Expert
Licensed User
Longtime User
In the b4a IDE under the menu option 'Configure paths' what version of android.jar have you selected?
If that's a version prior to 19 then maybe that explains the missing permission - BUT if that's the case then surely the project would fail to even compile?

I'll look into it later and see what i can establish.

Martin.
 

ivan.tellez

Active Member
Licensed User
Longtime User
If that's a version prior to 19 then maybe that explains the missing permission

Hi, well, I tested this before.


I compiled the app with:

B4X:
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19"/>

And in the paths I used:

B4X:
C:\Android\android-sdk\platforms\android-19\android.jar


And still got the permission missing and not working on API 17


So, Compiled with:

Manifest:
B4X:
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.TRANSMIT_IR"/>

Paths
B4X:
C:\Android\android-sdk\platforms\android-17\android.jar


And works on API 17 and API 19



As said, its Odd o_O



IVAN
 

ivan.tellez

Active Member
Licensed User
Longtime User
Hi Martin,

Do you think its posible to integrate the LG sdk to the IRdaManager?

Its the LG QRemote SDK, Android API 16, Revision 3
http://developer.lge.com/resource/mobile/RetrieveSDKList.dev?categoryId=CTANRS030201###


They had a function:

B4X:
public int sendIRPattern (int carrierFrequency, int[] pattern)

Which they stated: "The usage of sendIRPattern() is identical to ConsumerIrManager.transmit() of Android." in this doc:

http://developer.lge.com/MOBILE_HEL...Developing/Developing/Sending+Raw+IR+Data.htm


Please let me know what you think.


Thanks
 

warwound

Expert
Licensed User
Longtime User
Which they stated: "The usage of sendIRPattern() is identical to ConsumerIrManager.transmit() of Android."

If the method is identical then why is there a need to wrap the LG library - it simply duplicates the existing IrdaManager library functionality...?
 

ivan.tellez

Active Member
Licensed User
Longtime User
If the method is identical then why is there a need to wrap the LG library - it simply duplicates the existing IrdaManager library functionality...?

Its Identical just in the format of the parameters used. But, the IR blaster in the LG devices dont work with the standar ConsumerIrManager. Their hardware works only whit their API.
 

nortonir

Member
Licensed User
Longtime User
Hello
I test all of IRDA b4a code and it dont work with galaxy note 4 , why?

- thanks
 

nortonir

Member
Licensed User
Longtime User
hi
plz see the picture.
i test all of sample code and test the IRDA MANAGER code with a learning device , the return code for IRDA MANAGER is not same of in my code.
why?
Device.jpg
 

ivan.tellez

Active Member
Licensed User
Longtime User
hi
plz see the picture.
i test all of sample code and test the IRDA MANAGER code with a learning device , the return code for IRDA MANAGER is not same of in my code.
why?



Hi nortonir, after a little research, I found that the problem is with the Android version, this lib will not work on Android 4.4.3 and on. Your device is 4.4.4, so, it will not work. Also happens with Android Lollipop.

There is a little work around:

http://stackoverflow.com/questions/28794899/ir-emitter-and-android-5-0
http://stackoverflow.com/questions/20244337/consumerirmanager-api-19

I hope warwound will find some spare time to include this fix in his lib.
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello, i'm try the IrdaHelper, but don't work in samsung s5 - lollipop....
before lollipop, work with irdamanager

some one have a solution working in lollipop ????
 

aleung

Member
Licensed User
Longtime User
Hello, i'm try the IrdaHelper, but don't work in samsung s5 - lollipop....
before lollipop, work with irdamanager

some one have a solution working in lollipop ????

In the irdaHelper, the pattern array was defined as # of pulses. For lollipop, it need to be the timing in terms of microseconds.
 

scsjc

Well-Known Member
Licensed User
Longtime User
In the irdaHelper, the pattern array was defined as # of pulses. For lollipop, it need to be the timing in terms of microseconds.

ok... and some body fix this problem ?
can i send a pattern array in timing microseconds??? how i calculate???
 
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
hi i'm try this code, to calculate pulses and send in lolipop s5, but don't work, some one can help me ?
thanks.

B4X:
#Region  Project Attributes
    #ApplicationLabel: IrdaHelper
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Dim button1,button2 As Button
    Dim IrdaHelper1 As IrdaHelper
    Dim sf As StringFunctions   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    button1.Initialize("button1")
    button2.Initialize("button2")
    Activity.AddView(button1,0,0,100%x,100dip)
    Activity.AddView(button2,0,150dip,100%x,100dip)
   
    Dim Initialized As Boolean=IrdaHelper1.Initialize
    If Initialized Then
        Log("Able to transmit IR codes")
       
        Select IrdaHelper1.GetIrdaHelperState
            Case IrdaHelper1.STATE_CONSUMER_IR_MANAGER
                Log("The ConsumerIrManager is initialized")
                '    you can get the instance of ConsumerIrManager using IrdaHelper1.GetConsumerIrManager
            Case IrdaHelper1.STATE_IRDA_MANAGER
                Log("The Samsung IrdaManager is initialized")
                '    you can get the instance of IrdaManager using IrdaHelper1.GetIrdaManager
            Case IrdaHelper1.STATE_NOT_INITIALIZED
                Log("Neither ConsumerIrManager or IrdaManager are initialized")
                '    this condition should not be met as IrdaHelper1.Initialize has returned True
        End Select
       
    Else
        Log("Unable to transmit IR codes")
        Log(IrdaHelper1.GetIrdaHelperState)
        ToastMessageShow("no compatible",True)
        ExitApplication
    End If
   
End Sub

Sub Button1_Click
    Log("send test")
    fir4lolipop(38028,Array As Int(169,168,21,63,21,63,21,63,21,21,21,21,21,21,21,21,21,21,21,63,21,63,21,63,21,21,21,21,21,21,21,21,21,21,21,21,21,63,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,63,21,63,21,63,21,63,21,63,21,63,21,1794,169,168,21,21,21,3694))
End Sub

Sub Button2_Click
    Log("send test")
    fir4lolipop(38226,Array As Int(343,171,21,22,21,22,21,22,21,65,21,65,21,65,21,22,21,22,21,65,21,65,21,65,21,22,21,22,21,22,21,65,21,65,21,22,21,65,21,65,21,65,21,22,21,22,21,22,21,22,21,65,21,22,21,22,21,22,21,65,21,65,21,65,21,65,21,4892))
End Sub

Sub fir4lolipop(frecuencie As Int, pattern() As Int)
    'calculate pulses
    Dim pulses As Float
    pulses= 1000000/frecuencie

    Dim valor As Int
    Dim list1 As List
    list1.Initialize2(pattern)

    For i=0 To list1.Size -1
        valor=(list1.Get(i))*pulses
        list1.Set(i,Bit.ToHexString(valor) )
    Next

    Dim stringhex As String = sf.ListToString(list1,False,False)
    ToastMessageShow("send..." & stringhex,False)
    IrdaHelper1.Transmit(IrdaHelper1.GetTransmitData3(stringhex, " "))
End Sub



Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

aleung

Member
Licensed User
Longtime User
I tried this one works:

B4X:
Sub Globals
 'These global variables will be redeclared each time the activity is created.
 'These variables can only be accessed from this module.
 Dim button1,button2 As Button
  Dim IrdaHelper1 As IrdaHelper
End Sub
Sub Activity_Create(FirstTime As Boolean)
 'Do not forget to load the layout file created with the visual designer. For example:
 'Activity.LoadLayout("Layout1")
  button1.Initialize("button1")
  button2.Initialize("button2")
  Activity.AddView(button1,0,0,100%x,100dip)
  Activity.AddView(button2,0,150dip,100%x,100dip)
 IrdaHelper1.Initialize
 
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
  Log("send test")
 Dim frequency As Int
 Dim Pattern() As Int
 Dim IrObject As TransmitData
 frequency=38400
 'Pattern already in microseconds
 Pattern=Array As Int(9000, 4500, 500,500, 500,1300,500,500, 500, 500, 500,4000)
 IrObject=IrdaHelper1.GetTransmitData(frequency, Pattern)
 IrdaHelper1.Transmit(IrObject)
 
 
End Sub
Sub Button2_Click
  Log("send test")
 Dim frequency As Int
 Dim Pattern1() As Int
 Dim IrObject As TransmitData
 frequency=38400
 'Pattern in pulse, calculate to convert into microseconds
 Pattern1=Array As Int(346,173,20,20,20,50,20,20,20,20,20,154) 
 Dim Pattern2(Pattern1.Length) As Int
 
 
 For i=0 To Pattern1.Length-1
 Dim i2 As Int
 i2=Round(1000000*Pattern1(i)/frequency) 
 Pattern2(i)=i2
 Next
 IrObject=IrdaHelper1.GetTransmitData(frequency, Pattern2)
 IrdaHelper1.Transmit(IrObject)
 
 
End Sub
 

scsjc

Well-Known Member
Licensed User
Longtime User
I tried this one works:

B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim button1,button2 As Button
  Dim IrdaHelper1 As IrdaHelper
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
  button1.Initialize("button1")
  button2.Initialize("button2")
  Activity.AddView(button1,0,0,100%x,100dip)
  Activity.AddView(button2,0,150dip,100%x,100dip)
IrdaHelper1.Initialize

End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
  Log("send test")
Dim frequency As Int
Dim Pattern() As Int
Dim IrObject As TransmitData
frequency=38400
'Pattern already in microseconds
Pattern=Array As Int(9000, 4500, 500,500, 500,1300,500,500, 500, 500, 500,4000)
IrObject=IrdaHelper1.GetTransmitData(frequency, Pattern)
IrdaHelper1.Transmit(IrObject)


End Sub
Sub Button2_Click
  Log("send test")
Dim frequency As Int
Dim Pattern1() As Int
Dim IrObject As TransmitData
frequency=38400
'Pattern in pulse, calculate to convert into microseconds
Pattern1=Array As Int(346,173,20,20,20,50,20,20,20,20,20,154)
Dim Pattern2(Pattern1.Length) As Int


For i=0 To Pattern1.Length-1
Dim i2 As Int
i2=Round(1000000*Pattern1(i)/frequency)
Pattern2(i)=i2
Next
IrObject=IrdaHelper1.GetTransmitData(frequency, Pattern2)
IrdaHelper1.Transmit(IrObject)


End Sub


Thanks!!!!... work perfect.
 
Top