0

I'm trying to make a simple glassware app that displays the accelerometer data on the screen. The code I am posting works on my Android phone, but when I use it on google glass, only the Y axis seems to work correctly (looking up and down).

When I say the Y axis, it's actually the third array entry from the SensorEvent event.values[] array (instead of the second array entry - see code).

All TextViews DO display a float value similar to how they appear on my android phone, but they just don't change by much (around .1 to .2) when moving my head.

public class SensorActivity extends Activity implements SensorEventListener {

  SensorManager mSensorManager;
   mAccel;

  TextView tvx, tvy, tvz;

  @Override
  protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    setContentView(R.layout.main);
    tvx = (TextView) findViewById(R.id.tvx2);
    tvy = (TextView) findViewById(R.id.tvy2);
    tvz = (TextView) findViewById(R.id.tvz2);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccel = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensorManager.registerListener(this, mAccel, SensorManager.SENSOR_DELAY_NORMAL);

  }

  @Override
  protected void onPause(){
    super.onPause();
    mSensorManager.unregisterListener(this);
  }

  @Override
  protected void onResume(){
    super.onResume();
    mSensorManager.registerListener(this, mAccel, SensorManager.SENSOR_DELAY_NORMAL);
  }

  @Override
  public void onAccuracyChanged(Sensor sensor, int accuracy) {


  }


  @Override
  public void onSensorChanged(SensorEvent event) {

    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];

    tvx.setText(Float.toString(x));
    tvy.setText(Float.toString(y));
    tvz.setText(Float.toString(z));

  }

}

The Glass Documentation pretty much points to the Android documentation, so I am assuming they should be the same. Any insight would be greatly appreciated.

**** NEW UPDATE ****

Now, all of a sudden. The Y-axis is reading the Y-direction (and the Z-axis is too). Main problem with that is that the Y-axis reading starts at value "9" and goes to "0" in either direction (no negative direction) so determining where the user is looking is an issue. I am aware I could call the Z-axis the Y-axis, but that would just be masking a different issue. It turns out that the X-axis is registering head tilt and NOT head turn (which is not in accordance with the documentation). I haven't found any documentation pertaining to calibrating the accelerometer (if that's even possible).

MWiesner
  • 8,868
  • 11
  • 36
  • 70
James B
  • 447
  • 3
  • 15
  • "When I say the Y axis, it's actually the third array entry from the SensorEvent event.values[] array" Huh? Why not call it z then? Also nulling out `onAccuracyChanged` seems like you could be silently losing something important, especially when the main problem is that the returned values have accuracy limitations. – msw Jul 18 '14 at 04:03
  • The point about the Y/Z axis was more of a reference to let you know that it's not responding the same as it does in android. Any idea on what to put in the onAccuracyChanged() method to help. The other two axes fluctuate intermittently and inconsistently, so determining if they are even working is difficult. – James B Jul 20 '14 at 20:01
  • I'm not familiar with that API so I was just making guesses about what might be a trouble spot. Sorry. – msw Jul 20 '14 at 20:08

0 Answers0