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).