9

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??

Community
  • 1
  • 1
joyBlanks
  • 6,419
  • 1
  • 22
  • 47
  • I had the same problem with an app of mine. It seems like the calculation changed on Lollipop. I'll try to find what I did to fix it. – Mauker Aug 09 '15 at 21:31

2 Answers2

1

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.

Sahar Avr
  • 131
  • 8
  • Can you provide a solution to convert this line `sequence.put(0, new TransmissionCodes(38000, "123,339,23,54,23,14,23,16,21,14,21,16,21,14,23,1 ...` to above said solution. A snippet maybe – joyBlanks Aug 17 '15 at 09:11
  • To transmit a wave `0.5s on, 0.5 off, 0.5 on, at 38000Hz` Before Android 4.4.3 your pattern would be `[19000, 190000, 19000]` - The 19000 comes from `0.5s*38000Hz` For Android 4.4.3+ your pattern would be `[500000, 500000, 500000]` - that is you convert each time to microseconds(us). – Sahar Avr Aug 17 '15 at 11:39
  • But I used to send like the above signal 123,339,23,54 not 50000,50000 50000. – joyBlanks Aug 17 '15 at 11:50
  • So convert it to microseconds. 123 would become 123,000,000 and so on. – Sahar Avr Aug 17 '15 at 12:04
  • Didn't work bro. I tried multiplying numbers didn't work *100000 – joyBlanks Aug 18 '15 at 21:58
  • @joyBlanks Did you manage to make it work? If so, can you show how? – Sahar Avr Aug 24 '15 at 10:37
  • check the post I have added as an answer. And a ton thanks for taking interest. Appreciate it. – joyBlanks Aug 24 '15 at 12:39
1

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

joyBlanks
  • 6,419
  • 1
  • 22
  • 47