简体   繁体   English

棒棒糖更新后无法正常工作的HTC ONE M8 IR Blaster

[英]HTC ONE M8 IR Blaster after Lollipop Update not working

I need to use the infrared transmitter on an HTC One device. 我需要在HTC One设备上使用红外发射器。 Before the lolipop update I could do this no problem, but now my code does not work. 在lolipop更新之前我可以做到这一点没有问题,但现在我的代码不起作用。

    ConsumerIrManager mCIR = (ConsumerIrManager)getSystemService(Context.CONSUMER_IR_SERVICE);
    mCIR.transmit(freq, pat);

where freq and pattern are the required values to power on my TV (from the manufacturer) 其中freq和pattern是我的电视所需的值(来自制造商)

I do not get any errors running this code, the only problem is that the infrared transmitter does not light up on HTC one devices. 运行此代码时没有任何错误,唯一的问题是红外发射器没有点亮HTC一个设备。 ( looking at ir blaster through camera ). (通过相机观看ir blaster)。 I dont understand, the exact same code works on galaxy s5 devices. 我不明白,完全相同的代码适用于galaxy s5设备。 I would appreciate any help from someone who can get infrared to work on HTC one devices. 我非常感谢能够让红外线工作在HTC设备上的人的任何帮助。

Yes, this issue seems to have been reported on the official bug tracker for Android. 是的,这个问题似乎已在Android的官方错误跟踪器上报告

I am developing an App which uses the official Consumer IR API introduced in Android 4.4 KitKat. 我正在开发一个使用Android 4.4 KitKat中引入的官方消费者IR API的应用程序。 Since the Lollipop rollouts for popular devices like the HTC One M8 or Samsung Galaxy S5 I am getting many reports from users of said devices that my App is not working on Lollipop. 自从Lollipop推出HTC One M8或三星Galaxy S5等流行设备后,我收到许多来自所述设备的用户的报告,我的应用程序没有在Lollipop上工作。 I do not own a Lollipop device myself, but I borrowed an M8 and did some tests. 我自己没有Lollipop设备,但我借了M8并做了一些测试。

It seems like the method ConsumerIrManager.transmit() is a no-op on Lollipop. 似乎ConsumerIrManager.transmit()方法是Lollipop上的无操作方法。 No matter was pattern is given, it returns instantly. 无论是给出模式,它都会立即返回。

Before discovering that Galaxy S5 users have the same problem, I contacted the HTC support on that matter and was told to contact the Google support. 在发现Galaxy S5用户遇到同样的问题之前,我就此问题联系了HTC支持,并被告知要联系Google支持。

It would seem S5 devices are getting the same issue as well, although it's hard to tell because developers are getting contradictory reports from S5 owners. 似乎S5设备也遇到了同样的问题,虽然很难说,因为开发人员从S5所有者那里获得了相互矛盾的报道。

Here is an HTC-only fix that someone found for his M7 after it stopped working because of a Lollipop update. 这是一个仅限HTC的修复程序 ,由于Lollipop更新,有人在M7停止工作后找到了它。 He basically reverted to an earlier version of the IR HTC API before they had switched to the official Google's api. 在他们切换到官方Google的api之前,他基本上恢复了早期版本的IR HTC API

Otherwise, you should star the issue on the bug tracker, and perhaps point your own users to do the same. 否则,您应该在错误跟踪器上加注问题,并指出您自己的用户也可以这样做。 The more people star this issue, the higher priority it will be given. 人们对此问题的关注度越高,优先级就越高。

I've just fixed this problem, for Samsung devices: 我刚刚为三星设备解决了这个问题:

Before Android 4.4.3 each element of the pattern is the number of cycles for the on/off pulse. 在Android 4.4.3之前,模式的每个元素都是开/关脉冲的周期数。

For Android 4.4.3 and above each element of the pattern if the number of micro seconds for the on/off pulse. 对于Android 4.4.3及以上版本的每个元素,如果开/关脉冲的微秒数。

Example: 例:

To transmit a wave 0.5s on, 0.5 off, 0.5 on, at 38000Hz 发射0.5s,0.5 off,0.5 on,38000Hz的波

Before Android 4.4.3 your pattern would be [19000, 190000, 19000] - The 19000 comes from 0.5s*38000Hz 在Android 4.4.3之前,你的模式是[19000,190000,19000] - 19000来自0.5s * 38000Hz

For Android 4.4.3+ your pattern would be [500000, 500000, 500000] - that is you convert each time to microseconds(us). 对于Android 4.4.3+,您的模式将是[500000,500000,500000] - 即您每次转换为微秒(我们)。

I'm going to blame Google on this one: Before 4.4.3 was released their API said to use the number of cycles, after 4.4.3 the changed it to say to use microseconds(us), Samsung simply followed the API thus breaking our apps. 我要责怪谷歌这个:在4.4.3发布之前,他们的API表示要使用周期数,4.4.3之后更改为使用微秒(我们),三星只是按照API这样打破我们的应用。

*Edit: UPDATED version of this fix can be found here: https://stackoverflow.com/a/28934938/1042362 *编辑:此修复程序的更新版本可在此处找到: https//stackoverflow.com/a/28934938/1042362

Give this a shot: 试一试:

/*
 * 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; 
            } 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;
}

/*
 * This method figures out if we should be running the equation in string2dec,
 * which is based on the type of device. Some need it to run in order to function, some need it NOT to run
 *
 * HTC needs it on (HTC One M8)
 * Samsung needs occasionally a special formula, depending on the version
 * Android 5.0+ need it on. 
 * Other devices DO NOT need anything special.
 */
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;
}

The stock remote has been stopped since end of April. 库存遥控器自4月底以来一直停止。 Download the Peel app which is branded version used on M9. 下载剥离应用程序,它是M9上使用的品牌版本。

My experience on HTC One M7: 1) KitKat 4.4.3 the ConsumerIRManager code worked fine, passing an array of microseconds. 我在HTC One M7上的经验:1)KitKat 4.4.3 ConsumerIRManager代码工作正常,传递了一个微秒的数组。

2) Updated to Lolipop 5.0.2 and there was no transmission at all from the IR Led, the no-op problem. 2)更新到Lolipop 5.0.2并且IR Led没有传输,即无操作问题。 I refactored my code to use the HTC API, which requires the waveform in "clock ticks" instead of direct microseconds. 我重构了我的代码以使用HTC API,它需要“时钟滴答”而不是直接微秒的波形。 All is working now. 现在一切正常。

It seems we cannot use the ConsumerIRManager on HTC One except for very specific versions, ie 4.4.3. 似乎我们不能在HTC One上使用ConsumerIRManager,除非是非常具体的版本,即4.4.3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM