He tenido problemas con esto durante demasiado tiempo. Este código debería generar dx, dy, dz para el acelerómetro y un total acumulado de dx. También debería generar acimut, tono y balanceo.Uso de getRotationMatrix y getOrientation en Android 2.1
I've used the information given here, pero en vano.
Este código no da salida correctamente en tono, azimut o balanceo. Da como resultado 0.0, -0.0, -0.0 para las últimas tres textviews, respectivamente.
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
accelerometerValues = event.values.clone();
case Sensor.TYPE_MAGNETIC_FIELD:
geomagneticMatrix = event.values.clone();
sensorReady = true;
break;
default:
break;
}
if (geomagneticMatrix != null && accelerometerValues != null && sensorReady) {
sensorReady = false;
float[] R = new float[16];
float[] I = new float[16];
SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticMatrix);
float[] actual_orientation = new float[3];
SensorManager.getOrientation(R, actual_orientation);
tvXCoordinate.setText(accelerometerValues[0] + "");
tvYCoordinate.setText(accelerometerValues[1] + "");
tvZCoordinate.setText(accelerometerValues[2] + "");
floatXTotal += accelerometerValues[0];
tvXTotal.setText(floatXTotal + "");
tvAzimuth.setText(actual_orientation[0] + "");
tvPitch.setText(actual_orientation[1] + "");
tvRoll.setText(actual_orientation[2] + "");
}