Bug? Sensor type not recognized

avalle

Active Member
Licensed User
Longtime User
I am working on PhoneSensors and started from the Sensor sample.
I have tried to add new sensor types to the existing list but I get a compilation error on most of the new sensors I've added:
Error description: Unknown member: type_gravity
Occurred on line: 35
AddSensor(ps.TYPE_GRAVITY, "GRAVITY", True)

This is my code:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
SensorsMap.Initialize
Dim ps As PhoneSensors 'This object is only used to access the type constants.
AddSensor(ps.TYPE_ACCELEROMETER, "ACCELEROMETER", True)
AddSensor(ps.TYPE_GYROSCOPE, "GYROSCOPE", True)
AddSensor(ps.TYPE_LIGHT, "LIGHT", False)
AddSensor(ps.TYPE_MAGNETIC_FIELD, "MAGNETIC", True)
AddSensor(ps.TYPE_ORIENTATION, "ORIENTATION", True)
AddSensor(ps.TYPE_PRESSURE, "PRESSURE", False)
AddSensor(ps.TYPE_PROXIMITY, "PROXIMITY", False)
AddSensor(ps.TYPE_TEMPERATURE, "TEMPERATURE", False)
AddSensor(ps.TYPE_GRAVITY, "GRAVITY", True)
AddSensor(ps.TYPE_LINEAR_ACCELERATION, "LINEAR ACCELERATION", False)
AddSensor(ps.TYPE_RELATIVE_HUMIDITY, "RELATIVE HUMIDITY", False)
AddSensor(ps.TYPE_ROTATION_VECTOR, "ROTATION VECTOR", True)
AddSensor(ps.TYPE_AMBIENT_TEMPERATURE, "AMBIENT TEMPERATURE", False)
End If

The last five calls to AddSensor all give the same kind of error... :-(

Then I have tried to use numeric constants instead of labels (e.g. 9 instead of ps.TYPE_GRAVITY) and that finally works.
So my suspect is that many sensor types are not defined with labels in the library.
To demonstrate this assumption I've noticed that code prediction for the ps object provides a list of labels which is limited to the sensors used by the default sample code (see screenshot).

Thanks for helping understand or solve the issue.

Regards
Andrea

upload_2013-9-12_9-44-54.png
 

avalle

Active Member
Licensed User
Longtime User
That's what I say in my post...
I can do it with constant values of course, but it would be cleaner to update the PhoneSensors object with the missing types from the Android APIs.
 

rthyoung26

Member
Licensed User
Longtime User
There are no such constants in PhoneSensors objects. You can however use the constant value: http://developer.android.com/reference/android/hardware/Sensor.html#TYPE_GRAVITY

For example for gravity it is 9.
The link has some outdated info, at least for the Note 3. The TYPE_AMBIENT_TEMPERATURE should have a value of 13 or (0x0000000d). The newer definitions such as TEMPERATURE and HUMIDITY sensors should be added to the Phone library to bring it more up to date. Many more phones are starting to use them. It took an unnecessarily long time to try and resolve the issue with not being able to read the temperature and humidity sensor on the Note 3.
 
Top