org.android.activityminer.logic.devices
Class AbstractAccelerometerDataSource

Package class diagram package AbstractAccelerometerDataSource
java.lang.Object
  extended by org.android.activityminer.logic.util.AbstractActivatableComponentImpl
      extended by org.android.activityminer.logic.devices.AbstractAccelerometerDataSource
All Implemented Interfaces:
EventObserver<ScreenChangeEvent>, ObservableEventSource<SampleGapErrorEvent>, ObserverRegistration<SampleGapErrorEvent>, SensorDataSource<AccelerometerData>, ActivatableComponent
Direct Known Subclasses:
LinearAccelerometerDataSource, LinearDeviceAccelerometerDataSource

public abstract class AbstractAccelerometerDataSource
extends AbstractActivatableComponentImpl
implements SensorDataSource<AccelerometerData>, EventObserver<ScreenChangeEvent>, ObservableEventSource<SampleGapErrorEvent>

Base class for the accelerometer data source.


Nested Class Summary
private  class AbstractAccelerometerDataSource.RawAccelerationListener
          The raw acceleration listener.
 
Field Summary
protected  AccelerometerDataCache cache
          The data cache to hold samples for scan access.
protected  Context context
          The Android context
protected  double[] currentData
          The most recent sample data (linear axis accelerations and force of gravity components)
protected  Object currentDataLock
          lock for access to the current sample data
protected  double[] currentFilterData
          The most recent smoothed sample data
protected  LowPassFilter filter
          The low pass filter to suppress higher frequencies
private  SensorEventListener rawAccListener
          The sensor event listener for the raw acceleration event
private  Sensor rawAccSensor
          The corresponding Android sensor for raw acceleration
protected  AtomicLong sampleCount
          The current sample count ( since last start ).
private  ScreenOnOffBroadcastReceiver screenStateChangeReceiver
          A broadcast receiver for screen state changes.
protected  int sensorRate
          The sensor rate
protected  AtomicLong startRefTime
          The time stamp of the first sensor event in nanoseconds.
protected  AtomicLong startTs
          The time stamp of the last start in milliseconds.
private  AtomicLong stopTs
          The current time stamp in milliseconds.
 
Constructor Summary
AbstractAccelerometerDataSource(Context context, FrequencyTypes fType, LowPassFilter filter)
          Constructor
 
Method Summary
 long getAverageSampleDistance()
          Getter for the average sample distance in milliseconds.
 boolean hasObservers()
           
 void notify(SampleGapErrorEvent data)
           
protected  void onActivationStateChange(boolean active)
          Handler for activation state changes
 void onDestroy()
          This method is for cleanup in case of termination.
 void onEvent(ObservableEventSource<? extends ScreenChangeEvent> eventSource, ScreenChangeEvent observedEvent)
           
abstract  void onSensorEventRawAcc(SensorEvent event)
          Handler for sensor events of the raw acceleration sensor
 void registerEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
           
protected  void registerListener(Context context)
          Does register the sensor listeners for the device type
 void removeAllObservers()
           
 void setFilter(LowPassFilter filter)
          Setter for the smoothing filter ( Access is only allowed if the device is not activate ).
 AccelerometerData takeSample(Long ts)
          Getter for the current sample
 void unregisterEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
           
protected  void unregisterListener(Context context)
          Does unregister the sensor listener for the device type
 void updateFilterConfiguration(RuntimeConfiguration config)
          Method to update the accelerometer filter configuration ( Access is only allowed if the device is not activate ).
 
Methods inherited from class org.android.activityminer.logic.util.AbstractActivatableComponentImpl
isActive, setActivationState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected final Context context
The Android context


rawAccListener

private final SensorEventListener rawAccListener
The sensor event listener for the raw acceleration event


rawAccSensor

private final Sensor rawAccSensor
The corresponding Android sensor for raw acceleration


currentData

protected final double[] currentData
The most recent sample data (linear axis accelerations and force of gravity components)


currentFilterData

protected double[] currentFilterData
The most recent smoothed sample data


stopTs

private final AtomicLong stopTs
The current time stamp in milliseconds.


startTs

protected final AtomicLong startTs
The time stamp of the last start in milliseconds.


startRefTime

protected final AtomicLong startRefTime
The time stamp of the first sensor event in nanoseconds.


sampleCount

protected final AtomicLong sampleCount
The current sample count ( since last start ).


screenStateChangeReceiver

private final ScreenOnOffBroadcastReceiver screenStateChangeReceiver
A broadcast receiver for screen state changes.


currentDataLock

protected final Object currentDataLock
lock for access to the current sample data


sensorRate

protected final int sensorRate
The sensor rate


cache

protected final AccelerometerDataCache cache
The data cache to hold samples for scan access.


filter

protected LowPassFilter filter
The low pass filter to suppress higher frequencies

Constructor Detail

AbstractAccelerometerDataSource

public AbstractAccelerometerDataSource(Context context,
                                       FrequencyTypes fType,
                                       LowPassFilter filter)
Constructor

Parameters:
context - the application context
fType - the sample frequency type
filter - the filter to cut of higher frequencies
Method Detail

registerListener

protected void registerListener(Context context)
Does register the sensor listeners for the device type

Parameters:
context - the context

unregisterListener

protected void unregisterListener(Context context)
Does unregister the sensor listener for the device type

Parameters:
context - the context

onSensorEventRawAcc

public abstract void onSensorEventRawAcc(SensorEvent event)
Handler for sensor events of the raw acceleration sensor

Parameters:
event - the sensor event

takeSample

public AccelerometerData takeSample(Long ts)
Description copied from interface: SensorDataSource
Getter for the current sample

Specified by:
takeSample in interface SensorDataSource<AccelerometerData>
Parameters:
ts - the requested time stamp
Returns:
the current sample

onEvent

public void onEvent(ObservableEventSource<? extends ScreenChangeEvent> eventSource,
                    ScreenChangeEvent observedEvent)
Specified by:
onEvent in interface EventObserver<ScreenChangeEvent>

onActivationStateChange

protected void onActivationStateChange(boolean active)
Description copied from class: AbstractActivatableComponentImpl
Handler for activation state changes

Specified by:
onActivationStateChange in class AbstractActivatableComponentImpl
Parameters:
active - the new activation state

getAverageSampleDistance

public final long getAverageSampleDistance()
Getter for the average sample distance in milliseconds.

Returns:
the average sample distance in milliseconds

setFilter

public final void setFilter(LowPassFilter filter)
                     throws AccessControlException
Setter for the smoothing filter ( Access is only allowed if the device is not activate ).

Parameters:
filter - the filter to set
Throws:
AccessControlException - if active

updateFilterConfiguration

public final void updateFilterConfiguration(RuntimeConfiguration config)
                                     throws AccessControlException
Method to update the accelerometer filter configuration ( Access is only allowed if the device is not activate ).

Parameters:
config - the current configuration
Throws:
AccessControlException - if active

onDestroy

public final void onDestroy()
Description copied from interface: SensorDataSource
This method is for cleanup in case of termination.

Specified by:
onDestroy in interface SensorDataSource<AccelerometerData>

registerEventObserver

public void registerEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
Specified by:
registerEventObserver in interface ObserverRegistration<SampleGapErrorEvent>

unregisterEventObserver

public void unregisterEventObserver(EventObserver<? extends SampleGapErrorEvent> observer)
Specified by:
unregisterEventObserver in interface ObserverRegistration<SampleGapErrorEvent>

removeAllObservers

public void removeAllObservers()
Specified by:
removeAllObservers in interface ObserverRegistration<SampleGapErrorEvent>

notify

public void notify(SampleGapErrorEvent data)
Specified by:
notify in interface ObservableEventSource<SampleGapErrorEvent>

hasObservers

public boolean hasObservers()
Specified by:
hasObservers in interface ObservableEventSource<SampleGapErrorEvent>