magnetometer

This commit is contained in:
jens 2022-03-03 17:32:06 +01:00
parent 76563eb89b
commit 195a60cfe0

View File

@ -34,17 +34,18 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
static int sensorValueCounter = 0; static int sensorValueCounter = 0;
// Gravity rotational data // Gravity rotational data
private float gravity[]; float gravity[];
// Magnetic rotational data // Magnetic rotational data
private float magnetic[]; //for magnetic rotational data float magnetic[]; //for magnetic rotational data
private float accels[] = new float[3]; float accels[] = new float[3];
private float mags[] = new float[3]; float mags[] = new float[3];
private float[] values = new float[3]; float[] values = new float[3];
boolean hasMagneticSensor=false;
// azimuth, pitch and roll // azimuth, pitch and roll
private float azimuth; float azimuth;
private float pitch; float pitch;
private float roll; float roll;
boolean applies = false; boolean applies = false;
boolean flipped = false; boolean flipped = false;
@ -91,7 +92,10 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
isRunning = true; isRunning = true;
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL); hasMagneticSensor = sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
if(!hasMagneticSensor)
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
} }
} }
@ -129,6 +133,9 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
break; break;
} }
if (!hasMagneticSensor)
mags=new float[]{1f,1f,1f};
if (mags != null && accels != null) if (mags != null && accels != null)
{ {
gravity = new float[9]; gravity = new float[9];