Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IR transmit ConsumerIrManager class after Android 4.4 not working

I built an Android app sometime back to control my Air conditioner, It used to work fine in Android 4.1 (I was using an HTC M8 phone), now after the upgrade to 5.0 lollipop it stopped working I am attaching a sample snippet.

There are no debug errors it says IR was transmitted.

--Air Conditioner brand Samsung (IR codes for on and off included)

PS: I have mocked up the code everything is connected,

//To hold my codes for remote say on, off temp+, temp-, swing etc
public class TransmissionCodes{
    private int[] transmission;
    private int frequency;

    //+getters +setters +constructor
}

//To hold all the TransmissionCodes objects
SparseArray<TransmissionCodes> sequence ;

//power on
sequence.put(0,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));
//power off
sequence.put(1,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));


//IR call in main Activity
findViewById(R.id.button).post(new Runnable() {
    public void run() {
        ConsumerIrManager mCIR = (ConsumerIrManager) getSystemService(android.content.Context.CONSUMER_IR_SERVICE);
        mCIR.transmit(sequence.getFrequency, sequence.getTransmission);
    }
});

Here is a link that was near but couldn't help. Stack Overflow reference

Can someone help me out to put things together, or if I am missing anything??

like image 415
joyBlanks Avatar asked Aug 09 '15 19:08

joyBlanks


2 Answers

Before Android 4.4.3 each element of the pattern is the number of cycles for the on/off pulse.

For Android 4.4.3 and above each element of the pattern if the number of micro seconds for the on/off pulse.

like image 185
Sahar Avr Avatar answered Nov 19 '22 02:11

Sahar Avr


Ok so initially the API supported pulses when I built it now they support duration in microseconds, Since I had my raw data in bits I didn't touch that, instead in my getter I did choose to modify and transmit So the formula stands duration = (1000000 / frequency) * pulse and transmit array of duration not pulse.

//To hold my codes for remote say on, off temp+, temp-, swing etc
public class TransmissionCodes{
    private int[] transmission; //will use to store and send transmssion
    private int frequency;//fed from my properties file
    private String countPattern; // Fed as string from my properties file

    //This modification in the getter did the trick
    private int[] getTransmission() {
        int pulses = 1000000/this.frequency;
        String[] countArray = this.countPattern.split(",");
        int[] anotherFix = new int[countArray.length];
        for (int i = 0; i < countArray.length; i++) {
            anotherFix[i] = Integer.parseInt(countArray[i]) * pulses;
        }
        return anotherFix;
    }
    //+getters +setters +constructor
}

//To hold all the TransmissionCodes objects
SparseArray<TransmissionCodes> sequence ;

//power on
sequence.put(0,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));
//power off
sequence.put(1,     new TransmissionCodes(38000,    "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,16,21,16,21,14,23,53,23,15,22,16,21,54,23,14,23,16,21,16,21,54,23,54,23,53,23,54,23,14,23,54,23,14,23,54,22,54,23,16,21,16,21,14,23,14,23,16,21,16,21,54,23,54,23,15,22,15,22,14,23,14,23,14,23,14,23,53,23,54,23,14,23,14,23,16,21,54,23,14,23,16,21,14,23,16,21,14,23,16,21,14,23,53,23,53,23,54,23,54,23,2500"));


//IR call in main Activity
findViewById(R.id.button).post(new Runnable() {
    public void run() {
        ConsumerIrManager mCIR = (ConsumerIrManager) getSystemService(android.content.Context.CONSUMER_IR_SERVICE);
        mCIR.transmit(sequence.getFrequency, sequence.getTransmission);
    }
});

However I am looking out for the fix that could be applied to HTC, coz this fix only runs for Samsung phone having IR. Didn't check on LG phone as well. But based on my research Samsung and LG should work HTC has a topping on the IR API. looking out

like image 1
joyBlanks Avatar answered Nov 19 '22 02:11

joyBlanks