com.drismo.logic
Class AccelerationHandler

java.lang.Object
  extended by com.drismo.logic.AccelerationHandler
All Implemented Interfaces:
android.hardware.SensorEventListener

public class AccelerationHandler
extends java.lang.Object
implements android.hardware.SensorEventListener

This object handles everything regarding collecting and filtering acceleration data. To listen for filtered acceleration data, implement the FilteredAccelerationListener interface.

See Also:
FilteredAccelerationListener

Nested Class Summary
private static class AccelerationHandler.MAQueue
          An inner static class used to remove noise from the acceleration values.
 
Field Summary
private  java.util.ArrayList<FilteredAccelerationListener> filteredAccelerationListeners
           
private  AccelerationHandler.MAQueue maQueue
           
private  double pitch
           
private  double roll
           
private  android.hardware.SensorManager sensorManager
           
private  double yaw
           
 
Constructor Summary
AccelerationHandler(android.hardware.SensorManager sm)
          Set up the sensor manager and the moving average queue.
 
Method Summary
 void onAccuracyChanged(android.hardware.Sensor sensor, int i)
          Never used
 void onSensorChanged(android.hardware.SensorEvent event)
          Filters the incoming acceleration data using the WMA or EMA algorithm, and fires the callback method of all the listeners.
 void registerFilteredAccelerationListener(FilteredAccelerationListener listener)
          Add an object to listen for filtered acceleration data.
static void rotate(double radAngle, int indexX, int indexY, float[] vectors)
          Rotates two vectors using polar rotation, using each vector as a coordinate.
 void rotateAll(float[] vectors)
          Rotates all the acceleration vectors given as parameter, according to the roll, pitch and yaw angles.
 void startListening()
          Start listening for acceleration data.
 void stopListening()
          Stop listening for acceleration data.
 void unregisterFilteredAccelerationListener(FilteredAccelerationListener listener)
          Remove an added listener from the list.
 void updatePitchAngle(double YZ)
          Updates the pitch angle relative to the vehicle.
 void updateRollAngle(double XZ)
          Updates the roll angle relative to the vehicle.
 void updateYawAngle(double XY)
          Updates the yaw angle relative to the vehicle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sensorManager

private android.hardware.SensorManager sensorManager

pitch

private double pitch

roll

private double roll

yaw

private double yaw

maQueue

private AccelerationHandler.MAQueue maQueue

filteredAccelerationListeners

private final java.util.ArrayList<FilteredAccelerationListener> filteredAccelerationListeners
Constructor Detail

AccelerationHandler

public AccelerationHandler(android.hardware.SensorManager sm)
Set up the sensor manager and the moving average queue.

Parameters:
sm - The sensor manager used to register a accelerometer data listener.
Method Detail

startListening

public void startListening()
Start listening for acceleration data.


stopListening

public void stopListening()
Stop listening for acceleration data.


registerFilteredAccelerationListener

public void registerFilteredAccelerationListener(FilteredAccelerationListener listener)
Add an object to listen for filtered acceleration data.

Parameters:
listener - The listener to add.

unregisterFilteredAccelerationListener

public void unregisterFilteredAccelerationListener(FilteredAccelerationListener listener)
Remove an added listener from the list.

Parameters:
listener - The listener to remove.

onSensorChanged

public void onSensorChanged(android.hardware.SensorEvent event)
Filters the incoming acceleration data using the WMA or EMA algorithm, and fires the callback method of all the listeners.

Specified by:
onSensorChanged in interface android.hardware.SensorEventListener
Parameters:
event - Sensor event. Only using Sensor.TYPE_ACCELEROMETER.
See Also:
FilteredAccelerationListener.onFilteredAccelerationChange(float[], float[])

updatePitchAngle

public void updatePitchAngle(double YZ)
Updates the pitch angle relative to the vehicle.

Parameters:
YZ - The new angle (radians)

updateYawAngle

public void updateYawAngle(double XY)
Updates the yaw angle relative to the vehicle.

Parameters:
XY - The new angle (radians)

updateRollAngle

public void updateRollAngle(double XZ)
Updates the roll angle relative to the vehicle.

Parameters:
XZ - The new angle (radians)

rotateAll

public void rotateAll(float[] vectors)
Rotates all the acceleration vectors given as parameter, according to the roll, pitch and yaw angles.

Parameters:
vectors - The acceleration vectors

rotate

public static void rotate(double radAngle,
                          int indexX,
                          int indexY,
                          float[] vectors)
Rotates two vectors using polar rotation, using each vector as a coordinate.

Parameters:
radAngle - The rotation angle in radians.
indexX - Index of the X coordinate
indexY - Index of the Y coordinate
vectors - Acceleration vector array.

onAccuracyChanged

public void onAccuracyChanged(android.hardware.Sensor sensor,
                              int i)
Never used

Specified by:
onAccuracyChanged in interface android.hardware.SensorEventListener