拔掉 USB 时 Android 传感器出现问题
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
叹息,我......
重力= event.values;指向它。一个简单的循环,例如:
就可以了
(为什么我总是在向某个地方询问后找到解决方案......)
sigh i'm ....
gravity = event.values; point to it. A simple loop like:
and it's ok
(why i always found the solutions after asking somewhere...)