Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Android sensors via NDK

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!

like image 952
MQS Avatar asked Nov 16 '10 23:11

MQS


People also ask

How can I see all sensors in Android?

Open the app and tap the Diagnostic button on the home screen. Tap the individual icons to run diagnostic tests on the battery, SIM card, sensors, touch screen, flashlight, camera, microphone, speaker, Bluetooth, Wi-Fi, and more. Alternatively, tap the Test all button to perform all the tests one after the other.

How do I find my sensor information?

There are two ways to obtain sensor information: Queried sampling to immediately read all enabled digital and analog input pins. Automatic sampling to transmit the sensor data periodically or whenever a digital pin changes.

What is Android NDK used for?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.


3 Answers

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

like image 109
Madmartigan Avatar answered Oct 12 '22 04:10

Madmartigan


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.

like image 20
HRJ Avatar answered Oct 12 '22 05:10

HRJ


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.

like image 33
Mihuilk Avatar answered Oct 12 '22 04:10

Mihuilk