Sensor in native code NDK R5

925 views
Skip to first unread message

Ratamovic

unread,
Mar 29, 2011, 3:17:38 PM3/29/11
to android-ndk
Hi all,


I am currently writing an Android application using NativeActivity
without any Java code which relies on sensors. So I need to access
sensors from native code.

But while looking for a way to get device orientation, I got surprised
to discover that only the following devices where "available" (extract
from sensor.h):
enum {
ASENSOR_TYPE_ACCELEROMETER = 1,
ASENSOR_TYPE_MAGNETIC_FIELD = 2,
ASENSOR_TYPE_GYROSCOPE = 4,
ASENSOR_TYPE_LIGHT = 5,
ASENSOR_TYPE_PROXIMITY = 8
};

After some test, I found that I got in fact the following sensors:
- BMA150 3-axis Accelerometer / Bosh / id 1
- AK8973 3-axis Magnetic field sensor / Asahi Kasei / id 2
- AK8973 Orientation sensor / Asahi Kasei / id 3
- CM3602 Light sensor / Capella Microsystems / id 5
- CM3602 Proximity sensor / Capella Microsystems / id 8
- Gravity Sensor / Google Inc. / id 9
- Linear Acceleration Sensor / Google Inc. / id 10
- Rotation Vector Sensor / Google Inc. / id 11


After some research, I found that that surprisingly, new (I guess
"virtual") sensors added in Gingerbread (the "Google Inc." ones, 9, 10
and 11) are not in the enum! So my question is why so? Shouldn't we
use them? Or expect their absence on a Gingerbread device?

My second question is about Orientation sensor which is now deprecated
(which is why 3 is not in the enum). It is stated that in SensorEvent
javadoc that "This sensor type exists for legacy reasons, please use
getRotationMatrix() in conjunction with remapCoordinateSystem() and
getOrientation() to compute these values instead.". Is there a
particular reason why we don't have these methods in NDK R5? Should we
expect them later or can we rely on the new sensors like Rotation
Vector Sensor 11?


Thanks in advance.

narkis

unread,
Oct 22, 2012, 5:00:11 PM10/22/12
to andro...@googlegroups.com
Could these "google inc." sensors, id9, 10 and 11 be part of their solution for "sensor fusion"?

http://www.youtube.com/watch?v=C7JQ7Rpwn2k

would you be able to describe how to read these "virtual" values?

Thanks

Bram Stolk

unread,
Jul 16, 2014, 2:28:49 AM7/16/14
to andro...@googlegroups.com


On Tuesday, March 29, 2011 12:17:38 PM UTC-7, Ratamovic wrote:
Hi all,


I am currently writing an Android application using NativeActivity
without any Java code which relies on sensors. So I need to access
sensors from native code.

But while looking for a way to get device orientation, I got surprised
to discover that only the following devices where "available" (extract
from sensor.h):
enum {
    ASENSOR_TYPE_ACCELEROMETER      = 1,
    ASENSOR_TYPE_MAGNETIC_FIELD     = 2,
    ASENSOR_TYPE_GYROSCOPE          = 4,
    ASENSOR_TYPE_LIGHT              = 5,
    ASENSOR_TYPE_PROXIMITY          = 8
};

After some test, I found that I got in fact the following sensors:
- BMA150 3-axis Accelerometer / Bosh / id 1
- AK8973 3-axis Magnetic field sensor / Asahi Kasei / id 2
- AK8973 Orientation sensor / Asahi Kasei / id 3
- CM3602 Light sensor / Capella Microsystems / id 5
- CM3602 Proximity sensor / Capella Microsystems / id 8
- Gravity Sensor / Google Inc. / id 9
- Linear Acceleration Sensor / Google Inc. / id 10
- Rotation Vector Sensor / Google Inc. / id 11

Interesting!

I was stuck on the missing ASENSOR_TYPE_GRAVITY enum value.

I'll try using a hardcoded '11' id instead, and see if it will work.

  Bram

Bram Stolk

unread,
Jul 16, 2014, 2:54:49 AM7/16/14
to andro...@googlegroups.com
Hmm... never mind. This list is device specific of course.
On my S5 device, I get:

I/biplane (27723): 0) MPU6500 Acceleration Sensor [Invensense]
I/biplane (27723): 1) AK09911C Magnetic field Sensor [Asahi Kasei Microdevices]
I/biplane (27723): 2) AK09911C Magnetic Sensor UnCalibrated [Asahi Kasei Microdevices]
I/biplane (27723): 3) MPU6500 Gyroscope Sensor [Invensense]
I/biplane (27723): 4) MPU6500 Uncalibrated Gyroscope Sensor [Invensense]
I/biplane (27723): 5) Barometer Sensor [BOSCH]
I/biplane (27723): 6) TMG399X Proximity Sensor [AMS, Inc.]
I/biplane (27723): 7) TMG399X RGB Sensor [AMS, Inc.]
I/biplane (27723): 8) MPL Rotation Vector [Invensense]
I/biplane (27723): 9) MPL Game Rotation Vector [Invensense]
I/biplane (27723): 10) SAMSUNG Step Detector Sensor [Samsung Inc.]
I/biplane (27723): 11) SAMSUNG Step Counter Sensor [Samsung Inc.]
I/biplane (27723): 12) SAMSUNG Significant Motion Sensor [Samsung Inc.]
I/biplane (27723): 13) MAX86900 [MAXIM]
I/biplane (27723): 14) Screen Orientation Sensor [Samsung Electronics]
I/biplane (27723): 15) HRM Sensor [Samsung Electronics]
I/biplane (27723): 16) Orientation Sensor [Samsung Electronics]
I/biplane (27723): 17) Gravity Sensor [Samsung Electronics]
I/biplane (27723): 18) Linear Acceleration Sensor [Samsung Electronics]



--
You received this message because you are subscribed to a topic in the Google Groups "android-ndk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-ndk/fF9psEShFio/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/d/optout.



--

“Programming today is a race between software engineers striving to build bigger and better idiot- proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” (R Cook).
Reply all
Reply to author
Forward
0 new messages