Android touch sensor 3?

I am working with Android sensors. <sensor.h>

It has:

enum {
    ASENSOR_TYPE_ACCELEROMETER      = 1,
    ASENSOR_TYPE_MAGNETIC_FIELD     = 2,
    ASENSOR_TYPE_GYROSCOPE          = 4,
    ASENSOR_TYPE_LIGHT              = 5,
    ASENSOR_TYPE_PROXIMITY          = 8
};

      

When I reset the sensors from ASensorManager_getSensorList

on HTC Evo I get:

SensorList: BMA150 3-axis Accelerometer (Bosh), 1
SensorList: AK8973 3-axis Magnetic field sensor (Asahi Kasei), 2
SensorList: AK8973 Orientation sensor (Asahi Kasei), 3
SensorList: CM3602 Proximity sensor (Capella Microsystems), 8
SensorList: CM3602 Light sensor (Capella Microsystems), 5

      

When I cross enums

in the list, sensor type 3 appears - orientation.

Question . Will the orientation sensor always be sensor type 3? Or will it change depending on the manufacturer?


Edit . And here is the dump from the ASUS TF-101 tablet:

SensorList: MPL rotation vector (Invensense), 11
SensorList: MPL linear accel (Invensense), 10
SensorList: MPL gravity (Invensense), 9
SensorList: MPL Gyro (Invensense), 4
SensorList: MPL accel (Invensense), 1
SensorList: MPL magnetic field (Invensense), 2
SensorList: MPL Orientation (Invensense), 3
SensorList: Lite-On al3000a Ambient Light Sensor (Lite-On), 5

      

Orientation is again 3, but there are some additional sensors.


Edit . And here is the dump from the Zeki TBQG 1084B tablet:

SensorList: STK831x accelerometer (Sensortek) 1 10000 1.000000

      

No orientation (and only one sensor is cheap, I think its for gaming).

+3


source to share


2 answers


The enum is for the types of sensor devices that can have and each type must always have the same numeric value across the platform. Therefore, regardless of the type of device or vendor, if it received a gyroscope, it should always be stated as ASENSOR_TYPE_GYROSCOPE

, which is ultimately equal 4

. If you see the gyroscope differently on the device, then this is a bug, that is, on low-level drivers on this device and will most likely be fixed with a subsequent firmware update or so.

These values ​​must remain the same on every device, or your application may not actually function. It would be a huge pain to develop for sensors if the types are not unified, since executable binaries operate on numeric values, not ENUMs / define etc. And the main thing is to have ENUMs - to use them instead of final values ​​to make your code more readable. It's clearer what code does when it sees ie

if( sensor == ASENSOR_TYPE_GYROSCOPE )

      



than

if( sensor == 4 ) 

      

Regarding orientation sensor and missing ENUM input - this sensor is deprecated in API8 and now you are advised to use magnetic field sensor and accelerometer to get equivalent functionality ( see implementation example ), so this is most likely the reason why it disappeared from ENUM.

+2


source


It looks like the NDK headers are just out of date. The Java docs have a [current] list of sensors and their values ​​of type sensor class .



I assume the two lists have been consistent in the past.

+1


source







All Articles