Then the solution is quite simple:

House n @ MIT used the deprecated constant
(@deprecated) SensorManager.SENSOR_ACCELEROMETER = (const) 2
with the new API, while jdesbonnet used
Sensor.TYPE_ACCELEROMETER = (const) 1

The constant value used above (=2) corresponds to
Sensor.TYPE_MAGNETIC_FIELD = (const) 2 in the new API, so indeed House
n @ MIT saw compass data, as I suspected.

Case solved :-)

Peli
www.openintents.org

On Jun 30, 4:15 pm, jdesbonnet <[email protected]> wrote:
> I checked with my Vodafone branded HTC Magic (using Android 1.5 API).
> Using SensorEventListener and the following code to register the
> listener:
>
> Sensor accSensor = mSensorManager.getSensorList
> (Sensor.TYPE_ACCELEROMETER).get(0);
> mSensorManager.registerListener(accSensorListener, accSensor,
> SENSOR_DELAY);
>
> I tried values for SENSOR_DELAY: SensorManager.SENSOR_DELAY_FASTEST,
> SensorManager.SENSOR_DELAY_GAME and
> SensorManager.SENSOR_DELAY_NORMAL...  all give me g vectors with
> magnitude ~ 9.8.
>
> Joe.
>
> On Jun 30, 2:17 pm, Peli <[email protected]> wrote:
>
> > > x: 12.5625      y: 20.8125      z: -16.4375
>
> > Unfortunately, I didn't have a chance yet to try out sensors through
> > the SDK 1.5 API on a real device yet, but these numbers look like they
> > could be from a compass (in microTesla).
>
> > Did you try rotating the device around its axis, while lying flat on
> > the table? Do the x and y values change? If they do, then you have
> > compass data (because accelerometer is not sensitive to that
> > rotation). If you don't then you have really weird accelerometer
> > data...
>
> > Peliwww.openintents.org
>
> > On Jun 29, 3:58 pm, "House n @ MIT" <[email protected]> wrote:
>
> > > Hello,
> > > I've been doing some testing on the accelerometer, specifically with
> > > the old SensorListener and new SensorEventListener versions available
> > > as of Cupcake.
>
> > > Using SensorListener, I've been getting normal acceleration values as
> > > expected according to the documentation - around 9.8 on the axis in
> > > line with gravity when sitting still. When I upgraded the code to
> > > SensorEventListener, that number jumped to around 30, which is not
> > > consistent with the documentation. I've tried sampling at different
> > > rates, but generally I've been using game mode, since that's the rate
> > > I ultimately intend to use.
>
> > > I'd be interested to hear if anyone has seen this behavior, has any
> > > ideas about it, or sees an issue with the code below. Give it a test
> > > run yourself. It might be relevant to note that the
> > > SensorEvent.accuracy is SENSOR_STATUS_ACCURACY_HIGH.
>
> > > When I run this code with the phone sitting flat on a table, screen,
> > > up, I get values like these:
>
> > > x: 12.5625      y: 20.8125      z: -16.4375
>
> > > ////////////////////////////////////////////////////////////////////
>
> > > package edu.accel;
>
> > > import java.io.File;
> > > import java.io.FileNotFoundException;
> > > import java.io.FileOutputStream;
> > > import java.io.PrintWriter;
> > > import java.util.List;
>
> > > import android.app.Activity;
> > > import android.content.Context;
> > > import android.hardware.Sensor;
> > > import android.hardware.SensorEvent;
> > > import android.hardware.SensorEventListener;
> > > import android.hardware.SensorManager;
> > > import android.os.Bundle;
>
> > > public class AccelTest extends Activity {
>
> > >         private SensorManager mSensorManager;
>
> > >     @Override
> > >     public void onCreate(Bundle savedInstanceState) {
> > >         super.onCreate(savedInstanceState);
> > >         setContentView(R.layout.main);
>
> > >                 // Set up the accelerometer reading
> > >       mSensorManager = (SensorManager)getSystemService
> > > (Context.SENSOR_SERVICE);
> > >       // Get the list of all sensors, and find the accelerometer
> > > within
> > >       List<Sensor> sensorList = mSensorManager.getSensorList
> > > (SensorManager.SENSOR_ACCELEROMETER);
>
> > >       mSensorManager.registerListener(mSensorListener,
> > >                   sensorList.get(0),
> > >                   SensorManager.SENSOR_DELAY_UI);
>
> > >     }
>
> > >         //Accelerometer
> > >   private final SensorEventListener mSensorListener = new
> > > SensorEventListener() {
>
> > >         private PrintWriter mCurrentFile;
>
> > >         boolean never = true;
> > >         String comma = new String(",");
>
> > >         public void runOnce()
> > >         {
> > >                 //Creating a file to print the data into
>
> > >         String nameStr = new String("/sdcard/10 second trials.xls");
> > >                 File outputFile = new File(nameStr);
> > >                 mCurrentFile = null;
> > >                 try {
> > >                         mCurrentFile = new PrintWriter(new 
> > > FileOutputStream(outputFile));
> > >                 } catch (FileNotFoundException e) {
> > >                         // TODO Auto-generated catch block
> > >                         e.printStackTrace();
> > >                 }
>
> > >         }
>
> > >                 @Override
> > >                 public void onAccuracyChanged(Sensor sensor, int 
> > > accuracy) {
> > >                         // TODO Auto-generated method stub
>
> > >                 }
>
> > >                 @Override
> > >                 public void onSensorChanged(SensorEvent event) {
>
> > >                         if (never)
> > >                 {
> > >                         never = false;
> > >                         runOnce();
> > >                 }
> > >                         StringBuffer buff = new StringBuffer();
> > >                         buff.append(String.valueOf(event.values[0]));
> > >                         buff.append(comma);
> > >                         buff.append(String.valueOf(event.values[1]));
> > >                         buff.append(comma);
> > >                         buff.append(String.valueOf(event.values[2]));
> > >                         mCurrentFile.println(buff.toString());
> > >                 }
> > >   };
>
> > > }
--~--~---------~--~----~------------~-------~--~----~
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