Access Android sensors via NDK

旧街凉风 提交于 2019-12-08 23:11:23

问题


I need read about 100 samples per second off the accelerometer on a Android, and at a fixed sample rate. The current sensormanager does or offers neither.

I've read Need to read android sensors really fast

He seems to have access to the driver code which made his life easier.

I am curious if anyone has been able to do something like this through the NDK w/o that type of knowledge.

Thanks in advance!


回答1:


I have taken a look at sensor.h, and the API looks very promising; however, a little howto on how to deal with the ASensorEventQueue and ASensorEventQueue_hasEvents and so forth would be -extremely- useful.

Ha! Update:

This looks a code example for what you want to do.

http://developer.android.com/reference/android/app/NativeActivity.html




回答2:


Since Android SDK version 9 (for Android > 2.2) it seems to be possible to use the sensors via NDK.

See the STABLE_APIS.html file included in the docs. (Search for "sensor.h"). A mirror of that file is here.




回答3:


Dianne Hackborn says this is not possible.

http://groups.google.com/group/android-ndk/browse_thread/thread/f299413e610c7e93?hl=en




回答4:


Example from google https://github.com/googlesamples/android-ndk/tree/master/sensor-graph.Their code allow you controll SENSOR_REFRESH_RATE_HZ for the accelerometer.Written on c++ and connected to java code through the NDK.




回答5:


Sensors can be read reading directly from system "files" like:

/sys/class/sensors/light_sensor/lux or /sys/class/sensors/light_sensor/raw_data

I wonder if there is a more direct way to do it, reading directly from the chip.

Like something in /dev/...



来源:https://stackoverflow.com/questions/4200119/access-android-sensors-via-ndk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!