# HG changeset patch # User Malte Bayer # Date 1322475840 -3600 # Node ID cc2274b92647c6bba3a7f041cf627a67b6538c85 # Parent 9e6feafc19e1db6be56297452c0df44ad80441a5# Parent 0250ceddee1b3c4f1f0877d7186467806d532e8d merge diff -r 9e6feafc19e1 -r cc2274b92647 trackscanner/bin/classes.dex Binary file trackscanner/bin/classes.dex has changed diff -r 9e6feafc19e1 -r cc2274b92647 trackscanner/bin/classes/de/neosoft/trackscanner/TrackScannerActivity.class Binary file trackscanner/bin/classes/de/neosoft/trackscanner/TrackScannerActivity.class has changed diff -r 9e6feafc19e1 -r cc2274b92647 trackscanner/src/de/neosoft/trackscanner/TrackScannerActivity.java --- a/trackscanner/src/de/neosoft/trackscanner/TrackScannerActivity.java Thu Nov 24 16:04:30 2011 +0100 +++ b/trackscanner/src/de/neosoft/trackscanner/TrackScannerActivity.java Mon Nov 28 11:24:00 2011 +0100 @@ -23,17 +23,18 @@ private float[] RotationMatrix = new float[matrix_size]; private float[] InclinationMatrix = new float[matrix_size]; + private int delay; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - int delay; - //delay = SensorManager.SENSOR_DELAY_NORMAL; - //delay = SensorManager.SENSOR_DELAY_FASTER; + delay = SensorManager.SENSOR_DELAY_NORMAL; + // delay = SensorManager.SENSOR_DELAY_FASTER; // delay = SensorManager.SENSOR_DELAY_FASTEST; - delay = SensorManager.SENSOR_DELAY_GAME; + // delay = SensorManager.SENSOR_DELAY_GAME; sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); @@ -55,37 +56,7 @@ @Override public void onSensorChanged(SensorEvent event) { - long actualTime = System.currentTimeMillis(); - if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { - //SensorManager.GRAVITY_EARTH - float alpha = 0.8f; - gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0]; - gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1]; - gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2]; - linear_acceleration[0] = event.values[0] - gravity[0]; - linear_acceleration[1] = event.values[1] - gravity[1]; - linear_acceleration[2] = event.values[2] - gravity[2]; - - mEdit.setText("Accelerometer action: "+ - "\nDelta: "+(actualTime-lastUpdate)+"ms"+ - "\nElevation Front/Back: "+gravity[0]+ - "\nElevation Left/Right: "+gravity[1]+ - "\nDrive Acceleration: "+linear_acceleration[0]+ - "\nDrift Force: "+linear_acceleration[1]+ - "\nVertical Force: "+linear_acceleration[2] - - ); - /* - * GravX = front/back elevation grade (recalc to degrees) - * GravY = left/right evelavtion grade - * LinAccX = driving acceleration - * LinAccY = drift acceleration - * LinAccZ = vertical acceleration - */ - } - - switch (event.sensor.getType()) { case Sensor.TYPE_MAGNETIC_FIELD: mags[0] = event.values[0]; @@ -96,26 +67,50 @@ accels[0] = event.values[0]; accels[1] = event.values[1]; accels[2] = event.values[2]; + + //SensorManager.GRAVITY_EARTH + float alpha = 0.8f; + gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0]; + gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1]; + gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2]; + + linear_acceleration[0] = event.values[0] - gravity[0]; + linear_acceleration[1] = event.values[1] - gravity[1]; + linear_acceleration[2] = event.values[2] - gravity[2]; break; } SensorManager.getRotationMatrix(RotationMatrix, InclinationMatrix, accels, mags); - float magHeading = SensorManager.getInclination(InclinationMatrix); + float orientation[] = new float[3]; + SensorManager.getOrientation(RotationMatrix, orientation); + float azimut = orientation[0]; // orientation contains: azimut, p + float heading = (-azimut*360/(2*3.14159f)); // 0 = North -90=West, 90= East - if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { - float[] values = event.values; - // Orientation (compass) - float x = values[0]; - float y = values[1]; - float z = values[2]; - mEdit2.setText("Magnetic Field:"+ - "\nX = "+x+ - "\nY = "+y+ - "\nZ = "+z+ - "\nMagnetic Heading (rad): "+magHeading); - } - - lastUpdate = actualTime; + mEdit.setText("Accelerometer action: "+ + "\nElevation Front/Back: "+gravity[0]+ + "\nElevation Left/Right: "+gravity[1]+ + "\nDrive Acceleration: "+linear_acceleration[0]+ + "\nDrift Force: "+linear_acceleration[1]+ + "\nVertical Force: "+linear_acceleration[2] + + ); + /* + * GravX = front/back elevation grade (recalc to degrees) + * GravY = left/right evlevation grade + * LinAccX = driving acceleration + * LinAccY = drift acceleration + * LinAccZ = vertical acceleration + */ + + float x = mags[0]; + float y = mags[1]; + float z = mags[2]; + mEdit2.setText("Magnetic Field:"+ + "\nX = "+x+ + "\nY = "+y+ + "\nZ = "+z+ + "\nHeading: "+heading); + } @Override @@ -131,7 +126,11 @@ // accelerometer sensors sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), - SensorManager.SENSOR_DELAY_NORMAL); + delay); + + sensorManager.registerListener(this, + sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), + delay); } @Override