> Hello all,
>
> I'm using a HTC Magic in order to develop an application which makes
> use of the accelerometer. Following the indications from tutorials and
> the docs, this is a snapshot of the code I'm using:
>
> /* Next code register the ACCELEROMETER SENSOR*/
>   SensorManager mSensorManager = (SensorManager) getSystemService
> (Context.SENSOR_SERVICE);
>
>   List<Sensor> listSensors = mSensorManager.getSensorList
> (Sensor.TYPE_ACCELEROMETER);
>   Sensor acelerometerSensor = listSensors.get(0);
>   mSensorManager.registerListener(this, acelerometerSensor,
> SensorManager.SENSOR_DELAY_UI);
>
> /*OnSensorChanged Method, here I receive the wrong values*/
> public void onSensorChanged(SensorEvent event) {
>               // TODO Auto-generated method stub
>               synchronized (this) {
>                         switch(event.sensor.getType()) {
>                                     case Sensor.TYPE_ACCELEROMETER:
>                                          for (int i=0 ; i<3 ; i++) {
>                                                 mAccelerometerValues[i] =
> event.values[i];
>                                          }
>                        if ( mAccelerometerValues[0]  >= 1)
>                                   //selectAndChange() send some HTTP
> Petitions and updates the screen
>                                selectAndChange(0, null,"",3);
>                        else if ( mAccelerometerValues[0]  <= -1)
>
>                                      [...]
>
>                               default:
>                      }
>
>              }
> }
>
> I'm nevermind getting values that don't match with the accelerometer.
> With the phone standing over my table, with no movement, I get values
> like:
>
> [0,0,15]
> [0,6,8]
> [0,0,0]
>
> And sometimes the expected value:
> [0,9.8,0]
>
> I guess my SensorManager is kind of mixing all the other sensors, but
> I do not guess where the problem could be. I have been checking other
> codes, and in all of them the estructure is aproximately the same.
>
> Any clues of what could I try?

Rather than:

Sensor acelerometerSensor = listSensors.get(0);  
mSensorManager.registerListener(this, acelerometerSensor,
SensorManager.SENSOR_DELAY_UI);

try:

mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_UI);

This may not help, but it is safer code than just assuming get(0) will
give you the best accelerometer.

Also, have you checked around your table for a black hole, neutron star,
or any other strong gravitational source that might affect your readings?
:-)

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to