拔掉 USB 时 Android 传感器出现问题

发布于 2024-10-03 20:54:06 字数 717 浏览 0 评论 0原文

我的 HTC 愿望遇到了一个奇怪的问题。

我目前使用加速度计和地磁传感器测试一些 opengl 的东西。

似乎他们两个有时(相当多)返回完全相同的值。

我在 onSensorChanged() 上得到了这个

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        gravity = event.values;
    } 
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        geomagnetic = event.values;
    }

,我不知道为什么,但是当我拔掉 USB(到计算机)时,情况变得更糟,(我使用这些值围绕天空图等对象旋转相机,当我拔掉插头时,看起来这些值大约每 2 秒 1 次是正确的 ~)。

有时(插入 USB 并查看 logcat)它工作得很好,并且永远不会从两个传感器获得相同的值。

这不是我的设备,其他程序(如天空地图)运行良好,但我不明白我做错了什么。 我从来没有混淆重力和地磁这两个数组,它们只是全局的并与 SensorManager.getRotationMatrix(R,gravity,geotropic) 一起使用。

我想知道我是否只是没有太快地获取值,但即使我在侦听器中定义了 SENSOR_DELAY_UI,这也是同样的故事。

i got a kind of weird issue with my HTC desire.

I currently test some opengl things using the accelerometer and geomagnetic sensors.

it seem that the two of them return sometimes (quite a few) the exact same values .

i got this on my onSensorChanged()

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        gravity = event.values;
    } 
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        geomagnetic = event.values;
    }

and i don't know why but when i unplug the usb (to computer) it's gettin worse , (i use thoses values to rotate a camera around an object like sky map, and when i unplug , it's look like the values are correct about 1 one time per 2 seconds ~).

and sometimes (with usb plugged in AND looking at the logcat) it work juste fine and never get the same values from the two sensors.

it's not my device , other program like sky map runs fine , but i don't get what i'm doing wrong.
i never mixed up the two arrays gravity and geomagnetic , they juste global and used with SensorManager.getRotationMatrix(R,gravity,geomagnetic).

i'm wondering if i just don't get values too fast , but even if i define SENSOR_DELAY_UI in the listener , it's the same story.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2024-10-10 20:54:06

叹息,我......

重力= event.values;指向它。一个简单的循环,例如:

for (int i=0 ; i<3 ; i++) {
            gravity[i] = event.values[i];
}

就可以了
(为什么我总是在向某个地方询问后找到解决方案......)

sigh i'm ....

gravity = event.values; point to it. A simple loop like:

for (int i=0 ; i<3 ; i++) {
            gravity[i] = event.values[i];
}

and it's ok
(why i always found the solutions after asking somewhere...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文